ci: ACR镜像清理策略 + CI自动清理 #593

Merged
auto-approve-bot merged 2 commits from ci/acr-cleanup into develop 2026-07-19 17:33:34 +08:00
Owner

变更内容

1. 清理脚本 scripts/ci/acr_cleanup.py

ACR镜像生命周期管理工具,纯Python标准库实现,无额外依赖。

清理策略:

  • 版本tag (v*):永久保留
  • 固定tag (latest, main, develop, master, dev, stable):永久保留
  • 缓存镜像仓库 (api-cache, worker-cache, web-cache):全部跳过
  • PR预览tag (pr-*):保留7天,过期自动删除
  • 📊 Commit hash tag:保留最近 20个,超过自动清理

特性:

  • 支持 --dry-run 预览模式
  • 支持 --keep N 自定义保留数量
  • 支持 --pr-days N 自定义PR保留天数
  • 支持 --repo NAME 指定单个仓库
  • 按manifest digest去重,避免重复删除
  • 兼容ACR的OCI index多架构格式

2. CI清理job ci-build.yml

新增 acr-cleanup job,在 build-staging 完成后自动执行:

  • 触发条件:push到 main / develop 分支
  • 每次构建推送镜像后自动清理老镜像,保持仓库整洁
  • 失败时通过飞书通知

验证结果

仓库 清理前 清理后 删除数 失败
xiaoxia-saas-api 110 20 90 0
xiaoxia-saas-worker 110 20 90 0
xiaoxia-saas-web 102 20 82 0
缓存仓库x3 3 3 - 跳过
合计 325 63 262 0
  • 删除成功率:100%(262/262)

  • 最早保留时间:API 7/16、Worker 7/15、Web 7/17(均覆盖最近3-4天构建)

  • 执行时长:约5分钟

  • dry-run预览验证通过

  • 全量实际清理执行完成

  • 清理后tag数验证正确

## 变更内容 ### 1. 清理脚本 `scripts/ci/acr_cleanup.py` ACR镜像生命周期管理工具,纯Python标准库实现,无额外依赖。 **清理策略:** - ✅ 版本tag (`v*`):永久保留 - ✅ 固定tag (`latest`, `main`, `develop`, `master`, `dev`, `stable`):永久保留 - ✅ 缓存镜像仓库 (`api-cache`, `worker-cache`, `web-cache`):全部跳过 - ⏰ PR预览tag (`pr-*`):保留7天,过期自动删除 - 📊 Commit hash tag:保留最近 **20个**,超过自动清理 **特性:** - 支持 `--dry-run` 预览模式 - 支持 `--keep N` 自定义保留数量 - 支持 `--pr-days N` 自定义PR保留天数 - 支持 `--repo NAME` 指定单个仓库 - 按manifest digest去重,避免重复删除 - 兼容ACR的OCI index多架构格式 ### 2. CI清理job `ci-build.yml` 新增 `acr-cleanup` job,在 `build-staging` 完成后自动执行: - 触发条件:push到 `main` / `develop` 分支 - 每次构建推送镜像后自动清理老镜像,保持仓库整洁 - 失败时通过飞书通知 ## 验证结果 ✅ | 仓库 | 清理前 | 清理后 | 删除数 | 失败 | |------|--------|--------|--------|------| | xiaoxia-saas-api | 110 | 20 | 90 | 0 | | xiaoxia-saas-worker | 110 | 20 | 90 | 0 | | xiaoxia-saas-web | 102 | 20 | 82 | 0 | | 缓存仓库x3 | 3 | 3 | - | 跳过 | | **合计** | **325** | **63** | **262** | **0** | - 删除成功率:**100%**(262/262) - 最早保留时间:API 7/16、Worker 7/15、Web 7/17(均覆盖最近3-4天构建) - 执行时长:约5分钟 - [x] dry-run预览验证通过 - [x] 全量实际清理执行完成 - [x] 清理后tag数验证正确
xiaoxia added 1 commit 2026-07-19 15:46:46 +08:00
ci: add ACR image cleanup workflow
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 16s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 16s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
AI Code Review / AI Code Review (pull_request) Failing after 31s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 3m56s
Auto Merge CI PRs / Auto Merge on CI Green + Approved (pull_request) Successful in 4m16s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 7m8s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 4m4s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 9m9s
Auto Approve CI PRs / Auto Approve on CI Green (pull_request) Successful in 9m42s
792ef76716
- Add scripts/ci/acr_cleanup.py for ACR image lifecycle management
- Cleanup strategy: version tags and fixed tags kept forever, PR tags kept 7 days, commit hash tags kept last 20
- Add acr-cleanup job to ci-build.yml, runs after build-staging on main/develop push
- Supports dry-run mode for preview before execution
- Uses Docker Registry V2 API with OCI index support (ACR multi-arch format)
xiaoxia added 1 commit 2026-07-19 17:09:43 +08:00
fix: isort import排序修复
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 15s
AI Code Review / AI Code Review (pull_request) Failing after 28s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 4s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 3m37s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 4m56s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 7m15s
Auto Approve CI PRs / Auto Approve on CI Green (pull_request) Successful in 11m49s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 4m7s
Auto Merge CI PRs / Auto Merge on CI Green + Approved (pull_request) Successful in 18m12s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 1m10s
2adaf02638
auto-approve-bot approved these changes 2026-07-19 17:26:26 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot approved these changes 2026-07-19 17:26:26 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot merged commit bf137350c6 into develop 2026-07-19 17:33:34 +08:00
auto-approve-bot deleted branch ci/acr-cleanup 2026-07-19 17:33:35 +08:00

🗑️ 预览环境已清理

PR #593 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #593 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.