# ---- Production Dockerfile for React frontend ----
# Multi-stage build: compile to static assets, serve with nginx

# Stage 1: Build
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
# VERSION must be copied into the build context before `docker build`.
# In CI / deploy scripts run: cp VERSION frontend/VERSION  (or pass VITE_APP_VERSION as build arg)
COPY VERSION ./
RUN npm run build

# Stage 2: Serve with nginx
FROM nginx:alpine

# Copy the built static files
COPY --from=builder /app/dist /usr/share/nginx/html

# Copy a small nginx config for SPA routing
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 3001
CMD ["nginx", "-g", "daemon off;"]
