FROM node:22-alpine AS builder

WORKDIR /app

ENV PNPM_HOME=/pnpm \
    PATH=/pnpm:$PATH \
    NODE_OPTIONS=--max-old-space-size=4096

RUN corepack enable

COPY web/ ./

RUN pnpm install --frozen-lockfile

ARG VITE_APP_TITLE=AI Agent Admin
ARG VITE_BASE=/ai-agent-admin/
ARG VITE_GLOB_API_URL=/ai-agent-admin/basic-api

ENV VITE_APP_TITLE=$VITE_APP_TITLE \
    VITE_BASE=$VITE_BASE \
    VITE_GLOB_API_URL=$VITE_GLOB_API_URL \
    VITE_COMPRESS=none \
    VITE_PWA=false

RUN pnpm --filter @vben/web-ele build

FROM nginx:1.27-alpine

COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf
COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/apps/web-ele/dist/ /usr/share/nginx/html/ai-agent-admin/

EXPOSE 80

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