Skip to content

Commit d41bd2c

Browse files
committed
fix: 修复 GitHub Actions Docker 构建 SSL 证书过期问题
- Dockerfile 添加 NPM_REGISTRY build-arg,默认保持 npmmirror 兼容本地构建 - CI 中传入官方 registry 绕过镜像证书过期
1 parent 0695c73 commit d41bd2c

3 files changed

Lines changed: 1041 additions & 1007 deletions

File tree

.github/workflows/docker.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ jobs:
5252
uses: docker/build-push-action@v6
5353
with:
5454
context: .
55+
pull: true
5556
push: ${{ github.event_name != 'pull_request' }}
5657
tags: ${{ steps.meta.outputs.tags }}
5758
labels: ${{ steps.meta.outputs.labels }}
5859
cache-from: type=gha
5960
cache-to: type=gha,mode=max
61+
build-args: |
62+
NPM_REGISTRY=https://registry.npmjs.org

Dockerfile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1+
# 全局参数:镜像源(CI 时通过 --build-arg NPM_REGISTRY=... 覆盖)
2+
ARG NPM_REGISTRY=https://registry.npmjs.org/
3+
14
# 阶段1:基础镜像准备
2-
FROM node:18-alpine AS base
5+
FROM node:24-alpine AS base
6+
7+
ARG NPM_REGISTRY
38

49
# 设置工作目录
510
WORKDIR /app
611

7-
# 配置国内镜像源
8-
RUN npm config set registry https://registry.npmmirror.com/
12+
# 配置镜像源
13+
RUN npm config set registry ${NPM_REGISTRY}
914

1015
# 安装必要的系统依赖(例如 CA 证书)
11-
RUN apk add --no-cache ca-certificates
16+
RUN apk update && apk add --no-cache ca-certificates && update-ca-certificates
1217

1318
# 阶段2:构建应用程序
1419
FROM base AS builder
1520

21+
ARG NPM_REGISTRY
22+
1623
WORKDIR /app
1724

1825
# 复制依赖文件
1926
COPY package.json yarn.lock ./
2027

2128
# 安装所有依赖,包括开发依赖
29+
RUN yarn config set registry ${NPM_REGISTRY}
2230
RUN yarn install
2331

2432
# 复制项目源代码
@@ -40,7 +48,7 @@ RUN yarn install --production --ignore-scripts --prefer-offline
4048
RUN yarn cache clean --all
4149

4250
# 阶段3:构建最终的生产镜像
43-
FROM node:18-alpine
51+
FROM node:24-alpine
4452

4553
# 设置工作目录
4654
WORKDIR /app

0 commit comments

Comments
 (0)