# Stage 1: Build the React application FROM node:20-alpine AS builder WORKDIR /app # Copy package.json and package-lock.json first to leverage Docker cache COPY package*.json ./ # Install dependencies RUN npm ci # Copy the rest of the application code COPY . . # Accept the API_KEY as a build argument ARG API_KEY ENV API_KEY=$API_KEY # Build the application RUN npm run build # Stage 2: Serve the application with Node.js FROM node:20-alpine AS runner WORKDIR /app # Set environment to production ENV NODE_ENV=production ENV PORT=8080 # Copy package.json and package-lock.json for production dependencies COPY package*.json ./ # Install only production dependencies RUN npm ci --only=production # Copy the built assets from the builder stage COPY --from=builder /app/dist ./dist # Copy the server script COPY server.js . # Expose the port the app runs on EXPOSE 8080 # Start the server CMD ["node", "server.js"]