9090 - ' helm/sim/ci/default-values.yaml'
9191 - ' .github/sandbox-kubernetes-e2e/**'
9292 - ' .github/actions/image/**'
93+ - ' .github/actions/sandbox-image/**'
9394 - ' .github/actions/attest-image/**'
9495 - ' .github/actions/k3s-*/**'
9596 - ' .github/actions/setup/**'
@@ -230,6 +231,7 @@ jobs:
230231 verification:
231232 - '.github/workflows/sandbox.yml'
232233 - '.github/actions/image/**'
234+ - '.github/actions/sandbox-image/**'
233235 - 'apps/sim/scripts/verify-sandbox-image.ts'
234236 - 'apps/sim/scripts/function-sandbox-parity-manifest.ts'
235237
@@ -407,29 +409,25 @@ jobs:
407409 } >> "$GITHUB_OUTPUT"
408410 cat /tmp/legs.jsonl
409411
410- # One leg per image and architecture, each on a native runner. The image is built
411- # into the local daemon and verified before anything is pushed; the pushed
412- # `<tag>-<arch>` is then signed and attested in the same leg, so a later failure
413- # never leaves a published digest unsigned.
412+ # One leg per image and architecture, each on a native runner, built into the
413+ # local daemon and verified. Every run that does not publish (pull requests, a
414+ # dry-run or e2e dispatch) builds here, with a read-only token: a pull request's
415+ # checkout controls this job's code, and GitHub grants a same-repository pull
416+ # request's token whatever write permissions its job asks for. amd64 builds an
417+ # e2e job needs upload their archive.
414418 image :
415419 name : image (${{ matrix.kind }}, ${{ matrix.arch }})
416420 needs : [plan]
417- if : needs.plan.outputs.legs != '[]'
421+ if : needs.plan.outputs.legs != '[]' && needs.plan.outputs.publish != 'true'
418422 runs-on : ${{ (vars.CI_PROVIDER == '' || vars.CI_PROVIDER == 'blacksmith') && (matrix.arch == 'arm64' && 'blacksmith-4vcpu-ubuntu-2404-arm' || 'blacksmith-4vcpu-ubuntu-2404') || (matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest') }}
419423 timeout-minutes : 45
420424 permissions :
421425 contents : read
422- packages : write
423- id-token : write
424- attestations : write
425- artifact-metadata : write
426426 strategy :
427427 fail-fast : false
428428 matrix :
429429 include : ${{ fromJSON(needs.plan.outputs.legs) }}
430430 env :
431- # Belt and braces with the plan: nothing but a main or staging run pushes.
432- PUBLISH : ${{ needs.plan.outputs.publish == 'true' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging') }}
433431 ARCHIVE : ${{ matrix.arch == 'amd64' && contains(fromJSON(needs.plan.outputs.archives), matrix.kind) }}
434432 ARCH_REF : ${{ matrix.ref }}-${{ matrix.arch }}
435433 steps :
@@ -438,41 +436,13 @@ jobs:
438436 with :
439437 persist-credentials : false
440438
441- - name : Login to Docker Hub
442- if : env.PUBLISH == 'true'
443- uses : docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
444- with :
445- username : ${{ secrets.DOCKERHUB_USERNAME }}
446- password : ${{ secrets.DOCKERHUB_TOKEN }}
447-
448- - name : Login to GHCR
449- if : env.PUBLISH == 'true'
450- uses : docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
451- with :
452- registry : ghcr.io
453- username : ${{ github.repository_owner }}
454- password : ${{ secrets.GITHUB_TOKEN }}
455-
456- - name : Build image
457- uses : ./.github/actions/image
439+ - name : Build and verify image
440+ uses : ./.github/actions/sandbox-image
458441 with :
459442 provider : ${{ vars.CI_PROVIDER }}
460- file : ./docker/sandbox-${{ matrix.kind }}.Dockerfile
461- platforms : linux/${{ matrix.arch }}
462- tags : ${{ env.ARCH_REF }}
463- push : ' false'
464- load : ' true'
465-
466- - name : Setup workspace
467- if : matrix.kind != 'agent'
468- uses : ./.github/actions/setup
469- with :
470- provider : ${{ vars.CI_PROVIDER }}
471- node-version : ' '
472-
473- - name : Verify image contract
474- if : matrix.kind != 'agent'
475- run : bun run apps/sim/scripts/verify-sandbox-image.ts --kind ${{ matrix.kind }} --image "$ARCH_REF"
443+ kind : ${{ matrix.kind }}
444+ arch : ${{ matrix.arch }}
445+ tag : ${{ env.ARCH_REF }}
476446
477447 # Under the reference the app defaults to, which is what pods name in k3s.
478448 - name : Save image
@@ -496,9 +466,62 @@ jobs:
496466 retention-days : 1
497467 compression-level : 1
498468
469+ # The publishing legs: the same build and verification, then the pushed
470+ # `<tag>-<arch>` is signed and attested in the same leg, so a later failure never
471+ # leaves a published digest unsigned. The only job holding registry-write and
472+ # signing permissions besides `publish`, and it never runs for a pull request:
473+ # only for a push to, or a dispatch on, main or staging.
474+ image-publish :
475+ name : image-publish (${{ matrix.kind }}, ${{ matrix.arch }})
476+ needs : [plan]
477+ if : >-
478+ needs.plan.outputs.legs != '[]' &&
479+ needs.plan.outputs.publish == 'true' &&
480+ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
481+ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging')
482+ runs-on : ${{ (vars.CI_PROVIDER == '' || vars.CI_PROVIDER == 'blacksmith') && (matrix.arch == 'arm64' && 'blacksmith-4vcpu-ubuntu-2404-arm' || 'blacksmith-4vcpu-ubuntu-2404') || (matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest') }}
483+ timeout-minutes : 45
484+ permissions :
485+ contents : read
486+ packages : write
487+ id-token : write
488+ attestations : write
489+ artifact-metadata : write
490+ strategy :
491+ fail-fast : false
492+ matrix :
493+ include : ${{ fromJSON(needs.plan.outputs.legs) }}
494+ env :
495+ ARCH_REF : ${{ matrix.ref }}-${{ matrix.arch }}
496+ steps :
497+ - name : Checkout code
498+ uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
499+ with :
500+ persist-credentials : false
501+
502+ - name : Login to Docker Hub
503+ uses : docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
504+ with :
505+ username : ${{ secrets.DOCKERHUB_USERNAME }}
506+ password : ${{ secrets.DOCKERHUB_TOKEN }}
507+
508+ - name : Login to GHCR
509+ uses : docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
510+ with :
511+ registry : ghcr.io
512+ username : ${{ github.repository_owner }}
513+ password : ${{ secrets.GITHUB_TOKEN }}
514+
515+ - name : Build and verify image
516+ uses : ./.github/actions/sandbox-image
517+ with :
518+ provider : ${{ vars.CI_PROVIDER }}
519+ kind : ${{ matrix.kind }}
520+ arch : ${{ matrix.arch }}
521+ tag : ${{ env.ARCH_REF }}
522+
499523 - name : Push image
500524 id : push
501- if : env.PUBLISH == 'true'
502525 run : |
503526 set -euo pipefail
504527 docker push "$ARCH_REF"
@@ -511,25 +534,25 @@ jobs:
511534 echo "digest=${digest}" >> "$GITHUB_OUTPUT"
512535
513536 - name : Attest and sign image
514- if : env.PUBLISH == 'true'
515537 uses : ./.github/actions/attest-image
516538 with :
517539 image : ${{ steps.push.outputs.image }}
518540 digest : ${{ steps.push.outputs.digest }}
519541 sbom-image : ${{ env.ARCH_REF }}
520542
521543 # Joins the two architectures under the content tag the app references, then signs
522- # and attests that index. Runs after a failed image leg too, so the other kinds and
523- # the index-only retry still publish; a kind joins only when both architectures are
524- # published and signed by this workflow, so a leg that pushed but failed to attest
525- # or sign is never exposed, and the next run rebuilds it.
544+ # and attests that index. Runs after a failed image-publish leg too, so the other
545+ # kinds and the index-only retry still publish; a kind joins only when both
546+ # architectures are published and signed by this workflow, so a leg that pushed but
547+ # failed to attest or sign is never exposed, and the next run rebuilds it.
526548 publish :
527549 name : publish (${{ matrix.kind }})
528- needs : [plan, image]
550+ needs : [plan, image-publish ]
529551 if : >-
530552 !cancelled() &&
531553 needs.plan.outputs.publish == 'true' &&
532554 needs.plan.outputs.kinds != '[]' &&
555+ (github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
533556 (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging')
534557 runs-on : ubuntu-24.04
535558 timeout-minutes : 15
@@ -571,7 +594,7 @@ jobs:
571594 echo "::error::${REF}-${arch} is not published; not publishing ${REF}"
572595 exit 1
573596 fi
574- # The image leg signs last, after both attestations, so a signature means
597+ # The image-publish leg signs last, after both attestations, so a signature means
575598 # the leg finished.
576599 if ! cosign verify \
577600 --certificate-identity-regexp "$SIGNER_IDENTITY_REGEXP" \
0 commit comments