2025-12-23 11:55:54 +08:00
|
|
|
|
# ==============================
|
|
|
|
|
|
# 1️⃣ 构建阶段
|
|
|
|
|
|
# ==============================
|
2025-12-18 12:04:23 +08:00
|
|
|
|
FROM node:20-alpine AS builder
|
|
|
|
|
|
|
2025-12-23 11:55:54 +08:00
|
|
|
|
# 设置工作目录
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------
|
|
|
|
|
|
# 设置 npm / pnpm registry
|
|
|
|
|
|
# ------------------------------
|
|
|
|
|
|
# npm 镜像源(淘宝镜像加速)
|
2025-12-18 13:36:13 +08:00
|
|
|
|
RUN npm config set registry https://registry.npmmirror.com && \
|
|
|
|
|
|
echo "registry=https://registry.npmmirror.com" > ~/.npmrc
|
2025-12-18 12:04:23 +08:00
|
|
|
|
|
2025-12-23 11:55:54 +08:00
|
|
|
|
# pnpm registry 指向 Verdaccio
|
|
|
|
|
|
ARG PNPM_REGISTRY=http://1Panel-verdaccio-Ynee:4873/
|
2025-12-18 14:20:06 +08:00
|
|
|
|
ENV PNPM_HOME="/pnpm"
|
|
|
|
|
|
ENV PATH="$PNPM_HOME:$PATH"
|
2025-12-18 13:36:13 +08:00
|
|
|
|
RUN corepack enable && corepack prepare pnpm@10.22.0 --activate
|
2025-12-23 11:55:54 +08:00
|
|
|
|
RUN pnpm config set registry $PNPM_REGISTRY
|
|
|
|
|
|
RUN pnpm config set store-dir /pnpm/store
|
2025-12-18 13:36:13 +08:00
|
|
|
|
|
2025-12-23 11:55:54 +08:00
|
|
|
|
# ------------------------------
|
|
|
|
|
|
# Docker BuildKit 缓存 pnpm store
|
|
|
|
|
|
# ------------------------------
|
|
|
|
|
|
# 复制依赖描述文件,利用缓存层
|
2025-12-18 13:45:29 +08:00
|
|
|
|
COPY package.json pnpm-lock.yaml turbo.json pnpm-workspace.yaml ./
|
2025-12-18 12:04:23 +08:00
|
|
|
|
|
2025-12-23 11:55:54 +08:00
|
|
|
|
# 复制源码文件
|
2025-12-18 13:36:13 +08:00
|
|
|
|
COPY packages packages
|
|
|
|
|
|
COPY apps apps
|
2025-12-18 13:47:15 +08:00
|
|
|
|
COPY internal internal
|
2025-12-18 13:36:13 +08:00
|
|
|
|
|
|
|
|
|
|
# 安装依赖
|
2025-12-23 11:55:54 +08:00
|
|
|
|
# network-concurrency 限制并发下载,降低带宽占用
|
2025-12-18 14:20:06 +08:00
|
|
|
|
RUN --mount=type=cache,id=pnpm-store,target=/pnpm/store \
|
2025-12-23 11:55:54 +08:00
|
|
|
|
pnpm install --frozen-lockfile --network-concurrency 2
|
2025-12-18 12:04:23 +08:00
|
|
|
|
|
2025-12-23 13:14:48 +08:00
|
|
|
|
# 限制turbo并发构建,降低资源占用(仅CI/CD构建时生效)
|
|
|
|
|
|
# 直接使用turbo命令并限制并发数,避免影响本地开发配置
|
|
|
|
|
|
RUN pnpm exec turbo build --filter=@vben/web-antd --concurrency=2
|
2025-12-18 12:04:23 +08:00
|
|
|
|
|
2025-12-23 11:55:54 +08:00
|
|
|
|
# ==============================
|
|
|
|
|
|
# 2️⃣ 运行阶段
|
|
|
|
|
|
# ==============================
|
2025-12-18 12:04:23 +08:00
|
|
|
|
FROM nginx:alpine
|
|
|
|
|
|
|
|
|
|
|
|
# 移除默认配置
|
|
|
|
|
|
RUN rm /etc/nginx/conf.d/default.conf
|
|
|
|
|
|
|
|
|
|
|
|
# 复制自定义 Nginx 配置
|
|
|
|
|
|
COPY apps/web-antd/nginx.conf /etc/nginx/conf.d/default.conf
|
|
|
|
|
|
|
|
|
|
|
|
# 复制构建产物
|
|
|
|
|
|
COPY --from=builder /app/apps/web-antd/dist /usr/share/nginx/html
|
|
|
|
|
|
|
|
|
|
|
|
EXPOSE 80
|
|
|
|
|
|
|
|
|
|
|
|
CMD ["nginx", "-g", "daemon off;"]
|