diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4b69cc7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,43 @@ +# Dependencies (reinstalled inside Docker) +node_modules + +# Build output (rebuilt inside Docker) +dist + +# Test & coverage +test +**/*.spec.ts +**/*.e2e-spec.ts +coverage +jest.config.* + +# Environment & secrets +.env +.env.* +!.env.example + +# Git +.git +.gitignore +.gitattributes + +# Docker itself +Dockerfile +.dockerignore +docker-compose*.yml + +# Editor & OS +.vscode +.idea +*.iml +.DS_Store +Thumbs.db + +# Logs +logs +*.log +npm-debug.log* + +# Misc +README.md +*.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..03bf91a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# ─── Stage 0: Base ──────────────────────────────────────────────────────────── +FROM node:20-alpine AS base +WORKDIR /app + +# ─── Stage 1: Dependencies ─────────────────────────────────────────────────── +FROM base AS deps +COPY package*.json ./ +RUN npm ci + +# ─── Stage 2: Builder ───────────────────────────────────────────────────────── +FROM deps AS builder +COPY . . +RUN npm run build +RUN npm ci --omit=dev --ignore-scripts + +# ─── Stage 3: Production ────────────────────────────────────────────────────── +FROM base AS production +ENV NODE_ENV=production +COPY --from=builder --chown=appuser:appgroup /app/dist ./dist +COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules +COPY --from=builder --chown=appuser:appgroup /app/package.json ./package.json +EXPOSE 3000 +CMD ["node", "dist/main"] \ No newline at end of file diff --git a/docker-compose.build.yml b/docker-compose.build.yml new file mode 100644 index 0000000..a2a29a1 --- /dev/null +++ b/docker-compose.build.yml @@ -0,0 +1,8 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile + target: production + image: ${REGISTRY_URL:-registry.ittalie.com}/${IMAGE_NAME:-shared-esg}:${IMAGE_TAG:-latest} + \ No newline at end of file diff --git a/docker-compose.deploy.yml b/docker-compose.deploy.yml new file mode 100644 index 0000000..3b2f368 --- /dev/null +++ b/docker-compose.deploy.yml @@ -0,0 +1,30 @@ +services: + app: + image: ${REGISTRY_URL:-docker.ittalie.com}/${IMAGE_NAME:-shared-esg}:${IMAGE_TAG:-latest} + container_name: shared-esg + hostname: shared-esg + restart: unless-stopped + ports: + - "127.0.0.1:3000:3000" + env_file: + - .production.env + depends_on: + mongodb: + condition: service_healthy + + mongodb: + image: docker.ittalie.com/mongo:7 + container_name: shared-esg-db + hostname: shared-esg-db + restart: unless-stopped + volumes: + - esg_mongodb_data:/data/db + healthcheck: + test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s + +volumes: + esg_mongodb_data: \ No newline at end of file