From 3ace14fcdbe74b8b4d2ccd1f9a2cb4006e0ce110 Mon Sep 17 00:00:00 2001 From: kithmina1999 Date: Thu, 19 Jun 2025 22:26:20 +0530 Subject: [PATCH 1/3] build(docker): optimize docker setup and compose configuration - Split Dockerfile into multi-stage build to reduce final image size - Update docker-compose.yml with restart policies and health checks - Improve .dockerignore files for both frontend and backend - Fix MinIO bucket creation script to use 'alias set' instead of deprecated command - Enhance PostgreSQL healthcheck configuration --- docker-compose.yml | 14 ++++++---- git | 3 +++ worklenz-backend/.dockerignore | 6 ++++- worklenz-backend/Dockerfile | 45 +++++++++++++++++++++------------ worklenz-frontend/.dockerignore | 6 +++++ 5 files changed, 52 insertions(+), 22 deletions(-) create mode 100644 git create mode 100644 worklenz-frontend/.dockerignore diff --git a/docker-compose.yml b/docker-compose.yml index e7d074ad..51b30b3a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,8 +7,8 @@ services: ports: - "5000:5000" depends_on: - backend: - condition: service_started + - backend + restart: unless-stopped env_file: - ./worklenz-frontend/.env.production networks: @@ -26,6 +26,7 @@ services: condition: service_healthy minio: condition: service_started + restart: unless-stopped env_file: - ./worklenz-backend/.env networks: @@ -37,6 +38,7 @@ services: ports: - "9000:9000" - "9001:9001" + restart: unless-stopped environment: MINIO_ROOT_USER: ${S3_ACCESS_KEY_ID:-minioadmin} MINIO_ROOT_PASSWORD: ${S3_SECRET_ACCESS_KEY:-minioadmin} @@ -52,13 +54,14 @@ services: container_name: worklenz_createbuckets depends_on: - minio + restart: on-failure entrypoint: > /bin/sh -c ' echo "Waiting for MinIO to start..."; sleep 15; for i in 1 2 3 4 5; do echo "Attempt $i to connect to MinIO..."; - if /usr/bin/mc config host add myminio http://minio:9000 minioadmin minioadmin; then + if /usr/bin/mc alias set myminio http://minio:9000 minioadmin minioadmin; then echo "Successfully connected to MinIO!"; /usr/bin/mc mb --ignore-existing myminio/worklenz-bucket; /usr/bin/mc policy set public myminio/worklenz-bucket; @@ -80,10 +83,11 @@ services: POSTGRES_DB: ${DB_NAME:-worklenz_db} POSTGRES_PASSWORD: ${DB_PASSWORD:-password} healthcheck: - test: [ "CMD-SHELL", "pg_isready -d ${DB_NAME:-worklenz_db} -U ${DB_USER:-postgres}" ] + test: ["CMD-SHELL", "pg_isready -h localhost -p 5432 -U postgres"] interval: 10s timeout: 5s - retries: 5 + retries: 10 + restart: unless-stopped networks: - worklenz volumes: diff --git a/git b/git new file mode 100644 index 00000000..ff506e2f --- /dev/null +++ b/git @@ -0,0 +1,3 @@ + PID PPID PGID WINPID TTY UID STIME COMMAND + 1449 1 1449 23644 cons0 197609 22:11:58 /usr/bin/bash + 1567 1449 1567 20324 cons0 197609 22:17:39 /usr/bin/PS diff --git a/worklenz-backend/.dockerignore b/worklenz-backend/.dockerignore index 263e9ac4..fdfab06a 100644 --- a/worklenz-backend/.dockerignore +++ b/worklenz-backend/.dockerignore @@ -1,5 +1,9 @@ node_modules npm-debug.log -build .scannerwork coverage +.dockerignore +.git +*.md +tests + diff --git a/worklenz-backend/Dockerfile b/worklenz-backend/Dockerfile index f381e37e..244b7cf8 100644 --- a/worklenz-backend/Dockerfile +++ b/worklenz-backend/Dockerfile @@ -1,26 +1,39 @@ -# Use the official Node.js 20 image as a base -FROM node:20 +# --- Stage 1: Build --- +FROM node:20-slim AS builder + +ARG RELEASE_VERSION +RUN apt-get update && apt-get install -y \ + python3 \ + make \ + g++ \ + curl \ + postgresql-server-dev-all \ + && rm -rf /var/lib/apt/lists/* -# Create and set the working directory WORKDIR /usr/src/app -# Install global dependencies -RUN npm install -g ts-node typescript grunt grunt-cli - -# Copy package.json and package-lock.json (if available) COPY package*.json ./ - -# Install app dependencies RUN npm ci -# Copy the rest of the application code COPY . . - -# Run the build script to compile TypeScript to JavaScript RUN npm run build -# Expose the port the app runs on -EXPOSE 3000 +RUN echo "$RELEASE_VERSION" > release + +# --- Stage 2: Production Image --- +FROM node:20-slim + +RUN apt-get update && apt-get install -y libpq5 && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY --from=builder /usr/src/app/package*.json ./ +COPY --from=builder /usr/src/app/build ./build +COPY --from=builder /usr/src/app/node_modules ./node_modules +COPY --from=builder /usr/src/app/release ./release +COPY --from=builder /usr/src/app/worklenz-email-templates ./worklenz-email-templates + + +EXPOSE 3000 +CMD ["node", "build/bin/www"] -# Start the application -CMD ["npm", "start"] \ No newline at end of file diff --git a/worklenz-frontend/.dockerignore b/worklenz-frontend/.dockerignore new file mode 100644 index 00000000..6a9920e7 --- /dev/null +++ b/worklenz-frontend/.dockerignore @@ -0,0 +1,6 @@ +node_modules +npm-debug.log +.git +.gitignore +.dockerignore +README.md From eca7af2d6f33c0d2a0d092e3b639e95d11d95f07 Mon Sep 17 00:00:00 2001 From: kithmina1999 Date: Thu, 19 Jun 2025 22:32:17 +0530 Subject: [PATCH 2/3] chore: remove obsolete git file with process information The file contained outdated process information that was no longer relevant to the project. This cleanup helps maintain a cleaner codebase. --- git | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 git diff --git a/git b/git deleted file mode 100644 index ff506e2f..00000000 --- a/git +++ /dev/null @@ -1,3 +0,0 @@ - PID PPID PGID WINPID TTY UID STIME COMMAND - 1449 1 1449 23644 cons0 197609 22:11:58 /usr/bin/bash - 1567 1449 1567 20324 cons0 197609 22:17:39 /usr/bin/PS From 0d0596b767e8b3c6b10a997e81f2e402b36e20a1 Mon Sep 17 00:00:00 2001 From: kithmina1999 Date: Fri, 20 Jun 2025 08:48:51 +0530 Subject: [PATCH 3/3] ci(docker): update postgres healthcheck and retry settings - Modify healthcheck command to use DB_NAME and DB_USER environment variables - Reduce retries from 10 to 5 to fail faster if database is unavailable --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 51b30b3a..363f2006 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -83,10 +83,10 @@ services: POSTGRES_DB: ${DB_NAME:-worklenz_db} POSTGRES_PASSWORD: ${DB_PASSWORD:-password} healthcheck: - test: ["CMD-SHELL", "pg_isready -h localhost -p 5432 -U postgres"] + test: [ "CMD-SHELL", "pg_isready -d ${DB_NAME:-worklenz_db} -U ${DB_USER:-postgres}" ] interval: 10s timeout: 5s - retries: 10 + retries: 5 restart: unless-stopped networks: - worklenz