perf(docker): consume attested Runner image in merge-queue builds and promote on master (#22993)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The repository includes `.github/workflows/docker-merge-group.yml`
and `scripts/merge-group-image.mjs` to pre-build production images in
the GitHub merge queue so `.github/workflows/docker.yml` can promote
verified bytes on `master` instead of rebuilding from scratch
> - Currently, `docker.yml` skips merge-queue promotion whenever
`needs.runner_image.outputs.mode == 'published'`, and
`docker-merge-group.yml` builds the Runner inline on 4-core
`ubuntu-latest` while waiting up to 15 minutes during promotion lookup
> - With `RUNNER_IMAGE_CONSUME_ENABLED=true`, that meant enabling the
merge queue would never promote pre-built images on normal commits
> - This pull request wires read-only attested Runner image consumption
into `docker-merge-group.yml`, records and verifies `runnerInputsDigest`
in `scripts/merge-group-image.mjs`, routes canonical `amd64` merge-group
builds to `cloud-release-32`, parallelizes disk cleanup, caps promotion
wait to 3 minutes, and allows `docker.yml` to promote verified
merge-queue images when `runner_image` resolves to `published`
> - The benefit is enabling fast pre-merge image promotion for
merge-queue commits without weakening attestation, Runner-digest
matching, or credential isolation

## Linked Issues or Issue Description

**What existing behavior does this improve?**
Pre-merge Docker image building and promotion across
`.github/workflows/docker-merge-group.yml`,
`scripts/merge-group-image.mjs`, and `.github/workflows/docker.yml`.

**Subsystem affected**
Cross-cutting (multiple of the above)

**Current behavior**
`docker-merge-group.yml` builds the Runner inline on `ubuntu-latest`
with serial disk cleanup, and `docker.yml` disables merge-queue
promotion whenever `needs.runner_image.outputs.mode == 'published'`.
`scripts/merge-group-image.mjs` also waits up to 15 minutes for an
in-flight merge-group run.

**Proposed behavior**
`docker-merge-group.yml` resolves an already-published Runner image
(non-blocking lookup, read-only permissions, `gh attestation verify`),
runs `amd64` on `vars.CORE_PUBLICATION_RUNNER || 'cloud-release-32'`,
skips unnecessary disk cleanup / runs cleanup in parallel, and records
`runnerInputsDigest` in `record.json`. `docker.yml` attempts merge-queue
promotion regardless of whether `runner_image` resolved `published` or
`inline`, passing `RUNNER_INPUTS_DIGEST` to `merge-group-image.mjs
verify` so promotion only succeeds when the merge-group image used the
exact same Runner inputs digest. Promotion wait is capped at 3 minutes
so `docker.yml` falls back quickly to building from source if a
merge-group build is still running.

**Reason and benefit**
Makes merge-queue pre-built image promotion work with published Runner
images so queued commits can promote verified bytes to GHCR instead of
rebuilding after merge.

**Breaking changes**
None.

## What Changed

- Added a read-only `runner_image` resolution and attestation
verification job to `.github/workflows/docker-merge-group.yml`
(non-blocking lookup, `persist-credentials: false`, SHA-pinned actions,
no secrets or registry writes).
- Routed canonical `amd64` merge-group builds in
`docker-merge-group.yml` to `vars.CORE_PUBLICATION_RUNNER ||
'cloud-release-32'`, skipped lockfile refresh when using a published
Runner, parallelized `Free runner disk` with a `>= 50 GiB` skip, and
passed `build-contexts`, `build-args`, and `labels` into `Build image
archive`.
- Updated `scripts/merge-group-image.mjs` to record and verify
`runnerInputsDigest`, include `scripts/runner-image-resolve.mjs` in
`pipelineFiles`, and cap `findWaitMs` at 3 minutes.
- Updated `.github/workflows/docker.yml` to output `inputs_digest` from
`runner_image`, run `Find the merge-queue build of this commit` even
when `mode == 'published'`, and verify `--runner-inputs-digest` before
promoting.
- Updated `scripts/merge-group-image.test.mjs`,
`server/src/__tests__/docker-build-stamp.test.ts`, and
`server/src/__tests__/docker-runner-workflows.test.ts`.

## Verification

- `node --test scripts/merge-group-image.test.mjs
scripts/__tests__/docker-cache-export-policy.test.mjs
scripts/__tests__/release-verify-workflow.test.mjs
scripts/macos-runner-runtime-workflow.test.mjs` (all passed)
- Vitest: `server/src/__tests__/docker-build-stamp.test.ts` (18/18
passed), `server/src/__tests__/docker-runner-workflows.test.ts` (11/11
passed)

## Risks

- Low risk. Promotion remains strictly fail-closed: `docker.yml` runs
`$BEFORE:scripts/merge-group-image.mjs`, refuses promotion on any
pipeline file change, verifies commit SHA, tree SHA, architecture,
archive blob digests, and exact `runnerInputsDigest`, and falls back to
building from source on any mismatch or timeout.

## Model Used

- Gemini 3 Pro (Antigravity agent with tool use, shell execution, and
local test verification)

## 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

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip authored and GitHub committed 2026-11-25 15:22:50 -06:00
1 parent 64bef50be0
commit 320d7fe76d
6 files changed
+300 -47

No files matched your search

+127 -12
View File
@@ -6,7 +6,7 @@ name: Docker merge-queue build
# commit, docker.yml pushes these exact bytes (scripts/merge-group-image.mjs)
# instead of rebuilding them. Without a matching successful run, docker.yml
# builds from source as before. Nothing here can publish: this workflow has no
# registry credentials, no secrets, and read-only contents access.
# registry credentials, no secrets, and read-only access.
#
# Inert until the merge queue is enabled for master: no merge_group event fires
# before then.
@@ -28,9 +28,88 @@ jobs:
contents: read
actions: read
runner_image:
name: Resolve the Runner image of this commit
if: vars.RUNNER_IMAGE_CONSUME_ENABLED == 'true' && github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.event.merge_group.base_ref == 'refs/heads/master'
continue-on-error: true
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
actions: read
attestations: read
outputs:
mode: ${{ steps.verify.outputs.mode || 'inline' }}
inputs_digest: ${{ steps.verify.outputs.inputs_digest }}
build_contexts: ${{ steps.verify.outputs.build_contexts }}
labels: ${{ steps.verify.outputs.labels }}
build_args: ${{ steps.verify.outputs.build_args }}
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
- name: Setup Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: 24
package-manager-cache: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@37fe631027851001ddb9b187196cc803df7f5f0e # v4
with:
buildkitd-config-inline: |
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
- name: Compute the Runner inputs of this commit
timeout-minutes: 5
run: node scripts/runner-image-resolve.mjs inputs --dir "$RUNNER_TEMP/runner-image-resolve"
- name: Find the published Runner image of these inputs
id: resolve
timeout-minutes: 5
run: node scripts/runner-image-resolve.mjs resolve --dir "$RUNNER_TEMP/runner-image-resolve"
- name: Verify the attestation of the Runner image
id: verify
if: steps.resolve.outputs.mode == 'published'
timeout-minutes: 5
env:
GH_TOKEN: ${{ github.token }}
IMAGE: ${{ steps.resolve.outputs.image }}
INPUTS_DIGEST: ${{ steps.resolve.outputs.inputs_digest }}
LABELS: ${{ steps.resolve.outputs.labels }}
BUILD_ARGS: ${{ steps.resolve.outputs.build_args }}
run: |
set -euo pipefail
if ! gh attestation verify "oci://$IMAGE" \
--repo paperclipai/paperclip \
--signer-workflow paperclipai/paperclip/.github/workflows/runner-image.yml \
--source-ref refs/heads/master; then
echo "::warning title=Runner image not verified::The attestation of $IMAGE did not verify. The image build makes its own Runner."
exit 1
fi
{
echo "mode=published"
echo "inputs_digest=$INPUTS_DIGEST"
echo "build_contexts=runner-artifacts=docker-image://$IMAGE"
echo "build_args=$BUILD_ARGS"
echo "labels<<runner-image-labels-end"
echo "$LABELS"
echo "runner-image-labels-end"
} >> "$GITHUB_OUTPUT"
build:
needs: macos_runner_runtime
if: github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.event.merge_group.base_ref == 'refs/heads/master'
needs: [macos_runner_runtime, runner_image]
if: ${{ !cancelled() && needs.macos_runner_runtime.result == 'success' && github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.event.merge_group.base_ref == 'refs/heads/master' }}
strategy:
fail-fast: false
matrix:
@@ -42,8 +121,10 @@ jobs:
runner: ubuntu-24.04-arm
arch: arm64
# GitHub-hosted runners: the protected release fleets admit only
# docker.yml on master.
runs-on: ${{ matrix.runner }}
# docker.yml on master. amd64 merge-queue builds for canonical master use
# the larger GitHub-hosted runner (cloud-release-32) so pre-merge builds
# finish quickly while commits wait in the queue.
runs-on: ${{ matrix.arch == 'amd64' && (vars.CORE_PUBLICATION_RUNNER || 'cloud-release-32') || matrix.runner }}
timeout-minutes: 60
permissions:
contents: read
@@ -88,6 +169,7 @@ jobs:
node-version: 24
- name: Refresh lockfile for Docker build context
if: needs.runner_image.outputs.mode != 'published'
run: |
set -euo pipefail
pnpm install --resolution-only --ignore-scripts --no-frozen-lockfile
@@ -101,11 +183,31 @@ jobs:
- name: Free runner disk
run: |
set -euo pipefail
pnpm store prune || true
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
avail_kb="$(df -Pk / | awk 'NR==2 {print $4}')"
if [ "${avail_kb:-0}" -ge 52428800 ]; then
echo "Root filesystem already has >= 50 GiB free; skipping cleanup."
df -h
exit 0
fi
pids=()
(pnpm store prune || true) & pids+=("$!")
(sudo apt-get clean || true) & pids+=("$!")
(docker system prune -af || true) & pids+=("$!")
for dir in \
/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; do
(sudo rm -rf "$dir" || true) & pids+=("$!")
done
for pid in "${pids[@]}"; do
wait "$pid" || true
done
df -h
- name: Set up Docker Buildx
@@ -148,11 +250,15 @@ jobs:
PAPERCLIP_BUILD_COMMIT=${{ github.sha }}
PAPERCLIP_MACOS_RUNTIME_INPUTS_DIGEST=${{ needs.macos_runner_runtime.outputs.inputs_digest }}
CLI_TOOLS_CACHE_EPOCH=${{ steps.tools-epoch.outputs.epoch }}
${{ needs.runner_image.outputs.build_args }}
build-contexts: ${{ needs.runner_image.outputs.build_contexts }}
platforms: ${{ matrix.platform }}
push: false
outputs: type=oci,dest=${{ runner.temp }}/merge-group-image/image.tar,name=paperclip-merge-group:${{ matrix.arch }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache-${{ matrix.arch }}
labels: ${{ steps.meta.outputs.labels }}
labels: |
${{ steps.meta.outputs.labels }}
${{ needs.runner_image.outputs.labels }}
# PID 1 must be an init that reaps adopted orphans; see docker.yml.
- name: Verify PID 1 reaps orphaned processes
@@ -168,7 +274,16 @@ jobs:
# Written only after the probe passes. Promotion trusts nothing without it.
- name: Record the verified image
run: node scripts/merge-group-image.mjs record --arch "${{ matrix.arch }}" --archive "${{ runner.temp }}/merge-group-image/image.tar" --out "${{ runner.temp }}/merge-group-image/record.json"
env:
ARCH: ${{ matrix.arch }}
RUNNER_INPUTS_DIGEST: ${{ needs.runner_image.outputs.inputs_digest }}
run: |
set -euo pipefail
node scripts/merge-group-image.mjs record \
--arch "$ARCH" \
--archive "$RUNNER_TEMP/merge-group-image/image.tar" \
--out "$RUNNER_TEMP/merge-group-image/record.json" \
--runner-inputs-digest "$RUNNER_INPUTS_DIGEST"
- name: Upload the verified image
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
+10 -6
View File
@@ -51,6 +51,7 @@ jobs:
attestations: read
outputs:
mode: ${{ steps.verify.outputs.mode || 'inline' }}
inputs_digest: ${{ steps.verify.outputs.inputs_digest }}
build_contexts: ${{ steps.verify.outputs.build_contexts }}
labels: ${{ steps.verify.outputs.labels }}
build_args: ${{ steps.verify.outputs.build_args }}
@@ -104,6 +105,7 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
IMAGE: ${{ steps.resolve.outputs.image }}
INPUTS_DIGEST: ${{ steps.resolve.outputs.inputs_digest }}
LABELS: ${{ steps.resolve.outputs.labels }}
BUILD_ARGS: ${{ steps.resolve.outputs.build_args }}
run: |
@@ -118,6 +120,7 @@ jobs:
fi
{
echo "mode=published"
echo "inputs_digest=$INPUTS_DIGEST"
echo "build_contexts=runner-artifacts=docker-image://$IMAGE"
echo "build_args=$BUILD_ARGS"
echo "labels<<runner-image-labels-end"
@@ -354,15 +357,15 @@ jobs:
# Build-before-merge. When the merge queue already built and probed this
# exact commit (docker-merge-group.yml, with no registry credentials),
# push those bytes, unless a published Runner image is used. The script
# requires a successful merge-group run of this repository for this SHA
# and checks the record's commit, tree, architecture and archive digest.
# Any missing or mismatched proof, or any failure here, leaves
# push those bytes. The script requires a successful merge-group run of
# this repository for this SHA and checks the record's commit, tree,
# architecture, Runner inputs digest, and archive digest. Any missing or
# mismatched proof, or any failure here, leaves
# `steps.promote.outputs.digest` empty and the build below runs as
# before. The probe below and the exact-source gate apply either way.
- name: Find the merge-queue build of this commit
id: find
if: needs.runner_image.outputs.mode != 'published' && github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs/heads/master'
if: github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs/heads/master'
continue-on-error: true
env:
GITHUB_TOKEN: ${{ github.token }}
@@ -395,6 +398,7 @@ jobs:
DIRECTORY: ${{ runner.temp }}/merge-group-image
IMAGE_NAME: ghcr.io/${{ github.repository }}
BEFORE: ${{ github.event.before }}
RUNNER_INPUTS_DIGEST: ${{ needs.runner_image.outputs.inputs_digest }}
run: |
set -euo pipefail
# Say plainly when this runner image cannot promote, instead of
@@ -412,7 +416,7 @@ jobs:
git show "$BEFORE:scripts/merge-group-image.mjs" > "$trusted"
# Verify without writing a step output: the digest is set only after
# the exact bytes are in the registry.
verified="$(GITHUB_OUTPUT='' node "$trusted" verify --arch "$ARCH" --dir "$DIRECTORY" --since "$BEFORE")"
verified="$(GITHUB_OUTPUT='' node "$trusted" verify --arch "$ARCH" --dir "$DIRECTORY" --since "$BEFORE" --runner-inputs-digest "$RUNNER_INPUTS_DIGEST")"
digest="$(printf '%s\n' "$verified" | sed -n 's/^digest=//p')"
printf '%s' "$digest" | grep -Eq '^sha256:[a-f0-9]{64}$'
# --preserve-digests fails rather than re-encode, so the registry