Files
PaperClipAI/.github/workflows/docker-merge-group.yml
T
Dotta 8f6d94169a fix(ci): run merge-queue Docker builds on standard runners and skip wait on AWS master (#23043)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The merge-queue Docker workflow
(`.github/workflows/docker-merge-group.yml`) pre-builds the production
image on `merge_group` so `docker.yml` can promote it on `master`
> - #22993 routed `amd64` merge-queue builds to `cloud-release-32`,
which does not admit `docker-merge-group.yml`, leaving every merge-queue
build queued forever
> - While those builds sat queued, `docker.yml` waited 3 minutes in
`Find the merge-queue build of this commit` before falling back to its
fast AWS release runner
> - This pull request moves `docker-merge-group.yml` back to standard
GitHub-hosted `matrix.runner` runners and sets
`MERGE_GROUP_FIND_WAIT_MS=0` when `CORE_RELEASE_AWS_ENABLED=true`
> - The benefit is that merge-queue builds actually execute and promote
when ready, while fast AWS `master` builds never lose 3 minutes waiting
behind slower GitHub-hosted merge-queue legs

## Linked Issues or Issue Description

Refs #22993, Refs #23000

**Describe the bug**
Every `docker-merge-group.yml` run stayed queued forever on `build
(linux/amd64)` because the `cloud-release-32` runner group does not
admit that workflow. In addition, `docker.yml` waited 3 minutes polling
unfinished merge-queue runs even when running on the faster AWS release
fleet (`CORE_RELEASE_AWS_ENABLED=true`).

**Steps to reproduce**
1. Merge a PR through the GitHub Merge Queue on `master`.
2. Inspect the triggered `Docker merge-queue build` run and see `build
(linux/amd64)` queued indefinitely.
3. Inspect the subsequent `Docker` run on `master` and see `Find the
merge-queue build of this commit` spend 3 minutes waiting before falling
back to a source build.

**Expected behavior**
`docker-merge-group.yml` starts on standard GitHub-hosted runners
(`ubuntu-latest` / `ubuntu-24.04-arm`), and `docker.yml` promotes an
already-completed merge-queue build immediately without stalling 3
minutes when running on the AWS release fleet.

## What Changed

- `.github/workflows/docker-merge-group.yml`: restore `runs-on: ${{
matrix.runner }}` for `build` so `amd64` runs on `ubuntu-latest` instead
of queueing on `cloud-release-32`.
- `.github/workflows/docker.yml`: pass `MERGE_GROUP_FIND_WAIT_MS: ${{
vars.CORE_RELEASE_AWS_ENABLED == 'true' && '0' || '180000' }}` to `Find
the merge-queue build of this commit`.
- `scripts/merge-group-image.mjs`: add `resolveFindWaitMs(env)` (clamped
to `[0, 180000]`, defaulting to `180000`) and use it in `find`.
- `server/src/__tests__/docker-runner-workflows.test.ts` &
`scripts/merge-group-image.test.mjs`: add guard tests for standard
runner placement and `resolveFindWaitMs` / `MERGE_GROUP_FIND_WAIT_MS`.

## Verification

- `vitest run server/src/__tests__/docker-runner-workflows.test.ts`:
15/15 passed.
- `node --test scripts/merge-group-image.test.mjs`: 10/10 passed.

## Risks

- Low risk. Restores standard runner placement (matching #23000) and
keeps the exact promotion verification contract unchanged; fail-open
fallback to source build is preserved.

## Model Used

- Google Antigravity agent (Gemini / Antigravity coding harness with
shell execution and tool use).

## 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
2026-11-26 07:18:53 -06:00

297 lines
11 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 and larger release
# runner groups admit only docker.yml on master.
runs-on: ${{ 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