name: Runner image # Builds and checks the Runner image: the `runner-artifacts` target of the # Dockerfile, a plain file tree that other image builds copy the Runner from, # and its `runner-artifacts-slim` variant without the pack's transport # archives. doc/runner-image-contract.md is the contract. # # This workflow builds and checks only. It has no access to a registry and # publishes nothing. on: pull_request: # Every input of scripts/runner-image-identity.mjs, .dockerignore (it # decides which of those files the build receives), and the pipeline's # own files. A test checks that every identity input is covered. paths: - .github/workflows/runner-image.yml - Dockerfile - .dockerignore - .npmrc - package.json - pnpm-lock.yaml - pnpm-workspace.yaml - tsconfig.base.json - patches/** - packages/paperclip-runner/** - packages/paperclip-eval-kernel/** - packages/shared/src/provider-failure.generated.ts - scripts/create-provider-pack-archive.mjs - scripts/link-plugin-dev-sdk.mjs - scripts/runner-image-identity.mjs - scripts/runner-image-layout.mjs - scripts/runner-image-oci.mjs - docker/runner-image/** workflow_dispatch: # Least privilege: nothing at the workflow level, and read-only contents in # each job. permissions: {} # A newer push to a pull request replaces its older run. concurrency: group: runner-image-${{ github.event.pull_request.number || github.sha }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: identity: name: Resolve the Runner image identity runs-on: ubuntu-latest timeout-minutes: 15 permissions: contents: read outputs: digest: ${{ steps.identity.outputs.digest }} steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Setup pnpm uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6 with: version: 9.15.4 run_install: false # No dependency cache: a restored cache must not reach the image. - name: Setup Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7 with: node-version: 24 package-manager-cache: false # A contributor cannot edit pnpm-lock.yaml, so a pull request that # changes the Runner's dependencies is built against a lockfile resolved # here. The image build installs from it frozen. - name: Resolve the lockfile run: | set -euo pipefail pnpm install --resolution-only --ignore-scripts --no-frozen-lockfile changed="$(git status --porcelain)" if [ -n "$changed" ] && printf '%s\n' "$changed" | grep -Fvq ' pnpm-lock.yaml'; then echo "Unexpected files changed during lockfile resolution:" echo "$changed" exit 1 fi echo "This run built from a \`pnpm-lock.yaml\` resolved for it${changed:+ (it differs from the committed file)}." >> "$GITHUB_STEP_SUMMARY" - name: Set up Docker Buildx uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4 with: buildkitd-config-inline: | [registry."docker.io"] mirrors = ["mirror.gcr.io"] # Computed inside the build, from the files the build context supplies # after .dockerignore. A digest computed from the checkout would cover # files the image build never receives. - name: Compute the identity in the build context id: identity timeout-minutes: 10 run: | set -euo pipefail out="$RUNNER_TEMP/runner-image-identity" docker buildx build --target runner-artifacts-identity --output "type=local,dest=$out" . digest="$(jq -er .digest "$out/runner-image-identity.json")" [[ "$digest" =~ ^[0-9a-f]{64}$ ]] echo "digest=$digest" >> "$GITHUB_OUTPUT" { echo "Runner image inputs digest: \`$digest\`" echo echo '```json' cat "$out/runner-image-identity.json" echo '```' } >> "$GITHUB_STEP_SUMMARY" # The legs must build from the file the identity was computed from, not # from a second resolution. - name: Keep the resolved lockfile for the build legs uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 with: name: runner-image-lockfile path: pnpm-lock.yaml if-no-files-found: error retention-days: 1 # Multi-arch by native runner, not QEMU, as in docker.yml. GitHub-hosted # runners: the protected release fleets admit only docker.yml on master. # # These legs hold no credential and use no registry build cache. The install # runs dependency lifecycle scripts. build: name: Build and check (${{ matrix.arch }}) needs: identity strategy: fail-fast: false matrix: include: - platform: linux/amd64 runner: ubuntu-latest arch: amd64 - platform: linux/arm64 runner: ubuntu-24.04-arm arch: arm64 runs-on: ${{ matrix.runner }} timeout-minutes: 60 permissions: contents: read env: DIGEST: ${{ needs.identity.outputs.digest }} ARCH: ${{ matrix.arch }} PLATFORM: ${{ matrix.platform }} steps: - name: Checkout uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 with: persist-credentials: false - name: Setup Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7 with: node-version: 24 package-manager-cache: false - name: Download the resolved lockfile uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 with: name: runner-image-lockfile path: ${{ runner.temp }}/runner-image-lockfile - name: Use the resolved lockfile run: cp "$RUNNER_TEMP/runner-image-lockfile/pnpm-lock.yaml" pnpm-lock.yaml - name: Free runner disk run: | set -euo pipefail sudo apt-get clean || true sudo rm -rf /usr/share/dotnet /usr/share/swift /usr/local/lib/android /usr/local/share/boost \ /usr/local/share/powershell /opt/ghc /opt/hostedtoolcache/CodeQL /opt/hostedtoolcache/PyPy /opt/hostedtoolcache/Ruby || true docker system prune -af || true df -h - name: Set up Docker Buildx uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4 with: buildkitd-config-inline: | [registry."docker.io"] mirrors = ["mirror.gcr.io"] # The build itself runs the frozen install, the Runner's own build, the # provider pack integrity check and the layout check. # # Both variants come from one build: the second command only reads the # cache of the first. Each is exported once, as an OCI archive and # nothing else. A command with two exports, an archive and a tree, # stalled on these runners when every stage came from the cache, so a # command has one export, and the step has a time limit: a cold build # takes about ten minutes. # # This is the publication form of the build, the only one whose pack # names the image (`runnerInputsDigest`), so the check below can bind # the tree to the digest the identity job resolved. Nothing here # publishes it: the archives and trees stay on this runner. - name: Build both variants of the Runner image timeout-minutes: 30 run: | set -euo pipefail for variant in full slim; do target=runner-artifacts if [ "$variant" = slim ]; then target=runner-artifacts-slim; fi docker buildx build \ --target "$target" \ --platform "$PLATFORM" \ --build-arg "PAPERCLIP_RUNNER_SOURCE_REVISION=$GITHUB_SHA" \ --build-arg PAPERCLIP_RUNNER_IMAGE_PUBLICATION=1 \ --provenance=false --sbom=false \ --output "type=oci,dest=$RUNNER_TEMP/runner-image/$variant.oci.tar" \ . done # The trees the checks below read are the layers of those archives, # written out in order. They are the bytes of the images themselves, # not a second export of the build, and each blob is checked against # its digest as it is read. - name: Unpack both images timeout-minutes: 10 run: | set -euo pipefail for variant in full slim; do node scripts/runner-image-oci.mjs unpack "$RUNNER_TEMP/runner-image/$variant.oci.tar" \ --out "$RUNNER_TEMP/runner-image/$variant" done # Against each unpacked tree, bound to this run: the digest the identity # job resolved, this commit and this leg's architecture. Checks every # documented path, the build stamp, and every pack artifact and tree # digest in provider-pack.json. A slim tree must not hold the transport # archives. A full tree must: the check verifies each one, extracts # them as a sandbox does and compares the result with the pack; that # needs about as much free disk as the pack is large. - name: Check the layout contract and pack integrity timeout-minutes: 10 run: | set -euo pipefail for variant in full slim; do node scripts/runner-image-layout.mjs check "$RUNNER_TEMP/runner-image/$variant" \ --variant "$variant" \ --expect-inputs-digest "$DIGEST" \ --expect-source-revision "$GITHUB_SHA" \ --expect-architecture "$ARCH" done # The full image must be the slim image's layers, as the same blobs, # then the transport layers, with nothing else in them. No file may be # in two layers. - name: Check the layers of both variants timeout-minutes: 10 run: | set -euo pipefail { echo '```' node scripts/runner-image-oci.mjs check-layers \ --slim "$RUNNER_TEMP/runner-image/slim.oci.tar" \ --full "$RUNNER_TEMP/runner-image/full.oci.tar" echo '```' } | tee -a "$GITHUB_STEP_SUMMARY" # On the slim tree: the daemon is in a layer both variants share, so # one run covers both, and the slim tree is the smaller one to load. # This command has one export, a few small files. - name: Run the daemon on every consumer base image timeout-minutes: 20 run: | docker buildx build \ --file docker/runner-image/Dockerfile.smoke \ --platform "$PLATFORM" \ --build-context "runner-artifacts=$RUNNER_TEMP/runner-image/slim" \ --output "type=local,dest=$RUNNER_TEMP/runner-image/smoke" \ docker/runner-image ls -l "$RUNNER_TEMP/runner-image/smoke"