Files
PaperClipAI/.github/workflows/docker-merge-group.yml
T
DottaandPaperclip 320d7fe76d 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>
2026-11-25 15:22:50 -06:00

299 lines
12 KiB
YAML

name: Docker merge-queue build
# Build-before-merge for the standard image. While a change waits in the merge
# queue, build the production image for the exact merge-group commit, probe it,
# and keep it as a run artifact. When the queue fast-forwards master to that
# 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 access.
#
# Inert until the merge queue is enabled for master: no merge_group event fires
# before then.
on:
merge_group:
permissions: {}
# Each merge group has its own ref; a group that the queue rebuilt replaces the
# older run for that ref.
concurrency:
group: docker-merge-group-${{ github.ref }}
cancel-in-progress: true
jobs:
macos_runner_runtime:
uses: ./.github/workflows/macos-runner-runtime.yml
permissions:
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, 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:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
arch: arm64
# GitHub-hosted runners: the protected release fleets admit only
# 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
steps:
- name: Checkout
uses: actions/checkout@v7
with:
persist-credentials: false
# Same history as docker.yml, for `git describe` below.
fetch-depth: 0
filter: blob:none
- name: Download the native macOS SSH runtime
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
name: ${{ needs.macos_runner_runtime.outputs.artifact_name }}
path: docker/remote-runtimes/
# The merge queue fast-forwards master to this exact commit, so these
# stamps match what a master build of the same commit would carry.
- name: Compute build version
id: build-version
run: |
set -euo pipefail
version="$(git describe --tags --match 'v*' --long --dirty 2>/dev/null || true)"
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "Stamping build version: ${version:-<none>}"
- name: Compute tool cache epoch
id: tools-epoch
run: echo "epoch=$(date -u +%G-W%V)" >> "$GITHUB_OUTPUT"
- name: Setup pnpm
uses: pnpm/action-setup@v6
with:
version: 9.15.4
run_install: false
- name: Setup Node.js
uses: actions/setup-node@v7
with:
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
changed="$(git status --porcelain)"
if [ -n "$changed" ] && printf '%s\n' "$changed" | grep -Fvq ' pnpm-lock.yaml'; then
echo "Unexpected files changed during lockfile refresh:"
echo "$changed"
exit 1
fi
- name: Free runner disk
run: |
set -euo pipefail
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
uses: docker/setup-buildx-action@v4
with:
buildkitd-config-inline: |
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
- name: Compute schema migration labels
id: schema
run: |
set -euo pipefail
last=$(find packages/db/src/migrations -maxdepth 1 -name '*.sql' -printf '%f\n' | LC_ALL=C sort | tail -1)
count=$(find packages/db/src/migrations -maxdepth 1 -name '*.sql' | wc -l | tr -d ' ')
echo "last=${last}" >> "$GITHUB_OUTPUT"
echo "count=${count}" >> "$GITHUB_OUTPUT"
# Same labels as a master build. The version label names master, not the
# temporary merge-queue branch this commit is tested on.
- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
labels: |
org.opencontainers.image.version=master
io.github.paperclipai.schema.last-migration=${{ steps.schema.outputs.last }}
io.github.paperclipai.schema.migration-count=${{ steps.schema.outputs.count }}
# Reads the public registry cache anonymously and writes none of it.
- name: Build image archive
id: build
uses: docker/build-push-action@v7
with:
context: .
target: production
build-args: |
PAPERCLIP_BUILD_VERSION=${{ steps.build-version.outputs.version }}
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 }}
${{ 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
env:
ARCHIVE: ${{ runner.temp }}/merge-group-image/image.tar
PLATFORM: ${{ matrix.platform }}
IMAGE: paperclip-merge-group:${{ matrix.arch }}
run: |
set -euo pipefail
docker load --input "$ARCHIVE"
docker run --rm -i --pull never --platform "$PLATFORM" "$IMAGE" sh -s < scripts/assert-orphan-reaping.sh
docker image rm "$IMAGE"
# Written only after the probe passes. Promotion trusts nothing without it.
- name: Record the verified image
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
with:
name: merge-group-image-${{ matrix.arch }}
path: |
${{ runner.temp }}/merge-group-image/image.tar
${{ runner.temp }}/merge-group-image/record.json
if-no-files-found: error
# Layers are already compressed.
compression-level: 0
retention-days: 3