build-flow.portal/Dockerfile
xiangning 5b34880b11 perf(docker): base 镜像走 Harbor Proxy Cache
node/nginx FROM 改走 dockerhub-proxy,经 Harbor 回源 docker.io 本地缓存,
避免公网拉取超时。
2026-07-17 12:13:03 +08:00

37 lines
1.3 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 多阶段构建:第一阶段用 Node 构建产物,第二阶段用 Nginx 托管静态资源
# 用 Node 22 LTS:Node 20.19.x 上 corepack/pnpm 现代版有 VM builtin module 兼容问题
# base 镜像走 Harbor Proxy Cache(dockerhub-proxy → docker.io),避免公网拉取超时
FROM 43.134.235.58:58080/dockerhub-proxy/library/node:22-alpine AS builder
WORKDIR /app
# 用 npm 全局安装 pnpm(与本地 11.9.0 对齐)
# corepack 在 alpine 上即便 prepare 也不可靠 shim 出 pnpm 命令,npm 装最稳妥
RUN npm install -g pnpm@11.9.0
# 先拷贝依赖清单,利用 Docker 层缓存
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
# 拷贝源码并构建(lint + 类型检查 + 构建,任一步失败则整体失败,构成质量门禁)
COPY . .
RUN pnpm lint && pnpm check && pnpm build
# ---- 运行阶段 ----
FROM 43.134.235.58:58080/dockerhub-proxy/library/nginx:1.27-alpine AS runtime
# 替换默认配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 拷贝构建产物到 Nginx 静态目录
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 5173
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget -q --spider http://127.0.0.1:5173/ || exit 1
CMD ["nginx", "-g", "daemon off;"]