FROM node:24.15.0-bookworm AS build
WORKDIR /workspace
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm test && npm run build

FROM nginx:1.28-alpine AS runtime
ENV BACKEND_UPSTREAM=backend:8080
COPY nginx/default.conf.template /etc/nginx/templates/default.conf.template
EXPOSE 8080

# CI supplies the production output it has already built and tested.
FROM runtime AS prebuilt
COPY dist/agiledancers-fe/browser/ /usr/share/nginx/html/

FROM runtime AS standalone
COPY --from=build /workspace/dist/agiledancers-fe/browser/ /usr/share/nginx/html/
