# client/Dockerfile -- Multi-stage React/Vite production build
# Stage 1 (deps): Install node_modules (cached unless package.json changes)
# Stage 2 (build): Build static assets with Vite
# Stage 3 (production): Serve with Nginx Alpine (~25MB final image)

# --- Stage 1: Install dependencies ---
FROM node:22-slim AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci

# --- Stage 2: Build application ---
FROM node:22-slim AS build
WORKDIR /app
# Copy node_modules from deps stage
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build-time environment variables (baked into static files)
ARG VITE_API_URL=/api
ENV VITE_API_URL=${VITE_API_URL}
RUN npm run build

# --- Stage 3: Production Nginx image ---
FROM nginx:1.27-alpine AS production
# Copy built static files from build stage
COPY --from=build /app/dist /usr/share/nginx/html
# Copy custom Nginx config for SPA routing (try_files fallback to index.html)
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Nginx runs as non-root by default in Alpine image
EXPOSE 80
# Default CMD from nginx image: ["nginx", "-g", "daemon off;"]
