Files
TK-Wiki-Newsletter/.gitea/workflows/docker-build.yml
smueller e4150d0bc3 Enhance Docker build workflow with additional API tests for registry authentication
- Introduce new diagnostic steps to validate registry login credentials, including checks for Basic-Auth and token requests.
- Implement curl commands to retrieve and display authentication details, improving debugging capabilities during the Docker build process.
2026-07-07 14:40:20 +02:00

88 lines
3.3 KiB
YAML

name: Docker Image bauen & veröffentlichen
on:
# Kein Build auf Branch-Pushes (dev/main).
# Build nur, wenn ein Versions-Tag (v*) gesetzt wird
# -> also beim Release-Merge dev -> main inkl. Tag.
push:
tags:
- "v*"
workflow_dispatch:
env:
# Host der Gitea Container Registry (bei Bedarf als Repo-Variable REGISTRY überschreiben)
REGISTRY: ${{ vars.REGISTRY || 'git.hexahost.dev' }}
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Repository auschecken
uses: actions/checkout@v4
- name: Docker Buildx einrichten
uses: docker/setup-buildx-action@v3
- name: Registry-Anmeldung prüfen (Diagnose)
env:
REG_USER: ${{ secrets.REGISTRY_USER || github.repository_owner }}
REG_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
run: |
IMAGE_LOWER=$(echo "${IMAGE_NAME}" | tr '[:upper:]' '[:lower:]')
echo "Registry: ${REGISTRY}"
echo "Username: '${REG_USER}' (Laenge: ${#REG_USER})"
echo "Token gesetzt: $([ -n "${REG_TOKEN}" ] && echo ja || echo NEIN) (Laenge: ${#REG_TOKEN})"
echo "Image (lower): ${IMAGE_LOWER}"
echo "--- API-Test: /api/v1/user (Basic-Auth gueltig?) ---"
curl -s -o /dev/null -w "HTTP %{http_code}\n" -u "${REG_USER}:${REG_TOKEN}" "https://${REGISTRY}/api/v1/user"
echo "--- /v2/ Challenge (WWW-Authenticate) ---"
HDR=$(curl -s -D - -o /dev/null "https://${REGISTRY}/v2/")
AUTH=$(printf '%s' "$HDR" | tr -d '\r' | grep -i '^www-authenticate:' || true)
echo "${AUTH:-(keine WWW-Authenticate Zeile)}"
REALM=$(printf '%s' "$AUTH" | sed -n 's/.*realm="\([^"]*\)".*/\1/p')
SERVICE=$(printf '%s' "$AUTH" | sed -n 's/.*service="\([^"]*\)".*/\1/p')
echo "realm='${REALM}' service='${SERVICE}'"
if [ -n "${REALM}" ]; then
echo "--- Token-Request am echten realm ---"
CODE=$(curl -s -o /tmp/tok.json -w "%{http_code}" -u "${REG_USER}:${REG_TOKEN}" \
"${REALM}?service=${SERVICE}&scope=repository:${IMAGE_LOWER}:pull,push")
echo "HTTP ${CODE}"
echo "Antwort (gekuerzt): $(head -c 300 /tmp/tok.json)"
fi
- name: An Gitea Container Registry anmelden
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USER || github.repository_owner }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Metadaten (Tags & Labels) bestimmen
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,format=short
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') }}
- name: Image bauen & pushen
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}