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
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:
parent
a2c6e54346
commit
749cddf561
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user