From 7e78ef65b1574b074ae7eeb6dc3e5338d051344b Mon Sep 17 00:00:00 2001 From: Slawomir Koszewski Date: Wed, 21 Jan 2026 20:06:39 +0100 Subject: [PATCH] Implement multi-stage Docker build for clean production image - Build stage: Has scripts/ for version generation, all dependencies - Production stage: Only production deps, built artifacts, server.js - Eliminates build scripts and dev dependencies from final image - Maintains proper version.js generation during build process --- Dockerfile | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2009612..35c586d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -# Use Node 24 LTS as base image -FROM node:24-alpine +# Build stage +FROM node:24-alpine AS builder # Set working directory WORKDIR /app @@ -10,17 +10,31 @@ COPY package*.json ./ # Install dependencies (production + dev for build) RUN npm ci -# Copy source code +# Copy source code and build scripts COPY src/ ./src/ COPY public/ ./public/ +COPY scripts/ ./scripts/ COPY server.js ./server.js # Build the application RUN npm run build -# Remove dev dependencies to reduce image size +# Production stage +FROM node:24-alpine AS production + +# Set working directory +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install only production dependencies RUN npm ci --only=production && npm cache clean --force +# Copy built application and server from build stage +COPY --from=builder /app/build ./build +COPY --from=builder /app/server.js ./server.js + # Expose port 3000 EXPOSE 3000