# 前端构建脚本
FROM --platform=$BUILDPLATFORM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/node:24-slim AS builder

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV NODE_OPTIONS=--max-old-space-size=8192
ENV TZ=Asia/Shanghai

RUN npm install -g pnpm@10.17.1

WORKDIR /app

COPY . /app

RUN --mount=type=cache,id=easyflow-admin-pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run build

FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:stable-alpine AS production

RUN rm -f /etc/nginx/conf.d/default.conf

COPY --from=builder /app/app/dist/ /usr/share/nginx/html/flow/
COPY scripts/deploy/nginx.conf /etc/nginx/nginx.conf

RUN nginx -t && chown -R nginx:nginx /usr/share/nginx/html

EXPOSE 80

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