FROM node:24-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json* ./
COPY local-packages/ ./local-packages/
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc \
    npm install --legacy-peer-deps

FROM deps AS base
COPY . .

FROM base AS portal-build
RUN npm run build:portal

FROM base AS backoffice-build
RUN npm run build:backoffice

FROM nginx:1.29-alpine AS portal
COPY --from=portal-build /app/dist/apps/portal /usr/share/nginx/html
COPY nginx/portal.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

FROM nginx:1.29-alpine AS backoffice
COPY --from=backoffice-build /app/dist/apps/backoffice /usr/share/nginx/html
COPY nginx/backoffice.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
