# Build stage FROM node:20-alpine AS builder WORKDIR /app # Copy package files COPY package*.json ./ # Install dependencies RUN npm ci # Copy source code COPY . . # Build arguments for environment variables ARG VITE_API_URL ENV VITE_API_URL=$VITE_API_URL # Build the application RUN npm run build # Production stage - nginx FROM nginx:alpine AS production # Copy custom nginx config COPY nginx.conf /etc/nginx/conf.d/default.conf # Copy built application COPY --from=builder /app/dist /usr/share/nginx/html # Create non-root user RUN addgroup -g 1001 -S nginx-user && \ adduser -S nginx-user -u 1001 -G nginx-user && \ chown -R nginx-user:nginx-user /usr/share/nginx/html && \ chown -R nginx-user:nginx-user /var/cache/nginx && \ chown -R nginx-user:nginx-user /var/log/nginx && \ touch /var/run/nginx.pid && \ chown -R nginx-user:nginx-user /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;"]