From 27c816578abf85edd2b12e5194dbff09a3e1470d Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Thu, 28 May 2026 11:40:26 -0700 Subject: [PATCH] fix: build docker images on native arch runners --- .github/workflows/docker.yml | 213 ++++++++++++++++++++++++++++------- 1 file changed, 171 insertions(+), 42 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index a47f81ae..13378e58 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,7 +11,8 @@ on: # pull_request: env: - DOCKER_IMAGE: archivebox-ci + DOCKERHUB_IMAGE: archivebox/archivebox + GHCR_IMAGE: ghcr.io/archivebox/archivebox permissions: contents: read @@ -22,8 +23,21 @@ concurrency: cancel-in-progress: true jobs: - buildx: - runs-on: ubuntu-latest + build: + name: build ${{ matrix.platform }} + runs-on: ${{ matrix.runner }} + strategy: + fail-fast: false + matrix: + include: + - platform: linux/amd64 + runner: ubuntu-24.04 + cache_scope: docker-amd64 + artifact_name: digest-linux-amd64 + - platform: linux/arm64 + runner: ubuntu-24.04-arm + cache_scope: docker-arm64 + artifact_name: digest-linux-arm64 steps: - name: Checkout uses: actions/checkout@v4 @@ -31,16 +45,12 @@ jobs: # submodules: true # fetch-depth: 1 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v3 with: version: latest install: true - platforms: linux/amd64,linux/arm64 - name: Builder instance name run: echo ${{ steps.buildx.outputs.name }} @@ -62,6 +72,105 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Collect Docker labels + id: docker_meta + shell: bash + run: | + set -Eeuo pipefail + VERSION="$(python3 - <<'PY' + from pathlib import Path + import re + + match = re.search(r'^version = "([^"]+)"$', Path("pyproject.toml").read_text(), re.MULTILINE) + if not match: + raise SystemExit("Failed to read version from pyproject.toml") + print(match.group(1)) + PY + )" + + { + echo 'labels<> "$GITHUB_OUTPUT" + + echo "[+] Building ${{ matrix.platform }} for ${VERSION}" + + - name: Build and push digest + id: docker_build + uses: docker/build-push-action@v6 + with: + context: ./ + file: ./Dockerfile + builder: ${{ steps.buildx.outputs.name }} + push: ${{ github.event_name != 'pull_request' }} + tags: | + ${{ env.DOCKERHUB_IMAGE }} + ${{ env.GHCR_IMAGE }} + labels: ${{ steps.docker_meta.outputs.labels }} + cache-from: type=gha,scope=${{ matrix.cache_scope }} + cache-to: type=gha,mode=max,scope=${{ matrix.cache_scope }} + platforms: ${{ matrix.platform }} + outputs: type=image,push-by-digest=true,name-canonical=true,push=true + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + + - name: Export digest + shell: bash + run: | + set -Eeuo pipefail + mkdir -p /tmp/digests + digest="${{ steps.docker_build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.artifact_name }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + publish: + name: publish multiarch tags + runs-on: ubuntu-24.04 + needs: + - build + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + version: latest + install: true + + - name: Login to Docker Hub + uses: docker/login-action@v3 + if: github.event_name != 'pull_request' + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digest-* + merge-multiple: true + - name: Collect Docker tags id: docker_meta shell: bash @@ -80,49 +189,69 @@ jobs: SHORT_SHA="${GITHUB_SHA::8}" { - echo 'tags<> "$GITHUB_OUTPUT" - echo "[+] Publishing Docker tags:" - cat <