# Stage 1: Build the React Application FROM node:20-bookworm AS builder WORKDIR /app # Copy ONLY package.json COPY package.json ./ # Install dependencies # --legacy-peer-deps: Ignores peer dependency conflicts # --no-audit: Skips vulnerability audit (faster, less noise) # --no-fund: Hides funding messages RUN npm install --legacy-peer-deps --no-audit --no-fund # Copy the rest of the application source code COPY . . # Build the frontend assets RUN npm run build # Stage 2: Setup the Production Server FROM node:20-bookworm-slim WORKDIR /app # Copy ONLY package.json COPY package.json ./ # Install ONLY production dependencies RUN npm install --omit=dev --legacy-peer-deps --no-audit --no-fund # Copy the built frontend assets from the 'builder' stage COPY --from=builder /app/dist ./dist # Copy the server entry point COPY server.js ./ # Set environment variables ENV NODE_ENV=production ENV PORT=3000 # Expose the port EXPOSE 3000 # Start the Node.js server CMD ["npm", "start"]