mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 10:07:24 +01:00
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:
1 parent
64bef50be0
commit
320d7fe76d
6 files changed
+300
-47
No files matched your search
@@ -175,9 +175,10 @@ describe("Application image Runner", () => {
|
||||
for (const [name, source] of [["standard", workflow], ["preview", previewWorkflow], ["merge group", mergeGroupWorkflow], ["pull request", appCheckWorkflow]]) {
|
||||
expect(source, name).toContain("PAPERCLIP_BUILD_COMMIT=");
|
||||
expect(source, name).not.toMatch(/PAPERCLIP_RUNNER_(?:SOURCE_REVISION|IMAGE_PUBLICATION)/);
|
||||
if (name !== "standard") expect(source, name).not.toMatch(/runner-artifacts|build-contexts?\b/);
|
||||
if (name !== "standard" && name !== "merge group") expect(source, name).not.toMatch(/runner-artifacts|build-contexts?\b/);
|
||||
}
|
||||
expect(workflow.match(/runner-artifacts|build-contexts?\b/g)).toEqual(["runner-artifacts", "build-contexts"]);
|
||||
expect(mergeGroupWorkflow.match(/runner-artifacts|build-contexts?\b/g)).toEqual(["runner-artifacts", "build-contexts"]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ const IMAGE = `ghcr.io/paperclipai/paperclip-runner@sha256:${"c".repeat(64)}`;
|
||||
const INPUTS = "1".repeat(64);
|
||||
const LABELS = `io.paperclip.runner.image=${IMAGE}\nio.paperclip.runner.inputs-digest=${INPUTS}`;
|
||||
const BUILD_ARGS = `PAPERCLIP_RUNNER_EXPECT_INPUTS_DIGEST=${INPUTS}`;
|
||||
const published = { mode: "published", build_contexts: `runner-artifacts=docker-image://${IMAGE}`, labels: LABELS, build_args: BUILD_ARGS };
|
||||
const published = { mode: "published", inputs_digest: INPUTS, build_contexts: `runner-artifacts=docker-image://${IMAGE}`, labels: LABELS, build_args: BUILD_ARGS };
|
||||
const canonical = "github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064'";
|
||||
const VERIFY = "Verify the attestation of the Runner image";
|
||||
|
||||
@@ -110,9 +110,7 @@ describe("the Runner image an application image build copies in docker.yml", ()
|
||||
expect(condition(resolver, 4)).toBe(`vars.RUNNER_IMAGE_CONSUME_ENABLED == 'true' && ${canonical}`);
|
||||
expect(workflow.match(/RUNNER_IMAGE_CONSUME_ENABLED/g)).toHaveLength(1);
|
||||
expect(Object.keys(jobs).filter((name) => jobs[name].includes("runner-image-resolve.mjs"))).toEqual(["runner_image"]);
|
||||
for (const name of ["docker-merge-group.yml", "docker-app-check.yml"]) {
|
||||
expect(read(name)).not.toMatch(/runner-image-resolve|RUNNER_IMAGE_CONSUME_ENABLED|build-contexts|--build-context|io\.paperclip\.runner|runner_image/);
|
||||
}
|
||||
expect(read("docker-app-check.yml")).not.toMatch(/runner-image-resolve|RUNNER_IMAGE_CONSUME_ENABLED|build-contexts|--build-context|io\.paperclip\.runner|runner_image/);
|
||||
});
|
||||
|
||||
it("keeps inline Runner arguments and includes the macOS runtime identity without a published Runner", () => {
|
||||
@@ -123,7 +121,7 @@ describe("the Runner image an application image build copies in docker.yml", ()
|
||||
it("gives both architectures the one answer: the context, the labels and the expected inputs of the verified image", () => {
|
||||
expect(/^ {4}needs: \[(.+)\]$/m.exec(legs)![1].split(", ")).toContain("runner_image");
|
||||
const reads = [...legs.matchAll(/needs\.runner_image\.[a-z_.]+/g)].map((match) => match[0]);
|
||||
expect(new Set(reads)).toEqual(new Set(["mode", "build_args", "build_contexts", "labels"].map((name) => `needs.runner_image.outputs.${name}`)));
|
||||
expect(new Set(reads)).toEqual(new Set(["mode", "inputs_digest", "build_args", "build_contexts", "labels"].map((name) => `needs.runner_image.outputs.${name}`)));
|
||||
for (const line of legs.split("\n").filter((entry) => entry.includes("needs.runner_image"))) expect(line).not.toContain("matrix.");
|
||||
expect(buildInputs(published)).toEqual({
|
||||
buildArgs: [...inlineBuild.buildArgs, BUILD_ARGS],
|
||||
@@ -136,6 +134,7 @@ describe("the Runner image an application image build copies in docker.yml", ()
|
||||
const declared = /\n {4}outputs:\n((?: {6}.+\n)+)/.exec(resolver)![1].trimEnd().split("\n").map((line) => line.trim());
|
||||
expect(declared).toEqual([
|
||||
"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 }}",
|
||||
@@ -143,7 +142,7 @@ describe("the Runner image an application image build copies in docker.yml", ()
|
||||
const verify = named(resolver, VERIFY);
|
||||
expect(verify).toContain("\n id: verify\n");
|
||||
expect(condition(verify, 8)).toBe("steps.resolve.outputs.mode == 'published'");
|
||||
const env = { IMAGE, LABELS, BUILD_ARGS, GH_TOKEN: "token-for-the-test" };
|
||||
const env = { IMAGE, INPUTS_DIGEST: INPUTS, LABELS, BUILD_ARGS, GH_TOKEN: "token-for-the-test" };
|
||||
const gh = (status: number) => ({ gh: `printf '%s\\n' "$*" >> "$CALLS"\nexit ${status}` });
|
||||
|
||||
const verified = runStep(verify, env, gh(0));
|
||||
@@ -209,13 +208,14 @@ describe("the Runner image an application image build copies in docker.yml", ()
|
||||
expectPinnedAndExpressionFree(resolver);
|
||||
});
|
||||
|
||||
it("does not promote a merge-queue image for a commit that copies a published Runner", () => {
|
||||
it("promotes a verified merge-queue image only when its Runner inputs digest matches master", () => {
|
||||
const find = named(legs, "Find the merge-queue build of this commit");
|
||||
expect(condition(find, 8)).toBe(`needs.runner_image.outputs.mode != 'published' && ${canonical} && ${masterPush}`);
|
||||
expect(condition(find, 8)).toBe(`${canonical} && ${masterPush}`);
|
||||
for (const name of ["Download the merge-queue image", "Promote the merge-queue image"]) {
|
||||
expect(condition(named(legs, name), 8)).toBe("steps.find.outputs.run_id != ''");
|
||||
}
|
||||
expect(legs.match(/steps\.find\.outputs\.run_id/g)).toHaveLength(3);
|
||||
expect(named(legs, "Promote the merge-queue image")).toContain("RUNNER_INPUTS_DIGEST: ${{ needs.runner_image.outputs.inputs_digest }}");
|
||||
expect(condition(named(legs, "Build and push by digest"), 8)).toBe("steps.promote.outputs.digest == ''");
|
||||
});
|
||||
|
||||
@@ -230,6 +230,81 @@ describe("the Runner image an application image build copies in docker.yml", ()
|
||||
});
|
||||
});
|
||||
|
||||
describe("the merge-queue build's Runner image in docker-merge-group.yml", () => {
|
||||
const workflow = read("docker-merge-group.yml");
|
||||
const jobs = jobsOf(workflow);
|
||||
const resolver = jobs.runner_image;
|
||||
const buildJob = jobs.build;
|
||||
const buildInputs = (resolved: Record<string, string>) =>
|
||||
listInputs(named(buildJob, "Build image archive"), "needs.runner_image.outputs", resolved);
|
||||
const inlineBuild = {
|
||||
buildArgs: [
|
||||
"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 }}",
|
||||
],
|
||||
buildContexts: [],
|
||||
labels: ["${{ steps.meta.outputs.labels }}"],
|
||||
};
|
||||
|
||||
it("gates resolution to canonical master merge groups when RUNNER_IMAGE_CONSUME_ENABLED is true and stays read-only", () => {
|
||||
expect(condition(resolver, 4)).toBe(
|
||||
`vars.RUNNER_IMAGE_CONSUME_ENABLED == 'true' && ${canonical} && github.event.merge_group.base_ref == 'refs/heads/master'`,
|
||||
);
|
||||
expect(permissions(resolver)).toEqual(["contents: read", "actions: read", "attestations: read"]);
|
||||
expect(resolver).toContain("\n continue-on-error: true\n");
|
||||
expect(resolver).toContain("persist-credentials: false");
|
||||
expect(resolver).not.toMatch(registryWrite);
|
||||
expectPinnedAndExpressionFree(resolver);
|
||||
// Non-blocking lookup in the merge queue: never passes --wait.
|
||||
expect(named(resolver, "Find the published Runner image of these inputs")).not.toContain("--wait");
|
||||
});
|
||||
|
||||
it("hands build only attested published outputs and falls back cleanly on inline or failed attestation", () => {
|
||||
const declared = /\n {4}outputs:\n((?: {6}.+\n)+)/.exec(resolver)![1].trimEnd().split("\n").map((line) => line.trim());
|
||||
expect(declared).toEqual([
|
||||
"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 }}",
|
||||
]);
|
||||
|
||||
const verify = named(resolver, VERIFY);
|
||||
expect(condition(verify, 8)).toBe("steps.resolve.outputs.mode == 'published'");
|
||||
const env = { IMAGE, INPUTS_DIGEST: INPUTS, LABELS, BUILD_ARGS, GH_TOKEN: "token-for-the-test" };
|
||||
const gh = (status: number) => ({ gh: `printf '%s\\n' "$*" >> "$CALLS"\nexit ${status}` });
|
||||
|
||||
const verified = runStep(verify, env, gh(0));
|
||||
expect(verified.status, verified.stderr).toBe(0);
|
||||
expect(outputs(verified.output)).toEqual(published);
|
||||
expect(verified.stdout).not.toContain("::warning");
|
||||
|
||||
for (const status of [1, 4]) {
|
||||
const refused = runStep(verify, env, gh(status));
|
||||
expect(refused.status, refused.stderr).toBe(1);
|
||||
expect(refused.output).toBe("");
|
||||
expect(refused.stdout).toContain("::warning title=Runner image not verified::");
|
||||
}
|
||||
|
||||
expect(buildInputs({})).toEqual(inlineBuild);
|
||||
expect(buildInputs({ mode: "inline" })).toEqual(inlineBuild);
|
||||
expect(buildInputs(published)).toEqual({
|
||||
buildArgs: [...inlineBuild.buildArgs, BUILD_ARGS],
|
||||
buildContexts: [`runner-artifacts=docker-image://${IMAGE}`],
|
||||
labels: [...inlineBuild.labels, ...LABELS.split("\n")],
|
||||
});
|
||||
});
|
||||
|
||||
it("records the attested Runner inputs digest for master promotion verification", () => {
|
||||
expect(condition(named(buildJob, "Refresh lockfile for Docker build context"), 8)).toBe("needs.runner_image.outputs.mode != 'published'");
|
||||
const record = named(buildJob, "Record the verified image");
|
||||
expect(record).toContain("RUNNER_INPUTS_DIGEST: ${{ needs.runner_image.outputs.inputs_digest }}");
|
||||
expect(record).toContain('--runner-inputs-digest "$RUNNER_INPUTS_DIGEST"');
|
||||
});
|
||||
});
|
||||
|
||||
describe("the pull-request check of the application image's Runner path", () => {
|
||||
const workflow = read("docker-app-check.yml");
|
||||
const jobs = jobsOf(workflow);
|
||||
|
||||
Reference in new issue
Block a user