# Stage 1: Build the React application FROM node:18-alpine AS build WORKDIR /app # Copy package.json and yarn.lock COPY package.json yarn.lock ./ # Install dependencies RUN yarn install --frozen-lockfile # Copy the rest of the application source code COPY . . # Set the production environment variable for the build ARG VITE_BACKEND_URL_PROD ENV VITE_BACKEND_URL=${VITE_BACKEND_URL_PROD} # Build for production RUN yarn build # Stage 2: Serve the application with Nginx FROM nginx:1.21-alpine # Copy the built files from the build stage COPY --from=build /app/dist /usr/share/nginx/html # Copy a basic Nginx configuration COPY nginx.prod.conf /etc/nginx/conf.d/default.conf # Expose port 80 EXPOSE 80 # Start Nginx CMD ["nginx", "-g", "daemon off;"]