FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:22-bookworm-slim AS browser-tests
WORKDIR /app
COPY package*.json ./
RUN npm ci && npx playwright install --with-deps chromium --only-shell
COPY tests ./tests
COPY src/navigation.ts ./src/navigation.ts
COPY playwright.config.ts ./
CMD ["npm", "run", "test:ci"]

FROM nginx:1.27-alpine AS runtime
COPY --from=build /app/dist /usr/share/nginx/html
COPY deploy/default.conf.template /etc/nginx/templates/default.conf.template
ENV API_UPSTREAM=http://host.docker.internal:18080
EXPOSE 80
HEALTHCHECK --interval=10s --timeout=3s CMD wget -q -O /dev/null http://127.0.0.1/healthz || exit 1
