# Stage 1: Build the React Application FROM node:20 AS builder WORKDIR /app # Copy ONLY package.json. # We intentionally IGNORE package-lock.json to prevent architecture mismatches # (e.g., trying to install macOS binaries for esbuild on Linux). COPY package.json ./ # Install dependencies from scratch for the container's architecture RUN npm install # 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 WORKDIR /app # Copy ONLY package.json COPY package.json ./ # Install ONLY production dependencies RUN npm install --omit=dev # 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"]