fix: use Harbor token auth for image cleanup on Volcano Engine CR
Some checks failed
Build and Deploy Log Center / build-and-deploy (push) Failing after 5s

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
repair-agent 2026-04-02 17:09:52 +08:00
parent a2c6e54346
commit 749cddf561

View File

@ -135,7 +135,13 @@ jobs:
for REPO in log-center-api log-center-web k8s-pod-monitor; do for REPO in log-center-api log-center-web k8s-pod-monitor; do
echo "Cleaning ${ORG}/${REPO}..." 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 " python3 -c "
import sys,json import sys,json
try: try:
@ -148,11 +154,13 @@ jobs:
" 2>/dev/null) " 2>/dev/null)
for TAG in $TAGS; do for TAG in $TAGS; do
DIGEST=$(curl -s -I -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \ DIGEST=$(curl -s -H "Authorization: Bearer ${TOKEN}" \
-u "${AUTH}" "https://${CR}/v2/${ORG}/${REPO}/manifests/${TAG}" 2>/dev/null | \ -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') grep -i docker-content-digest | awk '{print $2}' | tr -d '\r')
if [ -n "$DIGEST" ]; then 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}" echo " Deleted: ${TAG}"
fi fi
done done