FROM node:22-alpine AS build-stage

WORKDIR /app
RUN corepack enable
RUN corepack prepare pnpm@11.1.3 --activate

RUN npm config set registry https://registry.npmmirror.com

COPY .npmrc package.json pnpm-lock.yaml pnpm-workspace.yaml tsconfig.base.json ./
COPY web/package.json web/package.json
RUN pnpm install --frozen-lockfile --filter @simple-template/web...

COPY web web
WORKDIR /app/web
RUN pnpm build

FROM nginx:stable-alpine AS production-stage

COPY --from=build-stage /app/web/dist /usr/share/nginx/html
COPY web/nginx/default.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

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