improve: use alibaba mirror for maven and npmmirror for pnpm

This commit is contained in:
2026-09-21 13:07:50 +08:00
parent a23e2f600a
commit 931d3ee1b7
3 changed files with 80 additions and 7 deletions

View File

@@ -1,24 +1,30 @@
# =====================================================================
# 前端镜像:pnpm 构建静态资源 -> Nginx 托管(同时反代 /api 到后端)
# 构建:docker build -t lab-frontend ./frontend
#
# 国内加速:npm/pnpm 使用 npmmirror(淘宝镜像)
# 如需走官方源:docker build --build-arg NPM_REGISTRY=https://registry.npmjs.org -t lab-frontend ./frontend
# =====================================================================
# ---------- 构建阶段 ----------
FROM docker.io/library/node:24-alpine AS build
FROM node:24-alpine AS build
WORKDIR /app
# 使用与本地一致的 pnpm 主版本,锁定依赖保证可复现
RUN npm install -g pnpm@11.3.0
# 使用 npmmirror 加速 npm 全局安装与依赖拉取
ARG NPM_REGISTRY=https://registry.npmmirror.com
RUN npm config set registry "$NPM_REGISTRY" \
&& npm install -g pnpm@11.3.0 \
&& pnpm config set registry "$NPM_REGISTRY"
# 先装依赖,充分利用层缓存
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
RUN pnpm install --frozen-lockfile --registry="$NPM_REGISTRY"
COPY . .
RUN pnpm build
# ---------- 运行阶段 ----------
FROM docker.io/library/nginx:1.27-alpine
FROM nginx:1.27-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html