ci: Docker镜像缓存按分支隔离 - develop写回缓存, feature分支只读 #243

Merged
xiaoxia merged 3 commits from feat/docker-cache-branch-isolation into develop 2026-07-13 12:22:58 +08:00
Owner

改动

  1. 按分支隔离缓存读写策略(核心修复)

    • develop/main 分支:读写缓存(--cache-from + --cache-to
    • feature 分支:只读缓存(仅 --cache-from,不写回)
    • 防止 feature 分支改依赖文件时污染主缓存,导致 develop 构建偶发 50min+
  2. 新增 npm 缓存 volume

    • web 构建的 node_modules 使用持久化 Docker volume
    • 避免每次 npm ci 全量下载依赖
  3. 代码重构

    • 抽取 build_with_cache 函数,消除 3 份重复的 buildx 命令
    • 缓存 tag 从 release 改为 develop,语义更清晰

背景

最近 Build Staging 偶发耗时 53min(正常 7-8min),根因是 buildx 缓存失效。
多分支共享同一缓存 tag 互相覆盖是主因。

详见:/运维文档/docker_cache_optimization.md

## 改动 1. **按分支隔离缓存读写策略**(核心修复) - develop/main 分支:读写缓存(`--cache-from` + `--cache-to`) - feature 分支:只读缓存(仅 `--cache-from`,不写回) - 防止 feature 分支改依赖文件时污染主缓存,导致 develop 构建偶发 50min+ 2. **新增 npm 缓存 volume** - web 构建的 node_modules 使用持久化 Docker volume - 避免每次 `npm ci` 全量下载依赖 3. **代码重构** - 抽取 `build_with_cache` 函数,消除 3 份重复的 buildx 命令 - 缓存 tag 从 `release` 改为 `develop`,语义更清晰 ## 背景 最近 Build Staging 偶发耗时 53min(正常 7-8min),根因是 buildx 缓存失效。 多分支共享同一缓存 tag 互相覆盖是主因。 详见:/运维文档/docker_cache_optimization.md
xiaoxia added 3 commits 2026-07-13 12:18:07 +08:00
ci: Docker镜像缓存按分支隔离 - develop写回缓存, feature分支只读
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 30s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 57s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m2s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 3m13s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production Runtime Images (pull_request) Has been skipped
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 / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
2d3f71c503
- 核心改动:按 GITHUB_REF_NAME 判断分支,develop/main 读写缓存,feature 分支只读不写
- 防止feature分支修改requirements等依赖文件时污染主缓存,导致develop构建偶发50min+
- 新增 npm 缓存 volume,web构建 node_modules 持久化,减少 npm ci 下载时间
- 缓存 tag 从 release 改为 develop,语义更清晰
- 重构 build_with_cache 函数,消除三份重复的 buildx 命令
xiaoxia force-pushed feat/docker-cache-branch-isolation from ccb01ade3d to 2d3f71c503 2026-07-13 12:18:07 +08:00 Compare
xiaoxia merged commit 5e704094f6 into develop 2026-07-13 12:22:58 +08:00
Sign in to join this conversation.