# Production image for the admin/council SPA (frontend_admin).
# Multi-stage: build the minified bundle in the npm workspace, then serve it with nginx.
# The runtime image holds ONLY static files — no Node, no source, no Vite dev server.
#
# Build context = repo ROOT (the npm workspace):
#   docker build -f frontend_admin/Dockerfile.prod -t frontend_admin .

# ---- build stage ----
FROM node:22-alpine AS build
WORKDIR /app

# Workspace manifests first (layer cache); all three are needed for `npm ci` to resolve.
COPY package.json package-lock.json ./
COPY shared/package.json ./shared/
COPY frontend_user/package.json ./frontend_user/
COPY frontend_admin/package.json ./frontend_admin/
COPY frontend_investigator/package.json ./frontend_investigator/
COPY frontend_publisher/package.json ./frontend_publisher/
RUN npm ci

# Only the sources this app needs: the admin app + the shared kernel (consumed as source).
COPY shared ./shared
COPY frontend_admin ./frontend_admin

# Vite production build → /app/frontend_admin/dist (minified, sourcemap:false).
RUN npm run build -w frontend_admin

# ---- runtime stage (static only) ----
FROM nginx:1.27-alpine
RUN rm -rf /usr/share/nginx/html/*
COPY frontend_admin/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/frontend_admin/dist /usr/share/nginx/html
EXPOSE 8080
CMD ["nginx", "-g", "daemon off;"]
