From 749cddf561672f468cc06c7faf0841956a98c382 Mon Sep 17 00:00:00 2001 From: repair-agent Date: Thu, 2 Apr 2026 17:09:52 +0800 Subject: [PATCH] fix: use Harbor token auth for image cleanup on Volcano Engine CR Co-Authored-By: Claude Opus 4.6 (1M context) --- .gitea/workflows/deploy.yaml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 4663cb0..7e7ece9 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -135,7 +135,13 @@ jobs: for REPO in log-center-api log-center-web k8s-pod-monitor; do echo "Cleaning ${ORG}/${REPO}..." - TAGS=$(curl -s -u "${AUTH}" "https://${CR}/v2/${ORG}/${REPO}/tags/list" 2>/dev/null | \ + + # 获取 Harbor token + TOKEN=$(curl -s -u "${AUTH}" "https://${CR}/service/token?service=harbor-registry&scope=repository:${ORG}/${REPO}:pull,delete" | \ + python3 -c "import sys,json; print(json.load(sys.stdin).get('token',''))" 2>/dev/null) + + # 列出所有标签,排序后取要删除的 + TAGS=$(curl -s -H "Authorization: Bearer ${TOKEN}" "https://${CR}/v2/${ORG}/${REPO}/tags/list" | \ python3 -c " import sys,json try: @@ -148,11 +154,13 @@ jobs: " 2>/dev/null) for TAG in $TAGS; do - DIGEST=$(curl -s -I -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \ - -u "${AUTH}" "https://${CR}/v2/${ORG}/${REPO}/manifests/${TAG}" 2>/dev/null | \ + DIGEST=$(curl -s -H "Authorization: Bearer ${TOKEN}" \ + -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \ + "https://${CR}/v2/${ORG}/${REPO}/manifests/${TAG}" -o /dev/null -D - | \ grep -i docker-content-digest | awk '{print $2}' | tr -d '\r') if [ -n "$DIGEST" ]; then - curl -s -X DELETE -u "${AUTH}" "https://${CR}/v2/${ORG}/${REPO}/manifests/${DIGEST}" 2>/dev/null + curl -s -X DELETE -H "Authorization: Bearer ${TOKEN}" \ + "https://${CR}/v2/${ORG}/${REPO}/manifests/${DIGEST}" echo " Deleted: ${TAG}" fi done