# Frontend production image: 2-stage build (node build -> nginx serve), rooted at the
# APPLICATION (standalone / app-creator shape — no framework monorepo build context).
# The nginx CSP config is a managed region owned by `wildo dev sync-csp --service app`;
# run it before building so the baked headers match the target environment.
ARG NODE_IMAGE=node:22-alpine

FROM ${NODE_IMAGE} AS builder
WORKDIR /workspace

ARG VITE_APP_NAME
ARG VITE_FRONTEND_SERVICE_NAME
ARG VITE_API_BASE_URL
ENV VITE_APP_NAME=${VITE_APP_NAME} \
    VITE_FRONTEND_SERVICE_NAME=${VITE_FRONTEND_SERVICE_NAME} \
    VITE_API_BASE_URL=${VITE_API_BASE_URL}

RUN corepack enable
COPY . .
RUN pnpm install --frozen-lockfile
RUN pnpm --filter ./frontend run build

FROM nginx:1.27-alpine
COPY --from=builder /workspace/frontend/dist /usr/share/nginx/html
COPY --from=builder /workspace/frontend/nginx-config/default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
