Cybersecurity-Projects/PROJECTS/intermediate/api-security-scanner/conf/docker/prod/vite.docker

48 lines
1.0 KiB
Docker

# ⒸAngelaMos | 2025
# Production Vite Dockerfile (Multi-stage build)
# Stage 1: Build the React app with Vite
# Stage 2: Serve static files with Nginx
# Stage 1: Build
FROM node:20-alpine AS builder
WORKDIR /app
# Install pnpm
RUN npm install -g pnpm
# Copy package files
COPY frontend/package.json frontend/pnpm-lock.yaml ./
# Install dependencies (including dev deps for build)
RUN pnpm install --frozen-lockfile
# Copy source code
COPY frontend/ .
# Build the app (creates dist/ folder with static files)
RUN pnpm run build
# Stage 2: Serve with Nginx
FROM nginx:alpine
# Copy built static files from builder stage
COPY --from=builder /app/dist /usr/share/nginx/html
# Copy nginx configurations
COPY conf/nginx/prod.nginx /etc/nginx/nginx.conf
COPY conf/nginx/http.conf /etc/nginx/http.conf
# Expose port
EXPOSE 80
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --quiet --tries=1 --spider http://localhost/health || exit 1
# Start nginx
CMD ["nginx", "-g", "daemon off;"]