mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-16 20:12:20 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The Runner is the part that executes agent work: a daemon (`paperclip-runnerd`) and a provider pack of agent tools > - `.github/workflows/runner-image.yml` builds the Runner alone and publishes it from `master` as `ghcr.io/paperclipai/paperclip-runner`, one time for each set of inputs > - The build used no cache, so every run compiled the daemon again. The first publication took 25m46s from push to tag > - The toolchain and the daemon change only with the Rust sources. Most commits that change the Runner's inputs do not touch them > - This pull request lets the build legs read a registry build cache for those stages. Only a new job can write the cache, and only for a `master` push > - A weekly run builds with no cache, so the cache cannot hide a broken build for long > - The benefit is about 3 minutes less on each build leg when the Rust sources did not change, with no change to the published image ## Linked Issues or Issue Description Refs #21230 (publication of the Runner image), #21229 and #21204 (the build this change makes faster). No issue exists for this change. **What existing behavior does this improve?** The Runner image build in `.github/workflows/runner-image.yml`. It builds the same image in less time. **Current behavior** Each build leg starts from an empty builder. It installs the Rust toolchain and compiles the daemon in every run. In the first `master` publication (run 43365670428) the amd64 leg spent 7m22s in the build step. The toolchain and the cargo build took 3m26s of that. **Proposed behavior** The build legs read `ghcr.io/paperclipai/paperclip-runner-buildcache:<arch>` for the stages up to the compiled daemon. A new `cache` job writes that cache after a publication. A scheduled run builds with no cache one time each week. **Reason and benefit** The stages before the last one read the Rust sources, the protocol files and the toolchain pin. In the last 30 days, 438 `master` commits changed an input of the image, and at most 181 of them changed a file those stages read. For the other commits, and for each pull request that does not touch those files, the build step is about 3 minutes shorter on each leg. **Breaking changes** None. The `Dockerfile` and each file in the image identity are unchanged. The published digest for a set of inputs does not change. This is part 4 of 4 of a stack ([stack #21309](https://github.com/paperclipai/paperclip/stack/21309)). Merge the parts in order: 1. #21306: the resolver and the no-rebuild mode 2. #21307: the report-only job in `docker.yml` and the pull-request check of the application image's Runner path 3. #21308: reading a retained provider pack from its Runner image 4. #21310: a registry build cache for the Runner image build (this pull request) This pull request uses no code from parts 1 to 3. It is stacked on them because all four parts edit `doc/runner-image-contract.md`. ## What Changed - The build legs pass `--cache-from type=registry,ref=ghcr.io/paperclipai/paperclip-runner-buildcache:<arch>` to the first build command. They do not log in. Their permissions stay `contents: read` and `packages: read`. - A new `cache` job writes the cache with `--cache-to type=registry,...,mode=max` and `--output type=cacheonly`. It runs only for a `master` push in the canonical repository, for inputs that had no image. Its permissions are `contents: read` and `packages: write`. It has no `id-token` and no `attestations` permission. - The `cache` job needs the `publish` job, and no job needs the `cache` job. A cache write cannot delay or fail a publication. - The `cache` job builds the target `runner-artifacts-runnerd` and no later stage. The last stage takes the commit as a build argument, so no other commit can reuse it. The install and its dependency lifecycle scripts are in that stage, so the job with the write token does not run them. - The `cache` job has one concurrency group for each architecture, a job time limit and a step time limit. - A `schedule` trigger starts a weekly build. It passes `--no-cache` to the first command and reads no cache. It runs all checks and publishes nothing. A fork's schedule runs nothing. - `server/src/__tests__/runner-image-workflow.test.ts` pins the new security properties: which jobs hold `packages: write`, that the build legs have no credential and cannot write the cache, the conditions of the `cache` job, that the `publish` job does not depend on it, and that a scheduled run cannot publish or write the cache. - `doc/runner-image-contract.md` has a "Build cache" section. ## Verification Tests, on macOS (Node 26.12.0) and in a `node:24.22.3-bookworm` container (Linux arm64, Node 24.22.3): - `pnpm exec vitest run src/__tests__/runner-image-workflow.test.ts src/__tests__/runner-image-identity.test.ts` in `server/`: 55 of 55 tests pass on both. - `node --test .github/scripts/tests/*.test.mjs`: 807 of 807 tests pass on both. The container needs `jq`. - `pnpm verify` exits 2 for this change, because a workflow file is a global CI input. Required CI supplies the broad coverage. - Each new assertion fails when the workflow breaks its rule. I checked seven such edits, for example: the `publish` job needs the `cache` job, the `cache` job gets `id-token: write`, a build leg gets `--cache-to`. Cache mechanics, on linux/arm64 with a local registry, BuildKit v0.34.2 (the version the hosted runners use), and an empty builder for each build: | Build of both variants | Time | Result | | --- | --- | --- | | No cache, cache ref does not exist | 260 s | An importer error in the log, exit 0 | | One changed TypeScript file, with the cache | 149 s | Toolchain and cargo steps cached | | Unchanged inputs and a new commit, with the cache | 129 s | Toolchain and cargo steps cached | | Each stage in the cache (a whole-build cache, which this change does not write) | 16 s | Both OCI archives complete | | `--no-cache` on the first command | 272 s | No cached step in the first command. The second command reuses all of it | - The images built from the cache pass `runner-image-layout.mjs check` and `runner-image-oci.mjs check-layers`. The daemon has the same SHA-256 as the daemon of a cold build. - A cache ref that does not exist, a host that refuses the connection, a name that does not resolve, and the real `ghcr.io/paperclipai/paperclip-runner-buildcache:arm64` (which does not exist yet) each give an importer error in the log and a complete build with exit 0. - The `cache` job command on an empty builder with the cache present takes 6 s. It downloads no layer. Not tested before merge: - The `cache` job. It runs only on `master`. - The scheduled run. It starts only from the default branch. - The cache package. It does not exist. I did not test a private package, which answers an anonymous read with an authorization error. I expect the same importer error and a cold build. - A fully cached build on the hosted runners. The local test used the same BuildKit version and a different buildx version (0.37.0, and the runners have 0.38.1). ## Risks - **A second job can write packages.** Before this change, only the `publish` job held `packages: write`, and it runs no build. Now the `cache` job holds it too, and it runs BuildKit on the repository's `Dockerfile`. GitHub cannot limit that token to one package, so it can also write to `ghcr.io/paperclipai/paperclip-runner`. The limits are: the job runs only for a `master` push in the canonical repository, the token goes only to the registry login, the build steps run inside BuildKit without it, the job does not run the install, and the job cannot sign. An image that it wrote has no attestation. - **Part of a published image can come from an earlier run.** The daemon in a published image can come from a step that an earlier `master` run compiled and cached. The attestation names the run that published, not the run that compiled. BuildKit reuses a step only for the same instruction and the same file content, but a party that can write the cache package can replace what a later build reuses. Write access to the cache package must stay as narrow as write access to the image package. - **A cached download is not repeated.** The toolchain installer, the toolchain and the crates are not downloaded again until the inputs of their step change. The weekly cold build finds a download that is gone. It does not compare its output with the cache. - **A registry failure after the cache import fails the leg.** A cache that cannot be read at the start is not a failure. A layer download that fails later is a failure. Run the job again. - **The cache package starts private.** GitHub creates it on the first write. A maintainer must make it public one time. Until then each build runs cold and nothing fails. - **The first cache write waits for an input change.** The merge of this pull request changes no input of the image, so its `master` run builds nothing and writes no cache. - **A cancelled cache job marks its run as cancelled.** When three cache writes for one architecture wait at the same time, GitHub cancels the middle one. The image of that run is published. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used Claude Fable 5.2 (`claude-fable-5-2`), Anthropic, through Claude Code. Tool use and shell execution. It wrote the change, ran the local builds and tests, and wrote this description. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
731 lines
33 KiB
YAML
731 lines
33 KiB
YAML
name: Runner image
|
|
|
|
# Builds the Runner once for each distinct set of its inputs and publishes it
|
|
# as ghcr.io/paperclipai/paperclip-runner, a multi-platform image that other
|
|
# image builds copy from, in two variants: `inputs-<digest>` (full) and
|
|
# `inputs-<digest>-slim` (without the pack's transport archives).
|
|
# doc/runner-image-contract.md is the contract.
|
|
#
|
|
# Every master push computes the digest from the commit's own build context,
|
|
# with the committed pnpm-lock.yaml. The build runs only when no image has
|
|
# that digest yet. When the committed lockfile is behind the manifests the
|
|
# Runner build reads, the run says so, publishes nothing and stays green: the
|
|
# repository's lockfile refresh brings the commit that publishes.
|
|
#
|
|
# Pull requests that touch the Runner's inputs, its recipe or this pipeline,
|
|
# and manual runs, always build and check the image and never publish it.
|
|
# They resolve the lockfile first, because a contributor cannot edit it.
|
|
#
|
|
# This is a workflow of its own, not a job in docker.yml: docker.yml has no
|
|
# pull-request trigger and holds one concurrency slot per ref, and the Runner
|
|
# image needs its own signer identity so its attestation cannot stand in for
|
|
# the application image's.
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
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
|
|
- scripts/runner-image-publish.mjs
|
|
- scripts/standard-image-contract.mjs
|
|
- docker/runner-image/**
|
|
workflow_dispatch:
|
|
schedule:
|
|
- cron: "23 6 * * 3"
|
|
|
|
# Least privilege: nothing at the workflow level. Only the publish job, which
|
|
# runs no build, can write images to the registry or sign.
|
|
permissions: {}
|
|
|
|
# A newer push to a pull request replaces its older run. A master run has a
|
|
# group of its own, so no other run cancels it here. The publish job has a
|
|
# second group, one for each digest; see there for what that group can cancel.
|
|
concurrency:
|
|
group: runner-image-${{ github.event.pull_request.number || github.sha }}
|
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
|
|
|
env:
|
|
IMAGE: ghcr.io/paperclipai/paperclip-runner
|
|
BUILD_CACHE: ghcr.io/paperclipai/paperclip-runner-buildcache
|
|
|
|
jobs:
|
|
identity:
|
|
name: Resolve the Runner image identity
|
|
# A fork's own pushes do not run this workflow. Pull requests and manual
|
|
# runs are not affected.
|
|
if: (github.event_name != 'push' && github.event_name != 'schedule') || (github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064')
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
permissions:
|
|
contents: read
|
|
packages: read
|
|
outputs:
|
|
lock: ${{ steps.lock.outputs.state }}
|
|
digest: ${{ steps.identity.outputs.digest }}
|
|
exists: ${{ steps.lookup.outputs.exists }}
|
|
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: the Actions cache must not reach a published 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.
|
|
#
|
|
# Never on a master push. The lockfile refresh owns pnpm-lock.yaml on
|
|
# master and holds new package versions until they are old enough, so
|
|
# the published image installs from the committed file and its digest
|
|
# is a function of the commit alone.
|
|
- name: Resolve the lockfile
|
|
if: github.event_name != 'push'
|
|
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)}."
|
|
echo "A master push publishes only from the committed lockfile."
|
|
} >> "$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"]
|
|
|
|
# The files the Runner build receives, after .dockerignore: the root
|
|
# manifest and the manifests of the Runner and the eval kernel are the
|
|
# only ones in it.
|
|
- name: Export the Runner build context
|
|
timeout-minutes: 10
|
|
run: docker buildx build --target runner-artifacts-context --output "type=local,dest=$RUNNER_TEMP/runner-image-context" .
|
|
|
|
# The image build installs with a frozen lockfile. This asks the same
|
|
# question first, offline and without installing, so that a lockfile
|
|
# that is merely behind is told apart from a broken build. pnpm can
|
|
# rewrite the lockfile it checks. It checks the exported copy above,
|
|
# which no build reads: the builds read the checkout.
|
|
- name: Check the lockfile against the Runner's manifests
|
|
id: lock
|
|
run: node scripts/runner-image-publish.mjs lock-state --context "$RUNNER_TEMP/runner-image-context"
|
|
|
|
# On master this is expected between a dependency change and the next
|
|
# lockfile refresh. It is not a failure, and there is nothing to build.
|
|
- name: Report a lockfile that is behind the Runner's manifests
|
|
if: steps.lock.outputs.state == 'behind'
|
|
run: |
|
|
set -euo pipefail
|
|
message="pnpm-lock.yaml is behind the Runner's manifests at $GITHUB_SHA; no Runner image for this commit; the next lockfile refresh will publish one."
|
|
echo "::notice title=No Runner image for this commit::$message"
|
|
echo "$message" >> "$GITHUB_STEP_SUMMARY"
|
|
# A run that resolved its own lockfile cannot be behind it.
|
|
test "$GITHUB_EVENT_NAME" = "push"
|
|
|
|
# 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
|
|
if: steps.lock.outputs.state == 'current'
|
|
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. Only for runs that resolved one: a master
|
|
# push builds from the committed file, which every job checks out.
|
|
- name: Keep the resolved lockfile for the build legs
|
|
if: steps.lock.outputs.state == 'current' && github.event_name != 'push'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
|
with:
|
|
name: runner-image-lockfile
|
|
path: pnpm-lock.yaml
|
|
if-no-files-found: error
|
|
retention-days: 1
|
|
|
|
# An image that exists is never rebuilt on master. It exists when its
|
|
# full tag does: that tag is written last. An inconclusive answer
|
|
# builds: the publish job decides again, strictly, before it writes a
|
|
# tag. Other events build whether or not the image exists.
|
|
- name: Look for the published image
|
|
id: lookup
|
|
if: steps.lock.outputs.state == 'current' && github.event_name == 'push'
|
|
env:
|
|
RUNNER_IMAGE_REGISTRY_USERNAME: ${{ github.actor }}
|
|
RUNNER_IMAGE_REGISTRY_PASSWORD: ${{ github.token }}
|
|
DIGEST: ${{ steps.identity.outputs.digest }}
|
|
run: node scripts/runner-image-publish.mjs publication-state --inputs-digest "$DIGEST"
|
|
|
|
# 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 cannot write to the registry on any event, and they
|
|
# write no registry build cache. The install runs dependency lifecycle
|
|
# scripts; the only token in the job can read packages, and only the lookup
|
|
# step receives it.
|
|
#
|
|
# A master push builds only when the image does not exist. A pull request
|
|
# and a manual run always build, so a change to the smoke matrix or to the
|
|
# pipeline is exercised even when the Runner's inputs did not change.
|
|
build:
|
|
name: Build and check (${{ matrix.arch }})
|
|
needs: identity
|
|
if: needs.identity.outputs.lock == 'current' && (github.event_name != 'push' || (github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && needs.identity.outputs.exists != 'true'))
|
|
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
|
|
packages: read
|
|
env:
|
|
# Only a canonical master push keeps its image for publication.
|
|
KEEP_IMAGE: ${{ github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs/heads/master' }}
|
|
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
|
|
|
|
# Another master run can have published these inputs since the identity
|
|
# job looked, most often the run of the push just before this one. Then
|
|
# this leg has nothing to do. Master only: other events always build.
|
|
# An inconclusive answer builds.
|
|
- name: Look again for the published image
|
|
id: published
|
|
if: github.event_name == 'push'
|
|
env:
|
|
RUNNER_IMAGE_REGISTRY_USERNAME: ${{ github.actor }}
|
|
RUNNER_IMAGE_REGISTRY_PASSWORD: ${{ github.token }}
|
|
run: node scripts/runner-image-publish.mjs publication-state --inputs-digest "$DIGEST"
|
|
|
|
- name: Download the resolved lockfile
|
|
if: github.event_name != 'push'
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: runner-image-lockfile
|
|
path: ${{ runner.temp }}/runner-image-lockfile
|
|
|
|
# Build from the lockfile the identity was computed from, not from a
|
|
# second resolution that a registry change could make different.
|
|
- name: Use the resolved lockfile
|
|
if: github.event_name != 'push'
|
|
run: cp "$RUNNER_TEMP/runner-image-lockfile/pnpm-lock.yaml" pnpm-lock.yaml
|
|
|
|
- name: Free runner disk
|
|
if: steps.published.outputs.exists != 'true'
|
|
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
|
|
if: steps.published.outputs.exists != 'true'
|
|
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. This job cannot
|
|
# publish it. On a canonical master push the archives are the images
|
|
# the publish job pushes, byte for byte.
|
|
- name: Build both variants of the Runner image
|
|
if: steps.published.outputs.exists != 'true'
|
|
timeout-minutes: 30
|
|
run: |
|
|
set -euo pipefail
|
|
cache=(--cache-from "type=registry,ref=$BUILD_CACHE:$ARCH")
|
|
if [ "$GITHUB_EVENT_NAME" = schedule ]; then cache=(--no-cache); fi
|
|
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" \
|
|
--metadata-file "$RUNNER_TEMP/runner-image/$variant.metadata.json" \
|
|
"${cache[@]}" \
|
|
.
|
|
cache=()
|
|
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
|
|
if: steps.published.outputs.exists != 'true'
|
|
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
|
|
if: steps.published.outputs.exists != 'true'
|
|
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
|
|
if: steps.published.outputs.exists != 'true'
|
|
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
|
|
if: steps.published.outputs.exists != 'true'
|
|
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"
|
|
|
|
# Written only after every check passed. The publish job accepts nothing
|
|
# without it. The two archives become one OCI layout that holds both
|
|
# variants and stores the layers they share once, so the upload is the
|
|
# size of the full image, not of both. The command reads the layout
|
|
# back and checks every blob against its digest.
|
|
#
|
|
# On every event, so that a pull request exercises the hand-off on
|
|
# real build output. Only the upload below is for a master push.
|
|
- name: Record the verified images
|
|
if: steps.published.outputs.exists != 'true'
|
|
timeout-minutes: 10
|
|
run: |
|
|
node scripts/runner-image-publish.mjs record \
|
|
--arch "$ARCH" \
|
|
--slim-archive "$RUNNER_TEMP/runner-image/slim.oci.tar" \
|
|
--slim-metadata "$RUNNER_TEMP/runner-image/slim.metadata.json" \
|
|
--full-archive "$RUNNER_TEMP/runner-image/full.oci.tar" \
|
|
--full-metadata "$RUNNER_TEMP/runner-image/full.metadata.json" \
|
|
--tree "$RUNNER_TEMP/runner-image/full" \
|
|
--layout "$RUNNER_TEMP/runner-image/images.oci.tar" \
|
|
--out "$RUNNER_TEMP/runner-image/record.json"
|
|
|
|
- name: Upload the verified images
|
|
if: env.KEEP_IMAGE == 'true' && steps.published.outputs.exists != 'true'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
|
with:
|
|
name: runner-image-${{ matrix.arch }}
|
|
path: |
|
|
${{ runner.temp }}/runner-image/images.oci.tar
|
|
${{ runner.temp }}/runner-image/record.json
|
|
if-no-files-found: error
|
|
# Layers are already compressed.
|
|
compression-level: 0
|
|
retention-days: 1
|
|
|
|
- name: Report an image another run published first
|
|
if: steps.published.outputs.exists == 'true'
|
|
run: echo "\`$IMAGE:inputs-$DIGEST\` and its slim variant already exist. This leg built nothing." >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
# Pushes the verified bytes, names them and attests them. Only a master push
|
|
# in the canonical repository reaches this job; it builds nothing and runs no
|
|
# dependency code.
|
|
#
|
|
# It writes two tags, `inputs-<digest>-slim` and then `inputs-<digest>`. The
|
|
# full tag is last, so it marks a complete publication: when it exists, both
|
|
# exist, and the full index names its slim index by digest. A run that stops
|
|
# between the two tags leaves a slim tag alone. The inputs are then not
|
|
# published; the next run for them builds again, replaces that slim tag with
|
|
# its own, and writes the full tag. It never keeps another run's slim image.
|
|
publish:
|
|
name: Publish and attest
|
|
needs: [identity, build]
|
|
if: github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs/heads/master' && needs.identity.outputs.lock == 'current' && needs.identity.outputs.exists != 'true'
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 30
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
id-token: write
|
|
attestations: write
|
|
# One publication per digest at a time, so the strict check below and the
|
|
# tag writes cannot interleave with another run for the same inputs.
|
|
# GitHub keeps one waiting job for a group. When three runs for one digest
|
|
# reach this job, the second is cancelled as the third arrives. That does
|
|
# no harm: the third publishes the digest if the first did not.
|
|
concurrency:
|
|
group: runner-image-publish-${{ needs.identity.outputs.digest }}
|
|
cancel-in-progress: false
|
|
env:
|
|
DIGEST: ${{ needs.identity.outputs.digest }}
|
|
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
|
|
|
|
# A build leg that found the image published uploaded nothing. Ask
|
|
# before the downloads, so that run ends here and not on a missing
|
|
# artifact.
|
|
- name: Look for an image another run published
|
|
id: early
|
|
env:
|
|
RUNNER_IMAGE_REGISTRY_USERNAME: ${{ github.actor }}
|
|
RUNNER_IMAGE_REGISTRY_PASSWORD: ${{ github.token }}
|
|
run: node scripts/runner-image-publish.mjs publication-state --inputs-digest "$DIGEST"
|
|
|
|
- name: Download the verified amd64 images
|
|
if: steps.early.outputs.exists != 'true'
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: runner-image-amd64
|
|
path: ${{ runner.temp }}/runner-image/amd64
|
|
|
|
- name: Download the verified arm64 images
|
|
if: steps.early.outputs.exists != 'true'
|
|
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
|
|
with:
|
|
name: runner-image-arm64
|
|
path: ${{ runner.temp }}/runner-image/arm64
|
|
|
|
- name: Accept only this run's verified images
|
|
id: legs
|
|
if: steps.early.outputs.exists != 'true'
|
|
run: |
|
|
node scripts/runner-image-publish.mjs verify-legs \
|
|
--dir "$RUNNER_TEMP/runner-image" \
|
|
--inputs-digest "$DIGEST" \
|
|
--source-revision "$GITHUB_SHA"
|
|
|
|
- name: Login to GitHub Container Registry
|
|
if: steps.early.outputs.exists != 'true'
|
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
if: steps.early.outputs.exists != 'true'
|
|
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4
|
|
|
|
# The downloads take a while. Ask once more immediately before the
|
|
# pushes, so that a run that lost the race does not upload its images.
|
|
- name: Look again immediately before pushing
|
|
id: prepush
|
|
if: steps.early.outputs.exists != 'true'
|
|
env:
|
|
RUNNER_IMAGE_REGISTRY_USERNAME: ${{ github.actor }}
|
|
RUNNER_IMAGE_REGISTRY_PASSWORD: ${{ github.token }}
|
|
run: node scripts/runner-image-publish.mjs publication-state --inputs-digest "$DIGEST"
|
|
|
|
# By digest and untagged. --preserve-digests fails rather than re-encode,
|
|
# so the registry holds exactly the images the build legs verified. Each
|
|
# leg's layout names its two images `slim` and `full`.
|
|
- name: Push the verified images by digest
|
|
if: steps.prepush.outputs.exists == 'false'
|
|
timeout-minutes: 15
|
|
env:
|
|
SLIM_AMD64: ${{ steps.legs.outputs.slim_amd64 }}
|
|
SLIM_ARM64: ${{ steps.legs.outputs.slim_arm64 }}
|
|
FULL_AMD64: ${{ steps.legs.outputs.full_amd64 }}
|
|
FULL_ARM64: ${{ steps.legs.outputs.full_arm64 }}
|
|
run: |
|
|
set -euo pipefail
|
|
command -v skopeo >/dev/null || { echo "skopeo is not installed on this runner"; exit 1; }
|
|
echo "Pushing with $(skopeo --version)"
|
|
layout="$RUNNER_TEMP/runner-image"
|
|
skopeo copy --preserve-digests "oci-archive:$layout/amd64/images.oci.tar:slim" "docker://$IMAGE@$SLIM_AMD64"
|
|
skopeo copy --preserve-digests "oci-archive:$layout/arm64/images.oci.tar:slim" "docker://$IMAGE@$SLIM_ARM64"
|
|
skopeo copy --preserve-digests "oci-archive:$layout/amd64/images.oci.tar:full" "docker://$IMAGE@$FULL_AMD64"
|
|
skopeo copy --preserve-digests "oci-archive:$layout/arm64/images.oci.tar:full" "docker://$IMAGE@$FULL_ARM64"
|
|
|
|
# The tags are create-only. Another run can have published these inputs
|
|
# since the lookups above. Only a clear answer goes on: `absent`, or
|
|
# `incomplete` (a slim tag alone, which this run replaces). `published`
|
|
# skips the rest. An inconclusive answer fails, and so does a full tag
|
|
# whose slim image is missing or is another image.
|
|
- name: Confirm the images are not published
|
|
id: gate
|
|
if: steps.prepush.outputs.exists == 'false'
|
|
env:
|
|
RUNNER_IMAGE_REGISTRY_USERNAME: ${{ github.actor }}
|
|
RUNNER_IMAGE_REGISTRY_PASSWORD: ${{ github.token }}
|
|
run: node scripts/runner-image-publish.mjs publication-state --inputs-digest "$DIGEST" --strict
|
|
|
|
# Candidate tags first, so a final tag appears only after its digest is
|
|
# attested. Candidate tags are internal and may be overwritten.
|
|
- name: Create the slim multi-platform candidate
|
|
if: steps.gate.outputs.publish == 'true'
|
|
env:
|
|
AMD64: ${{ steps.legs.outputs.slim_amd64 }}
|
|
ARM64: ${{ steps.legs.outputs.slim_arm64 }}
|
|
run: |
|
|
set -euo pipefail
|
|
docker buildx imagetools create \
|
|
--annotation "index:org.opencontainers.image.source=https://github.com/paperclipai/paperclip" \
|
|
--annotation "index:org.opencontainers.image.revision=$GITHUB_SHA" \
|
|
--annotation "index:io.paperclip.runner.inputs-digest=$DIGEST" \
|
|
--annotation "index:io.paperclip.runner.variant=slim" \
|
|
-t "$IMAGE:candidate-$DIGEST-slim" \
|
|
"$IMAGE@$AMD64" "$IMAGE@$ARM64"
|
|
|
|
- name: Verify the slim candidate names exactly the verified images
|
|
id: slim
|
|
if: steps.gate.outputs.publish == 'true'
|
|
env:
|
|
RUNNER_IMAGE_REGISTRY_USERNAME: ${{ github.actor }}
|
|
RUNNER_IMAGE_REGISTRY_PASSWORD: ${{ github.token }}
|
|
run: node scripts/runner-image-publish.mjs verify-index "candidate-$DIGEST-slim" --variant slim --dir "$RUNNER_TEMP/runner-image"
|
|
|
|
# The full index names the slim index of this same run by digest, so a
|
|
# consumer can tell that the two belong together.
|
|
- name: Create the full multi-platform candidate
|
|
if: steps.gate.outputs.publish == 'true'
|
|
env:
|
|
AMD64: ${{ steps.legs.outputs.full_amd64 }}
|
|
ARM64: ${{ steps.legs.outputs.full_arm64 }}
|
|
SLIM_INDEX: ${{ steps.slim.outputs.digest }}
|
|
run: |
|
|
set -euo pipefail
|
|
docker buildx imagetools create \
|
|
--annotation "index:org.opencontainers.image.source=https://github.com/paperclipai/paperclip" \
|
|
--annotation "index:org.opencontainers.image.revision=$GITHUB_SHA" \
|
|
--annotation "index:io.paperclip.runner.inputs-digest=$DIGEST" \
|
|
--annotation "index:io.paperclip.runner.variant=full" \
|
|
--annotation "index:io.paperclip.runner.slim-digest=$SLIM_INDEX" \
|
|
-t "$IMAGE:candidate-$DIGEST" \
|
|
"$IMAGE@$AMD64" "$IMAGE@$ARM64"
|
|
|
|
- name: Verify the full candidate names exactly the verified images and its slim index
|
|
id: full
|
|
if: steps.gate.outputs.publish == 'true'
|
|
env:
|
|
SLIM_INDEX: ${{ steps.slim.outputs.digest }}
|
|
RUNNER_IMAGE_REGISTRY_USERNAME: ${{ github.actor }}
|
|
RUNNER_IMAGE_REGISTRY_PASSWORD: ${{ github.token }}
|
|
run: |
|
|
node scripts/runner-image-publish.mjs verify-index "candidate-$DIGEST" --variant full \
|
|
--slim-digest "$SLIM_INDEX" --dir "$RUNNER_TEMP/runner-image"
|
|
|
|
- name: Attest the slim Runner image
|
|
if: steps.gate.outputs.publish == 'true'
|
|
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4
|
|
with:
|
|
subject-name: ghcr.io/paperclipai/paperclip-runner
|
|
subject-digest: ${{ steps.slim.outputs.digest }}
|
|
push-to-registry: true
|
|
|
|
- name: Attest the full Runner image
|
|
if: steps.gate.outputs.publish == 'true'
|
|
uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4
|
|
with:
|
|
subject-name: ghcr.io/paperclipai/paperclip-runner
|
|
subject-digest: ${{ steps.full.outputs.digest }}
|
|
push-to-registry: true
|
|
|
|
# Slim first, full last. Writing the slim tag replaces the one a run
|
|
# that stopped here left behind. The last command checks the pair as
|
|
# every later run will see it.
|
|
- name: Publish the tags
|
|
if: steps.gate.outputs.publish == 'true'
|
|
env:
|
|
SLIM_INDEX: ${{ steps.slim.outputs.digest }}
|
|
FULL_INDEX: ${{ steps.full.outputs.digest }}
|
|
RUNNER_IMAGE_REGISTRY_USERNAME: ${{ github.actor }}
|
|
RUNNER_IMAGE_REGISTRY_PASSWORD: ${{ github.token }}
|
|
run: |
|
|
set -euo pipefail
|
|
layout="$RUNNER_TEMP/runner-image"
|
|
docker buildx imagetools create -t "$IMAGE:inputs-$DIGEST-slim" "$IMAGE@$SLIM_INDEX"
|
|
node scripts/runner-image-publish.mjs verify-index "inputs-$DIGEST-slim" --variant slim --dir "$layout" --expect "$SLIM_INDEX"
|
|
docker buildx imagetools create -t "$IMAGE:inputs-$DIGEST" "$IMAGE@$FULL_INDEX"
|
|
node scripts/runner-image-publish.mjs verify-index "inputs-$DIGEST" --variant full --slim-digest "$SLIM_INDEX" --dir "$layout" --expect "$FULL_INDEX"
|
|
node scripts/runner-image-publish.mjs publication-state --inputs-digest "$DIGEST" --strict | grep -Fx "state=published"
|
|
{
|
|
echo "Published from \`$GITHUB_SHA\`:"
|
|
echo "- full: \`$IMAGE:inputs-$DIGEST\` at \`$IMAGE@$FULL_INDEX\`"
|
|
echo "- slim: \`$IMAGE:inputs-$DIGEST-slim\` at \`$IMAGE@$SLIM_INDEX\`"
|
|
} >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
- name: Report images another run published first
|
|
if: steps.early.outputs.exists == 'true' || steps.prepush.outputs.exists == 'true' || steps.gate.outputs.state == 'published'
|
|
run: echo "\`$IMAGE:inputs-$DIGEST\` and its slim variant already exist. Another run published first; this run published nothing." >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
cache:
|
|
name: Write the build cache (${{ matrix.arch }})
|
|
needs: [identity, publish]
|
|
if: github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs/heads/master' && needs.identity.outputs.lock == 'current' && needs.identity.outputs.exists != 'true'
|
|
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: 30
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
concurrency:
|
|
group: runner-image-buildcache-${{ matrix.arch }}
|
|
cancel-in-progress: false
|
|
env:
|
|
ARCH: ${{ matrix.arch }}
|
|
PLATFORM: ${{ matrix.platform }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
with:
|
|
persist-credentials: false
|
|
|
|
- name: Login to GitHub Container Registry
|
|
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4
|
|
with:
|
|
buildkitd-config-inline: |
|
|
[registry."docker.io"]
|
|
mirrors = ["mirror.gcr.io"]
|
|
|
|
- name: Build the cached stages and write the cache
|
|
timeout-minutes: 20
|
|
run: |
|
|
docker buildx build \
|
|
--target runner-artifacts-runnerd \
|
|
--platform "$PLATFORM" \
|
|
--cache-from "type=registry,ref=$BUILD_CACHE:$ARCH" \
|
|
--cache-to "type=registry,ref=$BUILD_CACHE:$ARCH,mode=max" \
|
|
--output type=cacheonly \
|
|
.
|