Add package version pruning to CI workflow
This commit is contained in:
@@ -29,3 +29,29 @@ jobs:
|
||||
run: |
|
||||
docker push gitea.niq-dev.com/gitea_admin/landing:${{ gitea.sha }}
|
||||
docker push gitea.niq-dev.com/gitea_admin/landing:latest
|
||||
|
||||
- name: Prune old package versions (keep newest 5)
|
||||
# Gitea container registry 沒有內建的 retention 機制,每次
|
||||
# push 都用 commit-sha 當 tag,不清理的話會無限累積把
|
||||
# gitea PVC(10Gi)塞滿。Package API 對同一個 build 會列出
|
||||
# 4 筆版本記錄:一筆 "latest"、一筆 commit-sha、兩筆
|
||||
# "sha256:<digest>"(manifest digest,由 tag 指向,不是
|
||||
# 獨立可清的東西)。只針對 version 是 40 字元 hex(commit
|
||||
# sha 格式)的記錄做「保留最新 5 筆」,latest 永遠保留、
|
||||
# sha256: 開頭的 digest 記錄不主動處理,避免誤刪或刪掉
|
||||
# 還在被引用的 manifest。
|
||||
run: |
|
||||
VERSIONS=$(curl -s -H "Authorization: token ${{ secrets.CI_REGISTRY_TOKEN }}" \
|
||||
"https://gitea.niq-dev.com/api/v1/packages/gitea_admin/container/landing" \
|
||||
| python3 -c "
|
||||
import json, sys, re
|
||||
data = json.load(sys.stdin)
|
||||
sha_versions = [v for v in data if re.fullmatch(r'[0-9a-f]{40}', v['version'])]
|
||||
sha_versions.sort(key=lambda v: v['created_at'], reverse=True)
|
||||
print('\n'.join(str(v['id']) for v in sha_versions[5:]))
|
||||
")
|
||||
for id in $VERSIONS; do
|
||||
echo "Deleting package version id=$id"
|
||||
curl -s -X DELETE -H "Authorization: token ${{ secrets.CI_REGISTRY_TOKEN }}" \
|
||||
"https://gitea.niq-dev.com/api/v1/packages/gitea_admin/container/landing/$id"
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user