# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM node:25-alpine AS builder

WORKDIR /build

RUN npm install -g pnpm@10

COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./

COPY packages ./packages
COPY apps ./apps

RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
    pnpm install

ARG VITE_API_URL=/api

ENV VITE_API_URL=$VITE_API_URL

WORKDIR /build/apps/web
RUN pnpm build

FROM nginx:alpine

COPY --from=builder /build/apps/web/dist /usr/share/nginx/html

COPY docker/nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 8082

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD wget --no-verbose --tries=1 --spider http://localhost:8082/health || exit 1

CMD ["nginx", "-g", "daemon off;"]
