# Stage 1: Build the React application FROM node:20-alpine AS builder WORKDIR /app # Accept build arguments ARG VITE_API_BASE_URL # Copy package.json and package-lock.json COPY package*.json ./ # Install dependencies RUN npm install # Copy the rest of the application source code COPY . . # Write the build arg to .env.production so Vite picks it up during build RUN echo "VITE_API_BASE_URL=${VITE_API_BASE_URL}" > .env.production # Build the application RUN npm run build # Stage 2: Serve the application with Nginx FROM nginx:alpine # Set working directory WORKDIR /usr/share/nginx/html # Remove default Nginx assets RUN rm -rf ./* # Copy built assets from the builder stage COPY --from=builder /app/dist . # Expose port 80 EXPOSE 80 # Start Nginx CMD ["nginx", "-g", "daemon off;"]