mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-16 03:31:44 +01:00
feat(ci): let docker.yml copy the published Runner image, behind a repository variable (#21340)
## 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. `master` publishes it alone as an attested image, once for each set of its inputs > - Since #21332 the application image takes its Runner only from the `runner-artifacts` stage, and a build can replace that stage with the published image > - No workflow does that yet, so every application image still builds its own Runner, and nothing on an application image says which Runner it has > - A build that copies the published Runner must also build the lockfile that Runner was built from. The workflow refreshes the lockfile before every build, and the server build then refuses the published Runner > - This pull request lets `docker.yml` copy the published Runner image and label the application image with it, behind a repository variable that is off, and makes that build use the committed lockfile > - The benefit is one Runner for all images of the same inputs, named on the image, with a switch that goes back to today's builds without a revert ## Linked Issues or Issue Description Refs #21204, #21229, #21230 (the Runner image), #21306 (the resolver), #21307 (the report-only job), #21308 (the server reads a pack from its Runner image), and #21331, #21332, #21333 (the application image takes its Runner from `runner-artifacts`). No issue exists for this change. **Problem or motivation** `docker.yml` builds the application image on `master` and on tags. Each build makes its own Runner. The report-only job that runs the resolver on `master` feeds no build. Downstream image composers cannot tell from an application image which Runner it has. There is a second problem, which only shows when a build copies the published Runner. The Runner's build stamp covers the whole `pnpm-lock.yaml`. The step that vendors the Runner into the server fails when the stamp does not match the tree. `docker.yml` refreshes `pnpm-lock.yaml` on the runner before every build. The refresh rewrites the file whenever the manifest of any package is ahead of it, also a package the Runner does not read. On the tree of this pull request it rewrites the file even for a pristine checkout: the registry changed the deprecation text of one package. The published Runner was built from the committed file, so the image build would fail. **Proposed solution** One job resolves the Runner once for the run. Both architecture builds need it and add its answer to their build: a build context that replaces the `runner-artifacts` stage, two labels, and the build argument with which the build checks the Runner. A build that copies the published Runner does not refresh the lockfile: it builds the committed tree, the tree the Runner was published for. The job runs only when the repository variable `RUNNER_IMAGE_CONSUME_ENABLED` is exactly `true`. This pull request merges with the variable unset, so no image changes when it merges. **Alternatives considered** - Resolve in each architecture build. The two builds could then disagree, and one image index would hold two Runners. - Write the labels in the `Dockerfile`. A `LABEL` cannot be left out for an inline build. - For the lockfile, copy the Runner image's `/pnpm-lock.yaml` over `/app/pnpm-lock.yaml` in the `build` stage. Nothing after that step reads the file: the two vendor checks are its only readers in `build`, `production` copies it and takes `node_modules` from `deps`, both `cloud-*` stages install with `--ignore-workspace --no-lockfile`, and the server reads only a plugin's own lockfile and the pack's own lockfile at run time. But the image would then ship a lockfile that its `node_modules` did not come from, the copy changes that file's layer for every inline build, and each `Dockerfile` edit makes a new Runner image. - For the lockfile, bind-mount the Runner image's lockfile over the file for the two steps that run the vendor check. This also edits the `Dockerfile`, and it makes the lockfile part of the check always true for a published Runner. - For the lockfile, let the resolver refresh and compare. The answer would depend on the registry at two different moments. - Skipping the refresh needs no `Dockerfile` edit, keeps the stamp check as strict as it is, and builds exactly the tree the inputs digest was computed from. **Roadmap alignment** This is build infrastructure. It adds no product feature and does not overlap an item in `ROADMAP.md`. This pull request is built on `runner/app-image-consume`. Merge in this order: 1. #21331, #21332, #21333: the application image takes its Runner from the `runner-artifacts` stage, checks the inputs digest a build names, and stops early on a stale lockfile. 2. `runner/app-image-consume`: the wait and the `unsupported` answer of the resolver. 3. This pull request. The same change for the preview cloud image build in `release.yml` is deferred. It has no pull request yet. ## What Changed - `.github/workflows/docker.yml`: the job `runner_image` replaces `runner_image_report`. - It runs only when `vars.RUNNER_IMAGE_CONSUME_ENABLED == 'true'`, in this repository. A fork never runs it. - Steps: `inputs` with no credential; `resolve`; then `gh attestation verify` of the full index against the signer `runner-image.yml` on `refs/heads/master`. - For a `master` push, `resolve` runs with `--wait` and the job token. For a tag or a manual run it does not wait and receives no token. - Only the verification step writes the job's outputs. An image that does not verify fails that step with a warning and writes no output. The job is `continue-on-error`: the job is red, the run is not, and the builds are inline. - Permissions: `contents: read`, `actions: read`, `attestations: read`. No registry login, no write. - Limits: 5 minutes for `inputs`, 55 for the lookup, 5 for the verification, 70 for the job. The wait of 40 minutes ends inside them. - `build-and-push` needs `runner_image` and adds its outputs to the build: `build-contexts`, one more line of `build-args` (`PAPERCLIP_RUNNER_EXPECT_INPUTS_DIGEST`), two more lines of `labels`. With empty outputs these are the values the build had before. - The step "Refresh lockfile for Docker build context" runs only when the answer is not `published`. - The step that looks for a merge-queue image of the commit runs only when the answer is not `published`. The two steps after it already depend on its result. - Labels on an image that copied the published Runner: `io.paperclip.runner.image=ghcr.io/paperclipai/paperclip-runner@sha256:<full index digest>` and `io.paperclip.runner.inputs-digest=<digest>`. An image without them made its own Runner. - The `Dockerfile` does not change. The Runner image digest does not move. - Tests that pin lines this changes follow: `scripts/merge-group-image.test.mjs` (the condition of the merge-queue lookup), `scripts/reuse-canary-image.test.mjs` (the `needs` of the build job), and `docker-build-stamp.test.ts` (no workflow names a build context; `docker.yml` now names exactly one). - `server/src/__tests__/docker-runner-workflows.test.ts`: the report-only tests give way to tests of the new job. - `server/scripts/prepare-runner-vendor.test.mjs`: one fixture test of the lockfile case. - `doc/runner-image-contract.md` and `doc/DOCKER.md`: how an application image gets its Runner, the labels and what their absence means, the variable, the wait, the verification, the lockfile rule, the merge-queue rule and the rollback. ## Verification ### Real builds `docker buildx build --target build --platform linux/arm64 --output type=cacheonly`, with a `docker-container` builder made for this test. The Runner image is the publication form (`PAPERCLIP_RUNNER_IMAGE_PUBLICATION=1`, `--target runner-artifacts`) built from a clean export of this branch, exported as an OCI layout: inputs `c4f9d089…34f0`, image `sha256:bef7e9cb…ffef`. The application builds receive `--build-context runner-artifacts=oci-layout://…@sha256:bef7e9cb…` and `PAPERCLIP_RUNNER_EXPECT_INPUTS_DIGEST=c4f9d089…`. The refresh command is the one in the workflow, run with pnpm 9.15.4 in the export: `pnpm install --resolution-only --ignore-scripts --no-frozen-lockfile`. | Build context | Result | | --- | --- | | The committed tree | Passes in 78 s. Both vendor checks: `reusing the current Runner build (inputs unchanged …; 1333 files and 1860 outputs checked)` | | `ui/package.json`: `clsx` `^2.1.1` → `^2.1.0`, then the refresh command (what the workflow did before this change) | Fails at `RUN node server/scripts/prepare-runner-vendor.mjs`: `PAPERCLIP_RUNNER_VENDOR_REQUIRE_CURRENT=1 forbids the Runner rebuild this step needs (inputs changed since the recorded build; 1333 files checked)` | | The committed tree, then only the refresh command | Fails the same way. The refresh changed only the `deprecated` text of one package | | The same `ui/package.json` change with no refresh (what the workflow does now for a `published` answer) | Passes in 66 s. `deps` resolves the manifest inside the image; both vendor checks reuse the Runner | | One line added to `packages/paperclip-runner/src/index.ts` | Fails at the vendor step, as before: a Runner of other inputs is still refused | Lockfile behind the Runner's own manifests (`packages/paperclip-runner/package.json`: `smol-toml` `^1.9.1` → `^1.9.0`), no build context: | Step | Result | | --- | --- | | `runner-image-resolve.mjs inputs`, then `resolve` | `lock: behind`, no digest; `inline (lock-behind)` | | Build without the refresh | Fails in 4 s at the `runner-lockfile` stage: `ERROR: pnpm-lock.yaml is behind the manifests the Runner is installed from …` | | Build after the refresh command (what the workflow does for an `inline` answer) | Passes in 193 s: the `runner-lockfile` stage passes, the build makes its own Runner with its pack, and both vendor checks reuse it | ### Tests macOS (Node 26.12.0) and Linux (`node:24.22.3-bookworm`, linux/arm64, with `jq` and `zstd` added), on this branch: - `pnpm exec vitest run` on `docker-runner-workflows`, `runner-image-resolve`, `runner-image-workflow`, `docker-build-stamp`, `container-init-reaping`, `cloud-image-bundled-plugins`, `docker-image-layer-reuse`, `cloud-image-sentry`, `runner-lockfile-guards` and `runner-image-identity` in `server/src/__tests__`, and `server/scripts/prepare-runner-vendor.test.mjs`: 225 tests in 11 files pass on Linux; on macOS 224 pass and 1 is skipped (it needs bash 4.4). - `node --test .github/scripts/tests/*.test.mjs scripts/merge-group-image.test.mjs scripts/reuse-canary-image.test.mjs scripts/cloud-source-verification.test.mjs scripts/standard-image-contract.test.mjs scripts/preview-artifacts.test.mjs scripts/__tests__/release-verify-workflow.test.mjs scripts/__tests__/release-dry-run-notes.test.mjs`: 991 of 991 pass on both. - The changed test files typecheck with the options of `server/src/__tests__/tsconfig.json`. What the workflow tests hold: - Variable off: the job's condition is the variable and the repository, with no alternative. With empty outputs, the build step has exactly the 3 build arguments, 0 build contexts and 1 label entry it had before, and the refresh step runs. - Published: both architecture builds are one job that reads only the outputs of `runner_image`, with no architecture in those lines. - The verification step runs as real shell against a stub `gh`. When `gh` succeeds it writes the context, the labels and the build argument. When `gh` fails the step exits 1, writes no output and prints the warning. The step has no `continue-on-error`; the job has. The condition of the build job does not name the resolver job and has no `success()`. - The lookup step runs as real shell against a stub `node`. It passes `--wait` only when the event is a `master` push. - Credentials: only the lookup and the verification steps have a token. The steps that build have no `env`. - The refresh step has the condition `needs.runner_image.outputs.mode != 'published'`, and it is the only `pnpm install` of the build job. - The fixture test gives the vendor step a Runner that another tree built for the committed lockfile. The step reuses it. After a change of one specifier of another package in the lockfile the step fails and names the lockfile. With the committed lockfile back it reuses the Runner again. - The merge-queue workflow and the pull-request check do not name the resolver, the variable, a build context or a Runner label. Read-only checks against the real services: - `gh attestation verify oci://ghcr.io/paperclipai/paperclip-runner@sha256:0cd8250b…1bf7 --repo paperclipai/paperclip --signer-workflow paperclipai/paperclip/.github/workflows/runner-image.yml --source-ref refs/heads/master`: exit 0 for the full index, and exit 0 for the slim index `sha256:69ab2001…69b3`. - The same command with `--signer-workflow …/docker.yml`: exit 1 for both. With `--source-ref refs/heads/not-master`: exit 1. With `--repo cli/cli`: exit 1. For a digest that does not exist: exit 1. With no token: exit 4. - The parsed YAML of `docker.yml` differs from its base only in the resolver job, the `needs` of the build job, the conditions of the refresh step and of the merge-queue lookup, and the three build inputs. Never run: - `docker.yml`. Only GitHub can run it, and it has no pull-request trigger. - A build with the variable on. The first one is the first run after a maintainer sets the variable. - A build that pulls the published Runner from the registry as `docker-image://`. The real builds used the same image form from a local OCI layout. - An `amd64` build. - The `production` and `cloud` targets. The real builds stopped at `build`, the last stage that checks the Runner. ## Risks - With the variable on, an application build on `master` starts after the resolver job. That is 2 to 3 minutes when the image exists, and up to 40 minutes from the push when the commit's own Runner publication is in progress. `docker.yml` holds one concurrency slot for each ref, so a long wait can make more `master` commits lose their image build to a newer push. - A build that copies the published Runner ships the committed `pnpm-lock.yaml` in `/app`, while `deps` resolves newer manifests of other packages inside the image. A local `docker build` has always done this; a CI image did not. Nothing in the image reads that file. - Any other build that gives the `Dockerfile` a published Runner and a refreshed lockfile fails at the vendor step. That is the intended answer to a tree the Runner was not built for, and the message names the lockfile. - The pack of an image that copied the published Runner names the commit that published the Runner (`runnerSourceRevision`), which can be older than the commit of the image. A consumer that compares the two must accept that before the variable is set. - A failed verification makes the resolver job red on a green run. That is on purpose: it means a published tag whose attestation does not verify. - `scripts/merge-group-image.mjs` refuses to promote a merge-queue image for a push that changes `docker.yml`. The push that lands this change is such a push. The merge queue is not enabled. - With the variable off there is no report of the resolver on `master` any more: the job that replaced the report-only job does not run. - Rollback: set the variable to another value or delete it. The next run builds inline, with the refresh. Images that exist do not change. > 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, used through Claude Code with tool use (shell, file edits, local Docker builds, read-only calls to the GitHub API and the container registry). ## 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 - [x] All Paperclip CI gates are green - [x] 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>
This commit is contained in:
1 parent
055a0a3c54
commit
647641a99b
8 files changed
+425
-54
No files matched your search
@@ -33,14 +33,21 @@ concurrency:
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
runner_image_report:
|
||||
name: Report the Runner image of this commit
|
||||
if: github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
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'
|
||||
continue-on-error: true
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 8
|
||||
timeout-minutes: 70
|
||||
permissions:
|
||||
contents: read
|
||||
actions: read
|
||||
attestations: read
|
||||
outputs:
|
||||
mode: ${{ steps.verify.outputs.mode || 'inline' }}
|
||||
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
|
||||
@@ -70,12 +77,48 @@ jobs:
|
||||
timeout-minutes: 5
|
||||
run: node scripts/runner-image-resolve.mjs inputs --dir "$RUNNER_TEMP/runner-image-resolve"
|
||||
|
||||
- name: Report the Runner an image build would use
|
||||
timeout-minutes: 2
|
||||
- name: Find the published Runner image of these inputs
|
||||
id: resolve
|
||||
timeout-minutes: 55
|
||||
env:
|
||||
WAIT: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
|
||||
GITHUB_TOKEN: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && github.token || '' }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
node scripts/runner-image-resolve.mjs resolve --dir "$RUNNER_TEMP/runner-image-resolve"
|
||||
echo "Report only: no build read this result." >> "$GITHUB_STEP_SUMMARY"
|
||||
if [ "$WAIT" = true ]; then
|
||||
node scripts/runner-image-resolve.mjs resolve --dir "$RUNNER_TEMP/runner-image-resolve" --wait
|
||||
else
|
||||
node scripts/runner-image-resolve.mjs resolve --dir "$RUNNER_TEMP/runner-image-resolve"
|
||||
fi
|
||||
|
||||
- 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 }}
|
||||
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."
|
||||
echo "The attestation of \`$IMAGE\` did not verify: the image build makes its own Runner." >> "$GITHUB_STEP_SUMMARY"
|
||||
exit 1
|
||||
fi
|
||||
{
|
||||
echo "mode=published"
|
||||
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"
|
||||
echo "The attestation of \`$IMAGE\` verified: the image build copies this Runner." >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
source_verification:
|
||||
name: Watch exact-source verification
|
||||
@@ -153,7 +196,7 @@ jobs:
|
||||
# digest; `merge` assembles the manifest list. Both architectures remain
|
||||
# available to self-hosted installations and downstream image composers.
|
||||
build-and-push:
|
||||
needs: [reuse_canary_image]
|
||||
needs: [reuse_canary_image, runner_image]
|
||||
if: ${{ !cancelled() && (needs.reuse_canary_image.result == 'skipped' || (needs.reuse_canary_image.result == 'success' && needs.reuse_canary_image.outputs.reused == 'false')) }}
|
||||
strategy:
|
||||
# Independent legs: one architecture failing should still publish
|
||||
@@ -235,6 +278,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
|
||||
@@ -286,7 +330,7 @@ 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 instead of rebuilding. scripts/merge-group-image.mjs
|
||||
# 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
|
||||
@@ -294,7 +338,7 @@ jobs:
|
||||
# before. The probe below and the exact-source gate apply either way.
|
||||
- name: Find the merge-queue build of this commit
|
||||
id: find
|
||||
if: github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
if: needs.runner_image.outputs.mode != 'published' && 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 }}
|
||||
@@ -413,6 +457,8 @@ jobs:
|
||||
PAPERCLIP_BUILD_VERSION=${{ steps.build-version.outputs.version }}
|
||||
PAPERCLIP_BUILD_COMMIT=${{ github.sha }}
|
||||
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 }}
|
||||
# By digest, not by tag: two runners cannot each push the same tag
|
||||
# and end up with a manifest list. Each leg publishes an untagged
|
||||
@@ -428,7 +474,9 @@ jobs:
|
||||
# have each leg overwrite the other's cache on every build.
|
||||
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache-${{ matrix.arch }}
|
||||
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache-${{ matrix.arch }},mode=max
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
labels: |
|
||||
${{ steps.meta.outputs.labels }}
|
||||
${{ needs.runner_image.outputs.labels }}
|
||||
|
||||
# Exactly one of the two paths produced this leg's digest.
|
||||
- name: Select image digest
|
||||
|
||||
+26
-1
@@ -92,7 +92,9 @@ identity rules and how to consume the image.
|
||||
|
||||
The application image takes its Runner from the `runner-artifacts` stage. It
|
||||
has no Runner build of its own, no Rust toolchain and no C compiler. Every
|
||||
build of the `production` or `cloud` target builds that stage itself, once:
|
||||
build of the `production` or `cloud` target builds that stage itself, once,
|
||||
unless it is given a published Runner image in its place (see "The Runner of
|
||||
the application image" below):
|
||||
|
||||
- The `build` stage copies the Runner's build output and its build stamp into
|
||||
`packages/paperclip-runner`. It sets `PAPERCLIP_RUNNER_VENDOR_REQUIRE_CURRENT=1`,
|
||||
@@ -128,6 +130,29 @@ lockfile in the checkout, then build again. Do not commit the result (see
|
||||
pnpm install --resolution-only --ignore-scripts --no-frozen-lockfile
|
||||
```
|
||||
|
||||
### The Runner of the application image
|
||||
|
||||
An application image either makes its own Runner in its build (inline) or
|
||||
copies the published Runner image of the same inputs. A local build, a fork,
|
||||
a pull request and the merge-queue build are always inline.
|
||||
`.github/workflows/docker.yml` in this repository copies the published image
|
||||
when the repository variable `RUNNER_IMAGE_CONSUME_ENABLED` is exactly `true`
|
||||
and the image of the commit's inputs is published and its attestation
|
||||
verifies. On a `master` push it waits for the commit's own run of
|
||||
`runner-image.yml`, at most 40 minutes from the push. In every other case the
|
||||
build is inline, with a notice: no state of the Runner image fails an
|
||||
application image build. A build that copies the published image builds the
|
||||
committed `pnpm-lock.yaml`: the workflow does not refresh it first, and the
|
||||
`deps` stage resolves the other packages' manifests inside the image.
|
||||
|
||||
An image that copied the published Runner has the labels
|
||||
`io.paperclip.runner.image` (`ghcr.io/paperclipai/paperclip-runner@sha256:<digest>`)
|
||||
and `io.paperclip.runner.inputs-digest`. An image without them made its own
|
||||
Runner and is as complete. To go back to inline builds everywhere, set the
|
||||
variable to another value or delete it; nothing needs a revert. See "The
|
||||
Runner of the application image" in
|
||||
[`doc/runner-image-contract.md`](runner-image-contract.md).
|
||||
|
||||
`.github/workflows/docker.yml` builds the application image on `master` and on
|
||||
tags only. `.github/workflows/docker-app-check.yml` builds the `build` and
|
||||
`runner-provider-pack` stages on a pull request that changes the `Dockerfile`,
|
||||
|
||||
+102
-12
@@ -4,7 +4,8 @@ The Runner image is the Runner built alone, as a plain file tree with no
|
||||
entrypoint and no operating system. An image build copies paths out of it
|
||||
instead of compiling the Runner again. The application image of this
|
||||
repository takes its Runner from the stage that builds it (see "The
|
||||
application image"); no build reads the published image yet. Its name is
|
||||
application image"), or copies the published image when a repository variable
|
||||
allows it (see "The Runner of the application image"). Its name is
|
||||
`ghcr.io/paperclipai/paperclip-runner`, and one build makes two variants:
|
||||
|
||||
- full, the `runner-artifacts` target of the `Dockerfile`: every path below;
|
||||
@@ -180,9 +181,10 @@ The `production` and `cloud` targets of the `Dockerfile` read only the
|
||||
`COPY --from=runner-provider-pack /provider-pack-transport/ /opt/paperclip-runner/`
|
||||
in the image history (`retained-provider-pack-oci.ts`). Do not change it.
|
||||
|
||||
No workflow replaces the stage yet, so every application image build runs
|
||||
the Runner stages itself: an inline Runner. An inline Runner is not this
|
||||
image, and an application image says so in three ways:
|
||||
Unless a workflow replaces the stage (see "The Runner of the application
|
||||
image"), an application image build runs the Runner stages itself: an inline
|
||||
Runner. An inline Runner is not this image, and an application image says so
|
||||
in three ways:
|
||||
|
||||
- its pack names the build commit of the application image as
|
||||
`payload.runnerSourceRevision`, the value of `PAPERCLIP_BUILD_COMMIT`;
|
||||
@@ -192,8 +194,9 @@ image, and an application image says so in three ways:
|
||||
A build without `PAPERCLIP_BUILD_COMMIT` has no pack, as before.
|
||||
|
||||
`build` also declares the build argument
|
||||
`PAPERCLIP_RUNNER_EXPECT_INPUTS_DIGEST`, which no build sets yet. It is for
|
||||
a build that replaces the stage with a published image. When the argument is
|
||||
`PAPERCLIP_RUNNER_EXPECT_INPUTS_DIGEST`. It is for a build that replaces the
|
||||
stage with a published image, and `docker.yml` sets it together with the
|
||||
build context. When the argument is
|
||||
set, `scripts/check-runner-image-expectation.mjs` reads `/runner-image.json`
|
||||
of the `runner-artifacts` the build was given, and the build fails unless
|
||||
that file has `publication: true` and names exactly those inputs. An inline
|
||||
@@ -203,12 +206,11 @@ The check runs before the server build vendors the Runner.
|
||||
### Choosing the Runner for an image build
|
||||
|
||||
`scripts/runner-image-resolve.mjs` decides whether a build of a checkout can
|
||||
copy the published image. No build uses its answer yet: on a `master` push,
|
||||
the `runner_image_report` job of `.github/workflows/docker.yml` runs it and
|
||||
writes the answer to the job summary, and nothing reads that job. The job
|
||||
runs on the committed files, holds no credential (the Runner package is
|
||||
public, so the lookup is anonymous) and cannot fail the run. The script has
|
||||
two commands, so that the one that builds reads no registry credential:
|
||||
copy the published image. The `runner_image` job of
|
||||
`.github/workflows/docker.yml` runs it for the application image; see "The
|
||||
Runner of the application image". The Runner package is public, so the lookup
|
||||
needs no credential. The script has two commands, so that the one that builds
|
||||
reads no credential:
|
||||
|
||||
```sh
|
||||
node scripts/runner-image-resolve.mjs inputs --dir "$dir"
|
||||
@@ -276,6 +278,94 @@ no wait.
|
||||
last time. Without an image the answer is `inline`, with the reason of that
|
||||
lookup and what the wait saw.
|
||||
|
||||
### The Runner of the application image
|
||||
|
||||
The application image, `ghcr.io/paperclipai/paperclip`, gets its Runner in one
|
||||
of two ways. The recipe is the same in both, so the Runner behaves the same.
|
||||
|
||||
- **Inline.** The image build runs the `runner-artifacts` stage itself.
|
||||
- **Published.** The build receives
|
||||
`--build-context runner-artifacts=docker-image://ghcr.io/paperclipai/paperclip-runner@sha256:<full index digest>`.
|
||||
The stage is then not built, and the image copies the published Runner.
|
||||
|
||||
Only `.github/workflows/docker.yml` in this repository can choose
|
||||
"published". A local `docker build`, a fork, the pull-request check
|
||||
(`docker-app-check.yml`) and the merge-queue build
|
||||
(`docker-merge-group.yml`) are always inline.
|
||||
|
||||
**Labels.** An image that copied the published Runner has two labels, on the
|
||||
image of each platform:
|
||||
|
||||
| Label | Value |
|
||||
| --- | --- |
|
||||
| `io.paperclip.runner.image` | `ghcr.io/paperclipai/paperclip-runner@sha256:<full index digest>` |
|
||||
| `io.paperclip.runner.inputs-digest` | The inputs digest of that Runner image. |
|
||||
|
||||
The workflow writes them, not the `Dockerfile`, and only together with the
|
||||
build context. An image without them made its own Runner. Nothing else
|
||||
follows from their absence: such an image is complete and supported. Its pack
|
||||
has no `payload.runnerInputsDigest`, and the pack's `runnerSourceRevision` is
|
||||
the commit of the image. In an image with the labels, `runnerSourceRevision`
|
||||
is the commit that published the Runner image, which can be older than the
|
||||
commit of the application image.
|
||||
|
||||
**The variable.** The repository variable `RUNNER_IMAGE_CONSUME_ENABLED`
|
||||
turns this on. Only the exact value `true` does. With any other value, or no
|
||||
variable, the `runner_image` job does not run and every build is inline, as
|
||||
before the job existed.
|
||||
|
||||
**The job.** `runner_image` runs once for a workflow run, and both
|
||||
architecture builds need it, so both always get the same answer.
|
||||
|
||||
1. `inputs`, on the committed files, with no credential.
|
||||
2. `resolve`. For a `master` push it runs with `--wait` and a token that can
|
||||
read workflow runs. For a tag or a manual run it does not wait: no run of
|
||||
`runner-image.yml` belongs to that event.
|
||||
3. For a `published` answer, the job verifies the attestation of the full
|
||||
index, with the command under "Create-only". Only this step writes the
|
||||
outputs of the job, so no build receives a digest that did not verify. An
|
||||
image that does not verify fails this step with a warning. The job is then
|
||||
red, the run is not, and the builds are inline.
|
||||
4. The builds add the outputs to their own values: the build context, the two
|
||||
labels and the build argument `PAPERCLIP_RUNNER_EXPECT_INPUTS_DIGEST`. With
|
||||
empty outputs a build has exactly the arguments, contexts and labels it
|
||||
had without the job.
|
||||
|
||||
The job holds no registry credential and cannot write anything. It cannot
|
||||
fail the run or stop a build: every failure, a timeout included, leaves the
|
||||
outputs empty and the builds inline. The 40 minutes of the wait end inside
|
||||
the limit of its step (55 minutes) and of the job (70 minutes), so the script
|
||||
ends the wait, with a notice, before the workflow would stop it.
|
||||
|
||||
**The check in the build.** With the build argument, the build fails unless
|
||||
its `runner-artifacts` is the publication of those inputs (see "The
|
||||
application image"). A wrong or missing build context then fails the build,
|
||||
and no image carries labels for a Runner it does not have. The resolver
|
||||
answers `unsupported` for a `Dockerfile` that does not declare the argument.
|
||||
|
||||
**The lockfile.** The published Runner was built from the committed
|
||||
`pnpm-lock.yaml`, and its build stamp covers that whole file. A build that
|
||||
copies it must therefore build the committed lockfile. `docker.yml` refreshes
|
||||
the lockfile on the runner before an inline build, because the inline Runner
|
||||
stages install frozen. It does not refresh it when the answer is `published`:
|
||||
a refresh rewrites the file whenever the manifest of any package is ahead of
|
||||
it, also a package the Runner does not read, and the server build would then
|
||||
refuse the published Runner as built from other inputs. The resolver answers
|
||||
`published` only when the committed lockfile matches the Runner's own
|
||||
manifests, so the `runner-lockfile` stage passes, and the `deps` stage
|
||||
resolves the manifests of the other packages inside the image, as it does for
|
||||
a local `docker build`. A build that is given a published Runner and a
|
||||
refreshed lockfile fails at the step that vendors the Runner.
|
||||
|
||||
**Merge-queue images.** `docker.yml` can push the image that the merge queue
|
||||
built for a commit instead of building it. That image made its own Runner. A
|
||||
run whose `runner_image` job answered `published` does not look for it and
|
||||
builds from source, so one commit never has both kinds.
|
||||
|
||||
**Rollback.** Set `RUNNER_IMAGE_CONSUME_ENABLED` to another value, or delete
|
||||
it. The next run of `docker.yml` builds inline. No revert is needed, and
|
||||
images that exist do not change.
|
||||
|
||||
## Publication
|
||||
|
||||
`.github/workflows/runner-image.yml` publishes on a `master` push in this
|
||||
|
||||
@@ -179,7 +179,7 @@ test("master promotes only after proof and otherwise builds exactly as before",
|
||||
const step = name => { const found = steps.find(item => item.startsWith(` - name: ${name}\n`)); assert.ok(found, name); return found; };
|
||||
const order = name => steps.indexOf(step(name));
|
||||
assert.match(step("Find the merge-queue build of this commit"),
|
||||
/if: github.repository == 'paperclipai\/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs\/heads\/master'/);
|
||||
/if: needs.runner_image.outputs.mode != 'published' && github.repository == 'paperclipai\/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs\/heads\/master'/);
|
||||
for (const name of ["Find the merge-queue build of this commit", "Download the merge-queue image", "Promote the merge-queue image"]) {
|
||||
assert.match(step(name), /continue-on-error: true/, `${name} must fall back to the build`);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ test("canary reuse gates both native builds and still runs convergent promotion"
|
||||
assert.match(reuse, /github.repository_id == '1170821064'.*startsWith\(github.ref, 'refs\/tags\/canary\/v'\)/);
|
||||
assert.match(reuse, /node scripts\/reuse-canary-image.mjs/);
|
||||
const build = workflow.split(" build-and-push:\n")[1].split(" merge-and-push:\n")[0];
|
||||
assert.match(build, /needs: \[reuse_canary_image\]/);
|
||||
assert.match(build, /needs: \[reuse_canary_image, runner_image\]/);
|
||||
assert.match(build, /!cancelled\(\).*result == 'skipped'.*result == 'success'.*outputs.reused == 'false'/);
|
||||
assert.match(build, /platform: linux\/amd64/);
|
||||
assert.match(build, /platform: linux\/arm64/);
|
||||
|
||||
@@ -313,6 +313,47 @@ describe("prepareRunnerVendor", () => {
|
||||
expect(readBuildInputsStamp(stampPath)).not.toBeNull();
|
||||
});
|
||||
|
||||
it("with PAPERCLIP_RUNNER_VENDOR_REQUIRE_CURRENT=1, accepts a Runner built elsewhere for the committed lockfile and refuses it once the lockfile is refreshed for another package", () => {
|
||||
const committed = [
|
||||
"lockfileVersion: '9.0'",
|
||||
"importers:",
|
||||
" packages/paperclip-runner:",
|
||||
" dependencies:",
|
||||
" ajv: { specifier: ^8.20.0, version: 8.20.0 }",
|
||||
" ui:",
|
||||
" dependencies:",
|
||||
" react: { specifier: ^19.2.7, version: 19.2.8 }",
|
||||
"",
|
||||
].join("\n");
|
||||
const built = makeRepo();
|
||||
writeFileSync(path.join(built.repoRoot, "pnpm-lock.yaml"), committed);
|
||||
recordCurrentBuild(built);
|
||||
|
||||
const { repoRoot, packageRoot } = makeRepo();
|
||||
writeFileSync(path.join(repoRoot, "pnpm-lock.yaml"), committed);
|
||||
writeTree(repoRoot, {
|
||||
"packages/paperclip-runner/node_modules/.cache/paperclip-runner-build-inputs.json": readFileSync(buildInputsStampPath(built.packageRoot), "utf8"),
|
||||
});
|
||||
const env = { [REQUIRE_CURRENT_VARIABLE]: "1" };
|
||||
let runs = 0;
|
||||
const prepare = (lines) => prepareRunnerVendor({ repoRoot, env, run: () => { runs += 1; return 0; }, log: (line) => lines.push(line) });
|
||||
|
||||
const reused = [];
|
||||
expect(prepare(reused)).toBe(0);
|
||||
expect(reused[1]).toMatch(/,action:reuse,reason:inputs_unchanged,/);
|
||||
|
||||
writeFileSync(path.join(repoRoot, "pnpm-lock.yaml"), committed.replace("specifier: ^19.2.7", "specifier: ^19.2.8"));
|
||||
const refused = [];
|
||||
expect(prepare(refused)).toBe(1);
|
||||
expect(refused[0]).toContain("pnpm-lock.yaml included");
|
||||
expect(refused[1]).toMatch(/,action:fail,reason:inputs_changed,/);
|
||||
|
||||
writeFileSync(path.join(repoRoot, "pnpm-lock.yaml"), committed);
|
||||
expect(prepare([])).toBe(0);
|
||||
expect(runs).toBe(0);
|
||||
expect(readBuildInputsStamp(buildInputsStampPath(packageRoot))).not.toBeNull();
|
||||
});
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"end to end: the first server build rebuilds the Runner, the second reuses it, a change or a lost output rebuilds again",
|
||||
async () => {
|
||||
|
||||
@@ -175,8 +175,9 @@ 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)/);
|
||||
expect(source, name).not.toMatch(/runner-artifacts|build-contexts?\b/);
|
||||
if (name !== "standard") expect(source, name).not.toMatch(/runner-artifacts|build-contexts?\b/);
|
||||
}
|
||||
expect(workflow.match(/runner-artifacts|build-contexts?\b/g)).toEqual(["runner-artifacts", "build-contexts"]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { RUNNER_IMAGE_WAIT_MINUTES } from "../../../scripts/runner-image-resolve.mjs";
|
||||
|
||||
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
||||
const read = (name: string) => readFileSync(path.join(repoRoot, ".github", "workflows", name), "utf8");
|
||||
@@ -23,40 +26,203 @@ function expectPinnedAndExpressionFree(text: string) {
|
||||
for (const script of shell) expect(script).not.toContain("${{");
|
||||
}
|
||||
|
||||
describe("the report-only Runner image job in docker.yml", () => {
|
||||
const named = (job: string, name: string) => {
|
||||
const found = steps(job).filter((step) => step.startsWith(` - name: ${name}\n`));
|
||||
expect(found, name).toHaveLength(1);
|
||||
return found[0];
|
||||
};
|
||||
const shell = (step: string) => scripts(`${step}\n`)[0].trimEnd();
|
||||
const condition = (text: string, indent: number) => new RegExp(`^ {${indent}}if: (.+)$`, "m").exec(text)?.[1] ?? "";
|
||||
const minutes = (text: string, indent: number) => Number(new RegExp(`^ {${indent}}timeout-minutes: (\\d+)$`, "m").exec(text)![1]);
|
||||
function runStep(step: string, env: Record<string, string>, stubs: Record<string, string>) {
|
||||
const directory = mkdtempSync(path.join(os.tmpdir(), "docker-runner-workflows-"));
|
||||
try {
|
||||
for (const [name, body] of Object.entries(stubs)) writeFileSync(path.join(directory, name), `#!/bin/sh\n${body}\n`, { mode: 0o755 });
|
||||
for (const file of ["output", "summary", "calls"]) writeFileSync(path.join(directory, file), "");
|
||||
const run = spawnSync("bash", ["--noprofile", "--norc", "-eo", "pipefail", "-c", shell(step)], {
|
||||
cwd: directory,
|
||||
encoding: "utf8",
|
||||
env: {
|
||||
PATH: `${directory}${path.delimiter}${process.env.PATH}`, RUNNER_TEMP: directory, CALLS: path.join(directory, "calls"),
|
||||
GITHUB_OUTPUT: path.join(directory, "output"), GITHUB_STEP_SUMMARY: path.join(directory, "summary"), ...env,
|
||||
},
|
||||
});
|
||||
const text = (file: string) => readFileSync(path.join(directory, file), "utf8");
|
||||
return { status: run.status, stdout: run.stdout, stderr: run.stderr, output: text("output"), calls: text("calls").trimEnd().split("\n").filter(Boolean) };
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
function outputs(text: string) {
|
||||
const values: Record<string, string> = {};
|
||||
const lines = text.split("\n");
|
||||
for (let index = 0; index < lines.length; index += 1) {
|
||||
const block = /^([a-z_]+)<<(.+)$/.exec(lines[index]);
|
||||
if (block) {
|
||||
const end = lines.indexOf(block[2], index + 1);
|
||||
values[block[1]] = lines.slice(index + 1, end).join("\n");
|
||||
index = end;
|
||||
} else if (lines[index].includes("=")) {
|
||||
values[lines[index].slice(0, lines[index].indexOf("="))] = lines[index].slice(lines[index].indexOf("=") + 1);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
function listInputs(step: string, source: string, resolved: Record<string, string>) {
|
||||
const rendered = `${step}\n`.replace(new RegExp(`\\$\\{\\{ ${source.replaceAll(".", "\\.")}\\.([a-z_]+) \\}\\}`, "g"), (_match, name: string) =>
|
||||
(resolved[name] ?? "").split("\n").join(`\n${" ".repeat(12)}`));
|
||||
const list = (input: string) => {
|
||||
const found = new RegExp(`^ {10}${input}: (?:\\|\\n((?: {12}.*\\n)+)|(.*)\\n)`, "m").exec(rendered);
|
||||
return (found?.[1] ?? found?.[2] ?? "").split("\n").map((line) => line.trim()).filter(Boolean);
|
||||
};
|
||||
return { buildArgs: list("build-args"), buildContexts: list("build-contexts"), labels: list("labels") };
|
||||
}
|
||||
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 canonical = "github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064'";
|
||||
const VERIFY = "Verify the attestation of the Runner image";
|
||||
|
||||
describe("the Runner image an application image build copies in docker.yml", () => {
|
||||
const workflow = read("docker.yml");
|
||||
const jobs = jobsOf(workflow);
|
||||
const report = jobs.runner_image_report;
|
||||
const resolver = jobs.runner_image;
|
||||
const legs = jobs["build-and-push"];
|
||||
const masterPush = "github.event_name == 'push' && github.ref == 'refs/heads/master'";
|
||||
const buildInputs = (resolved: Record<string, string>) => listInputs(named(legs, "Build and push by digest"), "needs.runner_image.outputs", resolved);
|
||||
const inlineBuild = {
|
||||
buildArgs: [
|
||||
"PAPERCLIP_BUILD_VERSION=${{ steps.build-version.outputs.version }}",
|
||||
"PAPERCLIP_BUILD_COMMIT=${{ github.sha }}",
|
||||
"CLI_TOOLS_CACHE_EPOCH=${{ steps.tools-epoch.outputs.epoch }}",
|
||||
],
|
||||
buildContexts: [],
|
||||
labels: ["${{ steps.meta.outputs.labels }}"],
|
||||
};
|
||||
|
||||
it("holds no credential, can only read the repository, and cannot write to a registry or sign", () => {
|
||||
it("runs only when the repository variable has the enabling value, in the canonical repository, and not otherwise", () => {
|
||||
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/);
|
||||
}
|
||||
});
|
||||
|
||||
it("gives a build with no answer exactly the build arguments, contexts and labels it had before", () => {
|
||||
expect(buildInputs({})).toEqual(inlineBuild);
|
||||
expect(buildInputs({ mode: "inline" })).toEqual(inlineBuild);
|
||||
});
|
||||
|
||||
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}`)));
|
||||
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],
|
||||
buildContexts: [`runner-artifacts=docker-image://${IMAGE}`],
|
||||
labels: [...inlineBuild.labels, ...LABELS.split("\n")],
|
||||
});
|
||||
});
|
||||
|
||||
it("hands a build only what the attestation step wrote, and that step fails and writes nothing for an image that does not verify", () => {
|
||||
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' }}",
|
||||
"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(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 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(verified.calls).toEqual([
|
||||
`attestation verify oci://${IMAGE} --repo paperclipai/paperclip --signer-workflow paperclipai/paperclip/.github/workflows/runner-image.yml --source-ref refs/heads/master`,
|
||||
]);
|
||||
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.calls).toHaveLength(1);
|
||||
expect(refused.output).toBe("");
|
||||
expect(refused.stdout).toContain("::warning title=Runner image not verified::");
|
||||
}
|
||||
expect(verify).not.toMatch(/continue-on-error/);
|
||||
expect(resolver).toContain("\n continue-on-error: true\n");
|
||||
expect(condition(legs, 4)).not.toMatch(/runner_image|success\(\)/);
|
||||
});
|
||||
|
||||
it("builds the committed lockfile when it copies the published Runner, and refreshes it for every other build", () => {
|
||||
const refresh = named(legs, "Refresh lockfile for Docker build context");
|
||||
expect(condition(refresh, 8)).toBe("needs.runner_image.outputs.mode != 'published'");
|
||||
expect(legs.match(/pnpm install/g)).toHaveLength(1);
|
||||
expect(refresh).toContain("pnpm install --resolution-only --ignore-scripts --no-frozen-lockfile");
|
||||
const order = ["Refresh lockfile for Docker build context", "Build and push by digest"].map((name) => steps(legs).indexOf(named(legs, name)));
|
||||
expect(order[0]).toBeLessThan(order[1]);
|
||||
});
|
||||
|
||||
it("waits only for a master push, and gives the token to the lookup only then", () => {
|
||||
const resolve = named(resolver, "Find the published Runner image of these inputs");
|
||||
expect(resolve).toContain("\n id: resolve\n");
|
||||
expect(resolve).toContain(` WAIT: \${{ ${masterPush} }}\n`);
|
||||
expect(resolve).toContain(` GITHUB_TOKEN: \${{ ${masterPush} && github.token || '' }}\n`);
|
||||
const node = { node: `printf '%s\\n' "$*" >> "$CALLS"` };
|
||||
const command = (wait: string) => runStep(resolve, { WAIT: wait }, node).calls;
|
||||
const waiting = command("true");
|
||||
expect(waiting).toHaveLength(1);
|
||||
expect(waiting[0]).toMatch(/^scripts\/runner-image-resolve\.mjs resolve --dir \S+\/runner-image-resolve --wait$/);
|
||||
for (const wait of ["false", ""]) {
|
||||
const once = command(wait);
|
||||
expect(once).toHaveLength(1);
|
||||
expect(once[0]).toMatch(/^scripts\/runner-image-resolve\.mjs resolve --dir \S+\/runner-image-resolve$/);
|
||||
}
|
||||
});
|
||||
|
||||
it("holds no credential where it builds, can write nothing, and reads only what the wait and the verification need", () => {
|
||||
expect(workflow).toMatch(/^permissions: \{\}$/m);
|
||||
expect(permissions(report)).toEqual(["contents: read"]);
|
||||
expect(report).not.toMatch(credential);
|
||||
expect(report).not.toMatch(/github\.actor|REGISTRY_USERNAME/);
|
||||
expect(report).not.toMatch(registryWrite);
|
||||
expect(report).toContain("persist-credentials: false");
|
||||
expectPinnedAndExpressionFree(report);
|
||||
expect(permissions(resolver)).toEqual(["contents: read", "actions: read", "attestations: read"]);
|
||||
expect(resolver.slice(0, resolver.indexOf("\n steps:\n"))).not.toMatch(credential);
|
||||
expect(steps(resolver).filter((step) => credential.test(step)).map((step) => /- name: (.+)/.exec(step)![1])).toEqual([
|
||||
"Find the published Runner image of these inputs",
|
||||
"Verify the attestation of the Runner image",
|
||||
]);
|
||||
const building = steps(resolver).filter((step) => /runner-image-resolve\.mjs inputs|docker buildx|setup-buildx/.test(step));
|
||||
expect(building).toHaveLength(2);
|
||||
for (const step of building) expect(step).not.toMatch(/\n {8}env:\n/);
|
||||
expect(resolver).not.toMatch(/github\.actor|REGISTRY_USERNAME|REGISTRY_PASSWORD/);
|
||||
expect(resolver).not.toMatch(registryWrite);
|
||||
expect(resolver).toContain("persist-credentials: false");
|
||||
expectPinnedAndExpressionFree(resolver);
|
||||
});
|
||||
|
||||
it("bounds the step that builds and the lookup", () => {
|
||||
for (const command of ["runner-image-resolve.mjs inputs", "runner-image-resolve.mjs resolve"]) {
|
||||
const running = steps(report).filter((step) => step.includes(command));
|
||||
expect(running).toHaveLength(1);
|
||||
expect(running[0]).toMatch(/^ {8}timeout-minutes: \d+$/m);
|
||||
it("does not promote a merge-queue image for a commit that copies a published Runner", () => {
|
||||
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}`);
|
||||
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(condition(named(legs, "Build and push by digest"), 8)).toBe("steps.promote.outputs.digest == ''");
|
||||
});
|
||||
|
||||
it("cannot fail the run or feed another job", () => {
|
||||
expect(report).toContain("\n continue-on-error: true\n");
|
||||
expect(report).toMatch(/^ {4}timeout-minutes: \d+$/m);
|
||||
expect(report).not.toMatch(/^ {4}(?:needs|outputs):/m);
|
||||
expect(workflow).not.toContain("needs.runner_image_report");
|
||||
for (const [name, job] of Object.entries(jobs)) {
|
||||
if (name !== "runner_image_report") expect(/^ {4}needs: .*$/m.exec(job)?.[0] ?? "").not.toContain("runner_image_report");
|
||||
}
|
||||
expect(/^ {4}if: (.+)$/m.exec(report)![1]).toBe(
|
||||
"github.repository == 'paperclipai/paperclip' && github.repository_id == '1170821064' && github.event_name == 'push' && github.ref == 'refs/heads/master'",
|
||||
);
|
||||
it("cannot fail or block an image build, and ends its own wait before any time limit of the workflow", () => {
|
||||
expect(resolver).toContain("\n continue-on-error: true\n");
|
||||
expect(condition(legs, 4).startsWith("${{ !cancelled() && ")).toBe(true);
|
||||
expect(condition(legs, 4)).not.toContain("runner_image");
|
||||
const limits = ["Compute the Runner inputs of this commit", "Find the published Runner image of these inputs", "Verify the attestation of the Runner image"]
|
||||
.map((name) => minutes(named(resolver, name), 8));
|
||||
expect(limits[1]).toBeGreaterThanOrEqual(RUNNER_IMAGE_WAIT_MINUTES + 15);
|
||||
expect(minutes(resolver, 4)).toBeGreaterThanOrEqual(limits.reduce((sum, limit) => sum + limit, 0) + 5);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user