From 2fc87c97e8a2a6ed333f9ecd38fcabd134dee277 Mon Sep 17 00:00:00 2001 From: Sina Alikhani Date: Tue, 9 Jun 2026 15:37:20 +0330 Subject: [PATCH 1/6] Add Dockerfile --- Dockerfile | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a33eb0e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Use the official Node.js image as the base image +FROM docker.arvancloud.ir/node:18 + +# Set the working directory inside the container +WORKDIR /usr/src/app + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Install the application dependencies +RUN npm install + +# Copy the rest of the application files +COPY . . + +# Build the NestJS application +RUN npm run build + +# Expose the application port +EXPOSE 3000 + +# Command to run the application +CMD ["node", "dist/main"] From 3af3805863c3e79539d5d79a7985541bed569521 Mon Sep 17 00:00:00 2001 From: Sina Alikhani Date: Tue, 9 Jun 2026 15:41:04 +0330 Subject: [PATCH 2/6] Add .dockerignore --- .dockerignore | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fa1ac57 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +# Versioning and metadata +.git/ +.gitignore +.dockerignore + +# Build dependencies +dist/ +node_modules/ +coverage + +# Environment (contains sensitive data) +.env + +# Files not required for production +.editorconfig +Dockerfile +README.md +.eslintrc.js +nodemon.json + +docker-compose* +LICENSE +*.md +.sonarcloud* +.editorconfig +commitlint* +*.gql \ No newline at end of file From 15ca17ce3bb9355aebc3cf600938d8cdf1c5892b Mon Sep 17 00:00:00 2001 From: Sina Alikhani Date: Tue, 9 Jun 2026 16:09:53 +0330 Subject: [PATCH 3/6] Chnage Dockerfile from single stage to multistage --- Dockerfile | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index a33eb0e..03bf91a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,23 @@ -# Use the official Node.js image as the base image -FROM docker.arvancloud.ir/node:18 +# ─── Stage 0: Base ──────────────────────────────────────────────────────────── +FROM node:20-alpine AS base +WORKDIR /app -# Set the working directory inside the container -WORKDIR /usr/src/app - -# Copy package.json and package-lock.json to the working directory +# ─── Stage 1: Dependencies ─────────────────────────────────────────────────── +FROM base AS deps COPY package*.json ./ +RUN npm ci -# Install the application dependencies -RUN npm install - -# Copy the rest of the application files +# ─── Stage 2: Builder ───────────────────────────────────────────────────────── +FROM deps AS builder COPY . . - -# Build the NestJS application RUN npm run build +RUN npm ci --omit=dev --ignore-scripts -# Expose the application port +# ─── 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 - -# Command to run the application -CMD ["node", "dist/main"] +CMD ["node", "dist/main"] \ No newline at end of file From 000611cf5c893a8ecba4237247aa1fa8bdeb0fe3 Mon Sep 17 00:00:00 2001 From: Sina Alikhani Date: Tue, 9 Jun 2026 16:11:23 +0330 Subject: [PATCH 4/6] Update .dockerignore --- .dockerignore | 56 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/.dockerignore b/.dockerignore index fa1ac57..4b69cc7 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,27 +1,43 @@ -# Versioning and metadata -.git/ -.gitignore -.dockerignore +# Dependencies (reinstalled inside Docker) +node_modules -# Build dependencies -dist/ -node_modules/ +# Build output (rebuilt inside Docker) +dist + +# Test & coverage +test +**/*.spec.ts +**/*.e2e-spec.ts coverage +jest.config.* -# Environment (contains sensitive data) +# Environment & secrets .env +.env.* +!.env.example -# Files not required for production -.editorconfig +# Git +.git +.gitignore +.gitattributes + +# Docker itself Dockerfile -README.md -.eslintrc.js -nodemon.json +.dockerignore +docker-compose*.yml -docker-compose* -LICENSE -*.md -.sonarcloud* -.editorconfig -commitlint* -*.gql \ No newline at end of file +# 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 From 24268bb653acfdb43ca0dff11dc74c38242c9de0 Mon Sep 17 00:00:00 2001 From: Sina Alikhani Date: Tue, 9 Jun 2026 16:17:04 +0330 Subject: [PATCH 5/6] Add docker-compose.build.yml --- docker-compose.build.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 docker-compose.build.yml 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 From a56a83ed40d5738d4fa8d0c1b2050c526436e680 Mon Sep 17 00:00:00 2001 From: Sina Alikhani Date: Tue, 9 Jun 2026 16:26:07 +0330 Subject: [PATCH 6/6] Add docker-compose.deploy.yml --- docker-compose.deploy.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 docker-compose.deploy.yml 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