FROM node:22-alpine AS build
WORKDIR /workspace

COPY package.json ./package.json
COPY yarn.lock ./yarn.lock
COPY tenant-platform ./tenant-platform
COPY ops-platform ./ops-platform

RUN yarn install --frozen-lockfile

ARG TENANT_APP_BASE=/
ARG OPS_APP_BASE=/ops/
ARG TENANT_API_BASE_URL=/api
ARG OPS_API_BASE_URL=/api

RUN cd tenant-platform && \
    VITE_APP_BASE=${TENANT_APP_BASE} VITE_API_BASE_URL=${TENANT_API_BASE_URL} yarn build

RUN cd ops-platform && \
    VITE_APP_BASE=${OPS_APP_BASE} VITE_API_BASE_URL=${OPS_API_BASE_URL} yarn build

FROM nginx:1.27-alpine
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /workspace/tenant-platform/dist /usr/share/nginx/html/tenant
COPY --from=build /workspace/ops-platform/dist /usr/share/nginx/html/ops
