From c010ea4ea72cb019e88056192b1a12f9ac29bd00 Mon Sep 17 00:00:00 2001 From: gibbyb Date: Thu, 27 Feb 2025 11:44:25 -0600 Subject: [PATCH] Add docker stuff --- docker/Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ docker/docker-compose.yml | 23 +++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/docker-compose.yml diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..fee1419 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,36 @@ +# Stage 1: Build the project +FROM node:18 as builder + +# Set the working directory in the container +WORKDIR /app + +# Copy package.json and pnpm-lock.yaml or package-lock.json (if using npm) to the working directory +COPY ../package.json ../pnpm-lock.yaml ./ + +# Install dependencies +RUN npm install -g pnpm +RUN pnpm install + +# Copy project files into the docker image +COPY ../ . + +# Build the project +RUN pnpm run build + +# Stage 2: Serve the app using a lightweight node image +FROM node:16-alpine + +# Install a simple http server +RUN npm install -g serve + +# Set the working directory to /app +WORKDIR /app + +# Copy built assets from the builder stage +COPY --from=builder /app/dist /app + +# Expose port 5000 for the server +EXPOSE 5000 + +# Start the server using the `serve` package +CMD ["serve", "-s", ".", "-l", "5000"] diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..c9b5c4a --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,23 @@ +version: '3.8' + +services: + bang-web-server: + build: + context: ../ # point to the parent directory where package.json and source code reside + dockerfile: docker/Dockerfile # specific path to the Dockerfile + container_name: bang + domainname: bang.gbrown.org + hostname: bang + networks: + - node_apps + ports: + - "5000:5000" + tty: true + restart: unless-stopped + volumes: + - ../:/app # mount the parent directory to /app in the container + command: serve -s /app -l 5000 + +networks: + node_apps: + external: true