add anonym token authentication
All checks were successful
Docker Build Smart Logic / Build amd64 & arm64 (push) Successful in 17s

This commit is contained in:
2026-02-06 23:14:57 +01:00
parent 6b87cc8704
commit 6ad3188b85

View File

@@ -27,19 +27,37 @@ while true; do
echo "Prüfe $TYPE: $REPO:$EXTRA..." echo "Prüfe $TYPE: $REPO:$EXTRA..."
if [ "$TYPE" == "DOCKER" ]; then if [ "$TYPE" == "DOCKER" ]; then
# Prüfen ob es Docker Hub (kein Punkt oder docker.io) oder eine eigene Registry ist
if [[ "$REPO" != *"."* ]] || [[ "$REPO" == *"docker.io"* ]]; then if [[ "$REPO" != *"."* ]] || [[ "$REPO" == *"docker.io"* ]]; then
# Docker Hub # --- Docker Hub Logik ---
CLEAN_REPO=${REPO#docker.io/} # Entferne docker.io/ falls vorhanden CLEAN_REPO=${REPO#docker.io/}
[[ "$CLEAN_REPO" != *"/"* ]] && CLEAN_REPO="library/$CLEAN_REPO" [[ "$CLEAN_REPO" != *"/"* ]] && CLEAN_REPO="library/$CLEAN_REPO"
NEW_VAL=$(curl -s "https://hub.docker.com/v2/repositories/${CLEAN_REPO}/tags/${EXTRA}" | jq -r '.last_updated // empty') NEW_VAL=$(curl -s "https://hub.docker.com/v2/repositories/${CLEAN_REPO}/tags/${EXTRA}" | jq -r '.last_updated // empty')
else else
# Eigene Registry (V2 API) # --- Custom Registry (z.B. Gitea) ---
REG_HOST=$(echo $REPO | cut -d/ -f1) REG_HOST=$(echo $REPO | cut -d/ -f1)
IMG_NAME=$(echo $REPO | cut -d/ -f2-) IMG_NAME=$(echo $REPO | cut -d/ -f2-)
# Wir holen den Docker-Content-Digest Header (funktioniert meist ohne komplexen Token-Voodoo)
NEW_VAL=$(curl -sI -H "Accept: application/vnd.docker.distribution.manifest.v2+json" \ # 1. Versuche einen anonymen Token zu holen (Standard V2 Auth)
"https://${REG_HOST}/v2/${IMG_NAME}/manifests/${EXTRA}" | grep -i "Docker-Content-Digest" | awk '{print $2}' | tr -d '\r') TOKEN=$(curl -s "https://${REG_HOST}/v2/token?service=${REG_HOST}&scope=repository:${IMG_NAME}:pull" | jq -r '.token // empty')
# 2. Abfrage mit Token (falls vorhanden) und explizitem GET statt HEAD
if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ]; then
AUTH_HEADER="Authorization: Bearer $TOKEN"
else
AUTH_HEADER="X-No-Auth: true" # Dummy Header
fi
# Wir nutzen curl -i (Header + Body) und fangen den Digest ab
RESPONSE=$(curl -s -i -H "$AUTH_HEADER" \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
"https://${REG_HOST}/v2/${IMG_NAME}/manifests/${EXTRA}")
NEW_VAL=$(echo "$RESPONSE" | grep -i "docker-content-digest" | awk '{print $2}' | tr -d '\r')
# Falls Digest leer, versuche ETag (Backup für manche Registries)
if [ -z "$NEW_VAL" ]; then
NEW_VAL=$(echo "$RESPONSE" | grep -i "etag" | awk '{print $2}' | tr -d '\r' | tr -d '"')
fi
fi fi
elif [ "$TYPE" == "GITHUB" ]; then elif [ "$TYPE" == "GITHUB" ]; then
NEW_VAL=$(curl -s "https://api.github.com/repos/${REPO}/branches/${EXTRA}" | jq -r '.commit.sha // empty') NEW_VAL=$(curl -s "https://api.github.com/repos/${REPO}/branches/${EXTRA}" | jq -r '.commit.sha // empty')