From d7236fc4fbb0076ce938a6a49668905131c9f55d Mon Sep 17 00:00:00 2001 From: Krishan Patel Date: Mon, 2 Nov 2026 23:04:13 +0000 Subject: [PATCH 1/2] Add a platforms input for multi-platform builds --- .github/workflows/pull-request.yml | 27 +++++++++++++++++++++++++++ README.md | 3 +++ action.yml | 10 ++++++++++ package.json | 2 +- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 58d36f2..55848ff 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -28,6 +28,10 @@ jobs: - uses: actions/checkout@v7 - name: Start a registry run: docker run --detach --name registry --publish 5000:5000 registry:3 + - name: Register QEMU + uses: docker/setup-qemu-action@v4 + with: + platforms: arm64 - name: Start a shared BuildKit if: matrix.buildkit-endpoint != '' run: | @@ -69,6 +73,29 @@ jobs: run: | docker pull --quiet "$IMAGE" test "$(docker run --rm "$IMAGE" cat /message)" = "$(printf 'from-args\nfinal')" + - name: Push a multi-platform image + uses: ./ + with: + image: test + context: ./tests/ + platforms: linux/amd64,linux/arm64 + push: localhost:5000/multi:latest + - name: Check the multi-platform image + run: | + platforms="$(docker buildx imagetools inspect localhost:5000/multi:latest --format '{{json .Manifest}}' | jq -r '[.manifests[].platform | select(.architecture != "unknown") | "\(.os)/\(.architecture)"] | sort | join(",")')" + test "$platforms" = 'linux/amd64,linux/arm64' + test "$(docker run --rm --platform linux/arm64 localhost:5000/multi:latest uname -m)" = aarch64 + - name: Reject tag with more than one platform + id: reject + continue-on-error: true + uses: ./ + with: + image: test + context: ./tests/ + platforms: linux/amd64,linux/arm64 + tag: test-multi + - name: Check tag with more than one platform was rejected + run: test "${{ steps.reject.outcome }}" = failure - name: Skip when the checks already passed uses: ./ env: diff --git a/README.md b/README.md index 0830d43..2e411fa 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ With `push`, the BuildKit pushes straight to the target registry with the runner A self-hosted runner without `BUILDKIT_ENDPOINT` still works, with the GitHub Actions cache, and the action adds a notice to the run saying so. +To build with `platforms` for a platform other than the BuildKit machine's own, register QEMU on that machine once, e.g. `docker run --privileged --rm tonistiigi/binfmt --install arm64`, then restart BuildKit so it picks the new platform up. + ### Choosing `image` `image` is the cache scope, so builds that share it share their cache. A GitHub Actions cache scope only keeps what the last build wrote to it: @@ -103,6 +105,7 @@ GitHub keeps up to 10 GB of cache per repository and evicts the least recently u | `build-args` | `''` | Build args, one per line. | | `tag` | `''` | Make the built image available to the local docker daemon under this tag. | | `push` | `''` | Tags to push the built image to, one per line. | +| `platforms` | the BuildKit machine's platform | Platforms to build for, comma separated, e.g. `linux/amd64,linux/arm64`. Use `push`, not `tag`, with more than one platform. | | `cache-mode` | `max` | GitHub Actions cache mode without a shared BuildKit: `max` caches every stage, `min` only the final image's layers. | | `driver-opts` | `''` | Options for the `docker-container` builder used without a shared BuildKit, one per line, e.g. `network=host`. | | `summary` | `false` | Add the build summary to the job summary and upload the build record as an artifact. | diff --git a/action.yml b/action.yml index faf2ef6..0e42934 100644 --- a/action.yml +++ b/action.yml @@ -31,6 +31,10 @@ inputs: description: 'Tags to push the built image to, one per line. Log in to the registry first.' required: false default: '' + platforms: + description: 'Platforms to build for, comma separated, e.g. linux/amd64,linux/arm64. Defaults to the platform of the machine running BuildKit. Builds for other platforms need QEMU registered on that machine. Use push, not tag, with more than one platform.' + required: false + default: '' cache-mode: description: 'GitHub Actions cache mode when building without a shared BuildKit: max caches every stage, min only the layers of the final image (smaller, but intermediate stages rebuild)' required: false @@ -58,12 +62,17 @@ runs: IMAGE: ${{ inputs.image }} TAG: ${{ inputs.tag }} PUSH: ${{ inputs.push }} + PLATFORMS: ${{ inputs.platforms }} RUNNER_ENVIRONMENT: ${{ runner.environment }} run: | if [[ -n "$TAG" && -n "$PUSH" ]]; then echo "::error::Set tag or push, not both" exit 1 fi + if [[ -n "$TAG" && "$PLATFORMS" == *,* ]]; then + echo "::error::Use push, not tag, with more than one platform: the local docker daemon can only hold one platform of an image" + exit 1 + fi endpoint="${BUILDKIT_ENDPOINT:-}" if [[ -z "$endpoint" && "$RUNNER_ENVIRONMENT" == 'self-hosted' && -z "${BUILD_IMAGE_BUILDER:-}" ]]; then echo "::notice title=Building without a shared BuildKit::BUILDKIT_ENDPOINT is not set on this self-hosted runner, so images build with the GitHub Actions cache. Set it in the runner's environment to build on a shared BuildKit." @@ -111,6 +120,7 @@ runs: file: ${{ inputs.file }} target: ${{ inputs.target }} build-args: ${{ inputs.build-args }} + platforms: ${{ inputs.platforms }} outputs: ${{ steps.resolve.outputs.outputs }} load: ${{ steps.resolve.outputs.endpoint == '' && inputs.tag != '' }} push: ${{ inputs.push != '' }} diff --git a/package.json b/package.json index 6d1b5cf..e0767c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kibalabs/github-action-build-image", - "version": "1.0.1", + "version": "1.1.0", "description": "GitHub Action to build a docker image with a shared BuildKit when the runner has one, or the GitHub Actions cache otherwise", "license": "MIT", "private": true, From 0301a5f72ece6d39b5ccc542beccc14d10db1f14 Mon Sep 17 00:00:00 2001 From: Krishan Patel Date: Tue, 3 Nov 2026 10:00:32 +0000 Subject: [PATCH 2/2] Count platforms separated by commas or newlines in the tag guard --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 0e42934..80f1e0f 100644 --- a/action.yml +++ b/action.yml @@ -69,7 +69,7 @@ runs: echo "::error::Set tag or push, not both" exit 1 fi - if [[ -n "$TAG" && "$PLATFORMS" == *,* ]]; then + if [[ -n "$TAG" && "$(echo "$PLATFORMS" | tr ',' '\n' | grep -c '[^[:space:]]')" -gt 1 ]]; then echo "::error::Use push, not tag, with more than one platform: the local docker daemon can only hold one platform of an image" exit 1 fi