# syntax=docker/dockerfile:1

FROM node:22-slim AS builder

WORKDIR /workspace

RUN corepack enable && corepack prepare pnpm@9.15.0 --activate

COPY pnpm-workspace.yaml package.json pnpm-lock.yaml .npmrc ./
COPY client/package.json ./client/
COPY brain-nest/package.json ./brain-nest/
COPY extractor-ts/package.json ./extractor-ts/
COPY transcriber-ts/package.json ./transcriber-ts/

RUN pnpm install --frozen-lockfile --filter frontend...

COPY client/ ./client/

ARG VITE_API_URL=
ENV VITE_API_URL=${VITE_API_URL}
# Keep heap below typical Docker Desktop build limits; mermaid is loaded from /vendor at runtime.
ENV NODE_OPTIONS=--max-old-space-size=3072

RUN pnpm --filter frontend build

FROM nginx:alpine AS runtime

COPY client/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /workspace/client/dist /usr/share/nginx/html

EXPOSE 80

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