From 7c853530e0084c0f5063baba5ed975866919af8f Mon Sep 17 00:00:00 2001 From: Simon Oulevay Date: Sat, 28 Sep 2024 00:26:58 +0200 Subject: [PATCH] Add docker & compose files --- .dockerignore | 12 ++++++++++++ Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ compose.yml | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..504b7b0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +# https://docs.docker.com/build/concepts/context/#dockerignore-files +/compose.yml +/Dockerfile +/.editorconfig +/eslint.config.mjs +/.github +/.gitignore +/node_modules +/nodemon.json +/.prettierignore +/.prettierrc.yml +/.tool-versions diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d6863ba --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +# Builder image +# ============= + +FROM node:22.9.0-alpine AS builder + +WORKDIR /app + +COPY package.json package-lock.json ./ +RUN npm ci + +COPY . . +RUN npm prune --production + +# Production image +# ================ + +FROM node:22.9.0-alpine + +ENV NODE_ENV=production \ + PORT=3000 + +LABEL org.opencontainers.image.authors="simon.oulevay@heig-vd.ch" + +WORKDIR /app + +RUN addgroup -S onechatroom && \ + adduser -D -G onechatroom -H -s /usr/bin/nologin -S onechatroom && \ + chown onechatroom:onechatroom /app + +USER onechatroom:onechatroom + +COPY --chown=onechatroom:onechatroom --from=builder /app /app + +CMD ["node", "./bin/www"] + +EXPOSE 3000 diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..baf11c6 --- /dev/null +++ b/compose.yml @@ -0,0 +1,32 @@ +name: one-chat-room + +services: + app: + build: + context: . + image: archidep/one-chat-room + depends_on: + - db + environment: + - DATABASE_URL=mongodb://db:27017/one-chat-room + - DEBUG=one-chat-room:* + init: true + networks: + - app + - db + ports: + - '${ONE_CHAT_ROOM_PORT:-3000}:3000' + + db: + image: mongo:8.0.0 + networks: + - db + volumes: + - db-data:/data/db + +networks: + app: + db: + +volumes: + db-data: