Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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. |
Expand Down
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" && "$(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
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."
Expand Down Expand Up @@ -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 != '' }}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading