diff --git a/.github/workflows/docker-arm64v8.yml b/.github/workflows/docker-arm64v8.yml index 8488b9b1..192ddff1 100644 --- a/.github/workflows/docker-arm64v8.yml +++ b/.github/workflows/docker-arm64v8.yml @@ -39,8 +39,14 @@ jobs: permissions: contents: read packages: write - steps: + - name: Configure non-interactive Docker credentials + run: | + docker_config="$RUNNER_TEMP/docker-config" + mkdir -p "$docker_config" + printf '{}\n' > "$docker_config/config.json" + echo "DOCKER_CONFIG=$docker_config" >> "$GITHUB_ENV" + - name: Checkout repository uses: actions/checkout@v4 @@ -53,12 +59,27 @@ jobs: # ARM64 build and works with Docker Desktop's containerd image store. driver: docker - - name: Log in to Docker Hub + - name: Configure Docker Hub authentication if: github.event_name != 'pull_request' - uses: docker/login-action@v4 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + run: | + # Avoid Docker Desktop's interactive macOS Keychain helper. BuildKit + # reads this short-lived Docker config directly during the push. + python3 - <<'PY' + import base64 + import json + import os + from pathlib import Path + + raw = f"{os.environ['DOCKERHUB_USERNAME']}:{os.environ['DOCKERHUB_TOKEN']}" + auth = base64.b64encode(raw.encode()).decode() + config = {"auths": {"https://index.docker.io/v1/": {"auth": auth}}} + path = Path(os.environ["DOCKER_CONFIG"]) / "config.json" + path.write_text(json.dumps(config), encoding="utf-8") + path.chmod(0o600) + PY - name: Docker metadata id: meta @@ -80,3 +101,7 @@ jobs: platforms: linux/arm64/v8 build-args: | ROS_DISTRO=${{ env.ROS_DISTRO }} + + - name: Clear Docker Hub credentials + if: always() && github.event_name != 'pull_request' + run: printf '{}\n' > "$DOCKER_CONFIG/config.json"