fix(ci): 修复registry不稳定导致镜像构建失败 - 解耦缓存推送 #357

Merged
xiaoxia merged 1 commits from ci/registry-cache-stability-fix into develop 2026-07-15 12:55:13 +08:00
Owner

问题

Worker镜像构建失败,错误为 use of closed network connection,发生在 buildx 推送缓存到 registry 阶段。

根因:Gitea 内置 registry 在传输大缓存层时连接不稳定,长连接被断开。虽然镜像本身已构建完成,但缓存推送失败导致整个构建步骤失败。

修复方案

1. 构建与缓存解耦(核心修复)

创建 scripts/ci/docker_build_push.sh 通用构建脚本:

  • Step 1: 构建+推送镜像(只读缓存模式),保证主构建100%成功
  • Step 2: 单独尝试推送缓存,自动重试3次,失败不影响主构建结果

2. 缓存优化

  • 缓存使用 mode=min + compression=zstd + oci-mediatypes=true 减小传输体积
  • 缓存引用改为按分支名区分,支持多分支独立缓存

3. 覆盖范围

全部6个镜像构建job(Staging/Production x API/Worker/Web)

验证

  • CI三门禁通过
  • Staging构建成功(核心验证目标)
  • 缓存推送在重试后成功或优雅降级
## 问题 Worker镜像构建失败,错误为 `use of closed network connection`,发生在 buildx 推送缓存到 registry 阶段。 根因:Gitea 内置 registry 在传输大缓存层时连接不稳定,长连接被断开。虽然镜像本身已构建完成,但缓存推送失败导致整个构建步骤失败。 ## 修复方案 ### 1. 构建与缓存解耦(核心修复) 创建 `scripts/ci/docker_build_push.sh` 通用构建脚本: - **Step 1**: 构建+推送镜像(只读缓存模式),保证主构建100%成功 - **Step 2**: 单独尝试推送缓存,自动重试3次,失败不影响主构建结果 ### 2. 缓存优化 - 缓存使用 `mode=min` + `compression=zstd` + `oci-mediatypes=true` 减小传输体积 - 缓存引用改为按分支名区分,支持多分支独立缓存 ### 3. 覆盖范围 全部6个镜像构建job(Staging/Production x API/Worker/Web) ## 验证 - [ ] CI三门禁通过 - [ ] Staging构建成功(核心验证目标) - [ ] 缓存推送在重试后成功或优雅降级
xiaoxia force-pushed ci/registry-cache-stability-fix from f55d574291 to c94ce7c1e1 2026-07-15 12:14:31 +08:00 Compare
xiaoxia force-pushed ci/registry-cache-stability-fix from c94ce7c1e1 to 446e3500f6 2026-07-15 12:17:56 +08:00 Compare
xiaoxia added 1 commit 2026-07-15 12:33:05 +08:00
fix(ci): 修复registry不稳定导致构建失败 - 构建与缓存推送解耦
CI/CD Pipeline / Frontend Lint (push) Successful in 1m32s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m31s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 2m44s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m49s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Validate Code Quality And Tests (push) Successful in 2m52s
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (push) Successful in 2m54s
CI/CD Pipeline / Build Staging API Image (push) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (push) Has been skipped
CI/CD Pipeline / Build Staging Web Image (push) Has been skipped
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (push) Has been skipped
CI/CD Pipeline / Staging E2E Tests (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m29s
CI/CD Pipeline / Integration Tests (push) Successful in 1m25s
99fa146a5c
- 新增docker_build_push.sh通用脚本
- 构建镜像(只读缓存)与推送缓存分离
- 缓存推送失败重试3次,不影响主构建结果
- 使用zstd压缩缓存层
xiaoxia force-pushed ci/registry-cache-stability-fix from 1058801264 to 99fa146a5c 2026-07-15 12:33:05 +08:00 Compare
auto-approve-bot approved these changes 2026-07-15 12:50:02 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
xiaoxia merged commit d3ed0bb4ba into develop 2026-07-15 12:55:13 +08:00
Sign in to join this conversation.