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
87 changes: 67 additions & 20 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@ env:
IMAGE: ghcr.io/zeroae/ci-runner

jobs:
# Each architecture builds and smoke-tests on its own native runner (no
# QEMU). Only main publishes: a push to main, the schedule (which runs on
# main), or a dispatch run on main. Other branches build and smoke.
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
uname: x86_64
runner: ubuntu-latest
- arch: arm64
uname: aarch64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v4

Expand All @@ -28,43 +41,77 @@ jobs:
uses: docker/build-push-action@v6
with:
context: image
platforms: linux/amd64
platforms: linux/${{ matrix.arch }}
pull: true
load: true
tags: ci-runner:smoke

- name: Smoke
run: >-
docker run --rm
-e EXPECT_ARCH=${{ matrix.uname }}
-v "$PWD/image/smoke.sh:/smoke.sh:ro"
--entrypoint bash
ci-runner:smoke /smoke.sh

- name: Decide whether to publish
id: publish
- name: Log in to GHCR
if: github.ref == 'refs/heads/main'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# The same build again, from the builder's cache, pushed untagged by
# digest. The merge job tags the manifest list of both digests.
- name: Push by digest
if: github.ref == 'refs/heads/main'
id: push
uses: docker/build-push-action@v6
with:
context: image
platforms: linux/${{ matrix.arch }}
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true

- name: Save the digest
if: github.ref == 'refs/heads/main'
run: |
# Only main publishes: a push to main, the schedule (which runs on
# main), or a dispatch run on main. Other branches build and smoke.
publish=false
if [ "${{ github.ref }}" = refs/heads/main ]; then publish=true; fi
echo "publish=$publish" >> "$GITHUB_OUTPUT"
echo "date=$(date -u +%Y%m%d)" >> "$GITHUB_OUTPUT"
echo "sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
mkdir -p digests
echo "${{ steps.push.outputs.digest }}" > "digests/${{ matrix.arch }}"

- name: Upload the digest
if: github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: digest-${{ matrix.arch }}
path: digests/${{ matrix.arch }}
retention-days: 1

publish:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
pattern: digest-*
path: digests
merge-multiple: true

- uses: docker/setup-buildx-action@v3

- name: Log in to GHCR
if: steps.publish.outputs.publish == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Publish
if: steps.publish.outputs.publish == 'true'
- name: Publish the manifest list
run: |
tag="${{ steps.publish.outputs.date }}-${{ steps.publish.outputs.sha }}"
for t in latest "$tag"; do
docker tag ci-runner:smoke "$IMAGE:$t"
docker push "$IMAGE:$t"
done
echo "Published $IMAGE:latest and $IMAGE:$tag" >> "$GITHUB_STEP_SUMMARY"
tag="$(date -u +%Y%m%d)-${GITHUB_SHA::7}"
refs=()
for arch in amd64 arm64; do refs+=("$IMAGE@$(cat "digests/$arch")"); done
docker buildx imagetools create -t "$IMAGE:latest" -t "$IMAGE:$tag" "${refs[@]}"
docker buildx imagetools inspect "$IMAGE:$tag"
echo "Published $IMAGE:latest and $IMAGE:$tag (linux/amd64, linux/arm64)" >> "$GITHUB_STEP_SUMMARY"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ the host's Docker daemon, so a `docker run -v` source is a path on the host.
a bind mount from any of them works as it does on a GitHub-hosted runner,
`mktemp` files and `~/` config included. Both are on the 50 GB root disk. A mount from anywhere else (`/opt`,
`/etc`, `/var`) gets an empty host path. Nothing is pinned: every boot pulls
`:latest`, and the image is rebuilt weekly.
`:latest`, and the image is rebuilt weekly, for linux/amd64 and linux/arm64,
each built and smoke-tested on its own native runner.

**Deploy jobs** keep their AWS access as before (typically GitHub OIDC into the
repo's own role). A trust policy that pins `runner_environment: github-hosted`
Expand Down
23 changes: 22 additions & 1 deletion image/smoke.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash
# Smoke test for the ci-runner image. Run it inside the image:
# docker run --rm -v "$PWD/image/smoke.sh:/smoke.sh:ro" --entrypoint bash IMAGE /smoke.sh
# docker run --rm -e EXPECT_ARCH=aarch64 -v "$PWD/image/smoke.sh:/smoke.sh:ro" --entrypoint bash IMAGE /smoke.sh
# Prints every added tool's version and fails if any check fails.
# EXPECT_ARCH (x86_64 or aarch64, as `uname -m` prints it) is the architecture
# the image was built for; without it the machine's own is expected.
set -uo pipefail

fail=0
Expand Down Expand Up @@ -45,6 +47,25 @@ check npm npm --version
check aws aws --version
expect python3.12 3.12 "$(python3 -c 'import sys; print("%d.%d" % sys.version_info[:2])' 2>&1)"

echo "== architecture"
# Each binary the image adds must be built for the image's architecture, so a
# wrong download (the arm64 AWS CLI or compose plugin) fails here, not in a job.
arch=${EXPECT_ARCH:-$(uname -m)}
elf_arch() {
# e_machine, bytes 18-19 of the ELF header: 62 is x86_64, 183 is aarch64.
case $(od -An -tu2 -j18 -N2 "$1" 2>/dev/null | tr -d ' ') in
62) echo x86_64 ;; 183) echo aarch64 ;; *) echo "not ELF: $1" ;;
esac
}
expect uname "$arch" "$(uname -m)"
expect docker-bin "$arch" "$(elf_arch "$(command -v docker)")"
expect buildx-bin "$arch" "$(elf_arch /usr/local/lib/docker/cli-plugins/docker-buildx)"
expect compose-bin "$arch" "$(elf_arch /usr/local/lib/docker/cli-plugins/docker-compose)"
expect gh-bin "$arch" "$(elf_arch "$(command -v gh)")"
expect node-bin "$arch" "$(elf_arch "$(command -v node)")"
expect aws-bin "$arch" "$(elf_arch "$(readlink -f "$(command -v aws)")")"
expect aws-exe "exe/$arch" "$(aws --version 2>&1 | grep -o 'exe/[a-z0-9_]*')"

echo "== runner user"
id runner
expect whoami runner "$(whoami)"
Expand Down
Loading