# ── Frontend Production Image ────────────────────────────────────────
# Stage 1: Build Vue 3 app with Vite
# Stage 2: Serve static files with Nginx (includes reverse proxy)
# ─────────────────────────────────────────────────────────────────────

# ── Stage 1: Build ───────────────────────────────────────────────────
FROM node:20-alpine AS builder

WORKDIR /build

# Dependencies layer (cached unless package files change)
COPY frontend/package.json frontend/package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
    npm ci

# Copy source and build
COPY frontend/ ./
RUN npm run build

# ── Stage 2: Nginx Runtime ──────────────────────────────────────────
FROM nginx:alpine

# Remove default nginx config
RUN rm -f /etc/nginx/conf.d/default.conf

# Copy production nginx config
COPY docker/nginx/nginx.prod.conf /etc/nginx/nginx.conf

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

EXPOSE 10038

# Nginx runs in foreground
CMD ["nginx", "-g", "daemon off;"]
