diff --git a/docker-compose.yml b/docker-compose.yml index d7bd8cb5..363f2006 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,6 +54,7 @@ services: container_name: worklenz_createbuckets depends_on: - minio + restart: on-failure entrypoint: > /bin/sh -c ' echo "Waiting for MinIO to start..."; @@ -84,6 +87,7 @@ services: interval: 10s timeout: 5s retries: 5 + restart: unless-stopped networks: - worklenz volumes: 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