# STAGE 1: Build the React application FROM node:20-alpine AS build WORKDIR /app # Copy package files and install dependencies COPY package.json package-lock.json ./ RUN npm install # Copy the rest of the application source code COPY . . # Build the application for production RUN npm run build # STAGE 2: Serve the static files with Nginx FROM nginx:alpine # Copy the built files from the build stage COPY --from=build /app/dist /usr/share/nginx/html # Copy our custom Nginx configuration # This config is for a Single Page Application (SPA) and listens on port 8080 for Cloud Run RUN echo 'server { listen 8080; server_name _; root /usr/share/nginx/html; index index.html; location / { try_files $uri $uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf # Expose the port Nginx is listening on EXPOSE 8080 # Command to run Nginx in the foreground CMD ["nginx", "-g", "daemon off;"]