# syntax=docker/dockerfile:1.7

FROM node:22-alpine AS deps
WORKDIR /workspace

COPY package.json package-lock.json ./
COPY apps/frontend/package.json apps/frontend/package.json
COPY apps/backend/auth-service/package.json apps/backend/auth-service/package.json
COPY packages/api-client/package.json packages/api-client/package.json
COPY packages/openclaw-plugin/package.json packages/openclaw-plugin/package.json
RUN npm ci

FROM deps AS build
WORKDIR /workspace

ARG VITE_FRONTEND_URL=http://localhost:3000
ARG VITE_AUTH_URL=http://localhost:3001
ARG VITE_API_URL=http://localhost:8080
ARG VITE_DEV_MAILBOX_ENABLED=true
ENV VITE_FRONTEND_URL=${VITE_FRONTEND_URL}
ENV VITE_AUTH_URL=${VITE_AUTH_URL}
ENV VITE_API_URL=${VITE_API_URL}
ENV VITE_DEV_MAILBOX_ENABLED=${VITE_DEV_MAILBOX_ENABLED}

COPY . .
RUN npm run gen:api && npm run build -w apps/frontend

FROM nginx:alpine AS runtime
WORKDIR /usr/share/nginx/html

COPY --from=build /workspace/apps/frontend/dist .
COPY apps/frontend/nginx.conf /etc/nginx/conf.d/default.conf

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