# SIOP V2 — image web (React statique derrière nginx).
# Contexte de build : RACINE du monorepo (docker build -f apps/web/Dockerfile .)

FROM node:24-slim AS builder
RUN corepack enable
WORKDIR /repo

COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY packages/shared/package.json packages/shared/package.json
COPY apps/web/package.json apps/web/package.json
RUN pnpm install --frozen-lockfile --filter @siop/web --filter @siop/shared

COPY packages/shared packages/shared
COPY apps/web apps/web
RUN pnpm --filter @siop/shared build && pnpm --filter @siop/web build

FROM nginx:1.29-alpine
# Cible du proxy /api — surchargée par le compose (réseau interne)
ENV API_UPSTREAM=siop2-api:3000
COPY apps/web/nginx/default.conf.template /etc/nginx/templates/default.conf.template
COPY --from=builder /repo/apps/web/dist /usr/share/nginx/html
EXPOSE 80
# 127.0.0.1 et non localhost : busybox wget tente ::1 alors que nginx écoute en IPv4
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
  CMD wget -q -O /dev/null http://127.0.0.1/ || exit 1
