From 96a2bc055f5cceda6ad56797f91fbb6ac3a8394a Mon Sep 17 00:00:00 2001 From: Vincent Hardouin Date: Mon, 7 Oct 2024 13:49:22 +0200 Subject: [PATCH] feat: add prod docker compose --- .dockerignore | 8 ++++++++ Dockerfile | 27 +++++++++++++++++++++++++++ prod.compose.yaml | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 prod.compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..40d4bb8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +sample.env +.env +README.md +eslint.config.js +.github +docs +node_modules +tests diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e8fa948 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +ARG NODE_VERSION=20.16.0 + +FROM node:${NODE_VERSION}-alpine as builder +ENV NODE_ENV production +WORKDIR /app + +# Download dependencies as a separate step to take advantage of Docker's caching. +# Leverage a cache mount to /root/.npm to speed up subsequent builds. +# Leverage a bind mounts to package.json and package-lock.json to avoid having to copy them into +# into this layer. +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=package-lock.json,target=package-lock.json \ + --mount=type=cache,target=/root/.npm \ + npm ci --omit=dev + +COPY . . + +FROM node:${NODE_VERSION}-alpine + +WORKDIR /app +USER node + +COPY --from=builder /app . + +ARG PORT=3000 +ENV PORT $PORT +EXPOSE $PORT \ No newline at end of file diff --git a/prod.compose.yaml b/prod.compose.yaml new file mode 100644 index 0000000..f8bf7bf --- /dev/null +++ b/prod.compose.yaml @@ -0,0 +1,39 @@ +services: + postgres-ucpa: + image: postgres:15.8-alpine + container_name: ucpa-postgres + networks: + - back + ports: + - '${UCPA_DATABASE_PORT_API:-5466}:5432' + environment: + POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_DB: ucpa_facilitator + env_file: + - .env + + app-ucpa: + build: + context: . + container_name: app-ucpa + command: > + sh -c "npm run db:migrate && npm start" + networks: + - back + - web + environment: + NODE_ENV: production + env_file: + - .env + labels: + traefik.enable: true + traefik.docker.network: web + traefik.http.routers.ucpa.rule: Host(`${URL}`) + traefik.http.routers.ucpa.entrypoints: websecure + traefik.http.routers.ucpa.tls: true + traefik.http.routers.ucpa.tls.certresolver: letsencrypt + +networks: + back: + web: + external: true \ No newline at end of file