# Frontend Dockerfile - React with multi-stage build # Stage 1: Build FROM node:20-alpine AS builder WORKDIR /app # Copy package files COPY package.json yarn.lock ./ # Install dependencies RUN yarn install --frozen-lockfile # Copy source code COPY . . # Build arguments for environment variables ARG REACT_APP_BACKEND_URL ENV REACT_APP_BACKEND_URL=$REACT_APP_BACKEND_URL # Build the application RUN yarn build # Stage 2: Production with Nginx FROM nginx:alpine AS production # Copy custom nginx config COPY nginx.conf /etc/nginx/conf.d/default.conf # Copy built assets from builder stage COPY --from=builder /app/build /usr/share/nginx/html # Create non-root user for security RUN adduser -D -g '' appuser && \ chown -R appuser:appuser /usr/share/nginx/html && \ chown -R appuser:appuser /var/cache/nginx && \ chown -R appuser:appuser /var/log/nginx && \ touch /var/run/nginx.pid && \ chown -R appuser:appuser /var/run/nginx.pid # Expose port EXPOSE 80 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1 # Start nginx CMD ["nginx", "-g", "daemon off;"]