mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
ci(docker): publish the push gateway only when its inputs change (#9658)
## Why
Every main push that rebuilds the relay image also published a new push
gateway image. A staging environment that promotes each published
`main-<commit UTC>-<7>` gateway image then rolls out identical gateways.
In one 29-hour window, main got 43 image-eligible commits, and only 2 of
them changed the gateway. The gateway crate depends on no other
workspace crate, so the other 41 images could not differ in behavior.
## What
- New `push-gateway-inputs` job in `docker.yml`. It runs
`scripts/push-gateway-image-inputs-changed.sh`. On a main push, the
script reads the `org.opencontainers.image.revision` label of the
current `ghcr.io/block/buzz-push-gateway:main` image. It then compares
the gateway's build inputs at that revision and at HEAD:
`crates/buzz-push-gateway`, `Cargo.toml`, `Cargo.lock`, `.cargo`,
`rust-toolchain.toml`, `Dockerfile.push-gateway`, `.dockerignore`,
`docker.yml` and the script itself. Every other event prints
`build=true`. The step appends the script's output to `$GITHUB_OUTPUT`,
so a failing check fails the run instead of skipping the build.
- `push-gateway-build` and `push-gateway-personal-dev` run only when
those inputs changed. When the build is skipped, `push-gateway-merge` is
skipped too.
- `push-gateway-merge` now moves `:main` in its own step, after
provenance is attested. The first publication sets every other tag. So
`:main`'s source label always names a completed publication, and a
failed attestation is retried on the next run.
- It compares with the published image, not `github.event.before`. Main
runs share one concurrency group, so a newer push replaces a pending
run, and a failed run publishes nothing. In both cases the next run
still sees the gateway change.
- When in doubt, it builds: an unreadable image, an unknown source, or a
source that isn't an ancestor of HEAD.
- `scripts/test-relay-image-eligibility-workflow.sh` pins the job
gating, the decision step, and `:main` moving after attestation. It runs
the script against a fixture repository with `docker` stubbed:
multi-platform and single-platform `:main` at HEAD, a non-main event, a
lookup failure, relay-only, toolchain-only, a gateway change behind a
later relay-only commit, a missing source, and a non-ancestor source. I
checked that each assertion fails when its production line is broken.
## Risk
- A base image update (`rust`, `debian:bookworm-slim`) alone no longer
publishes a new gateway image. The next gateway input change picks it
up. A manual dispatch at a `relay-v*` tag still builds.
- `:main` now moves a few seconds after the other tags on main pushes.
Deployments that follow `main-<commit UTC>-<7>` are unaffected.
- The relay image and its triggers are unchanged.
## Simpler
There are fewer published gateway images, and every one of them changes
the gateway. No new configuration.
## Testing
- `scripts/test-relay-image-eligibility-workflow.sh` passes locally.
Mutations of the script and the job gating fail it.
- `actionlint .github/workflows/docker.yml` passes.
- Checked locally that the `docker buildx imagetools inspect … --format
'{{json .Image}}'` + `jq` read returns the current `:main` gateway
source revision.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Signed-off-by: Luke Tornquist <tornquist@squareup.com>
Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
49
.github/workflows/docker.yml
vendored
49
.github/workflows/docker.yml
vendored
@@ -37,7 +37,9 @@ name: Docker image
|
||||
#
|
||||
# ghcr.io/block/buzz-push-gateway carries the same :main, :sha-<7> and
|
||||
# :main-<commit UTC>-<7> tags on main pushes, and publishes only after the
|
||||
# relay's `qualify` job accepts the same source SHA.
|
||||
# relay's `qualify` job accepts the same source SHA. A main push publishes it
|
||||
# only when the gateway's build inputs changed since the source of the current
|
||||
# :main gateway image (scripts/push-gateway-image-inputs-changed.sh).
|
||||
#
|
||||
# :main-<YYYYMMDDHHmmss>-<7> names the same main build as :sha-<7>, prefixed
|
||||
# with its UTC commit time so the tag sorts by build order. Kargo's Lexical
|
||||
@@ -80,6 +82,7 @@ on:
|
||||
- "scripts/create-deployment-eligibility-predicate.jq"
|
||||
- "scripts/select-qualified-ci-run.jq"
|
||||
- "scripts/test-relay-image-eligibility-workflow.sh"
|
||||
- "scripts/push-gateway-image-inputs-changed.sh"
|
||||
- "Cargo.toml"
|
||||
- "Cargo.lock"
|
||||
- "rust-toolchain.toml"
|
||||
@@ -522,8 +525,33 @@ jobs:
|
||||
fi
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
# Staging takes every published main gateway image, so a main push publishes
|
||||
# one only when the gateway's build inputs changed since the source of the
|
||||
# current :main image. Other events always build.
|
||||
push-gateway-inputs:
|
||||
name: Check push gateway build inputs
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 10
|
||||
permissions:
|
||||
contents: read
|
||||
outputs:
|
||||
build: ${{ steps.check.outputs.build }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
- name: Compare with the published gateway image
|
||||
id: check
|
||||
env:
|
||||
MAIN_PUSH: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
|
||||
run: scripts/push-gateway-image-inputs-changed.sh "$GITHUB_SHA" >> "$GITHUB_OUTPUT"
|
||||
|
||||
push-gateway-build:
|
||||
name: Build public push gateway (${{ matrix.platform }})
|
||||
needs: push-gateway-inputs
|
||||
if: needs.push-gateway-inputs.outputs.build == 'true'
|
||||
runs-on: ${{ matrix.runner }}
|
||||
timeout-minutes: 60
|
||||
permissions:
|
||||
@@ -601,6 +629,8 @@ jobs:
|
||||
|
||||
push-gateway-personal-dev:
|
||||
name: Build personal development push gateway
|
||||
needs: push-gateway-inputs
|
||||
if: needs.push-gateway-inputs.outputs.build == 'true'
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 60
|
||||
permissions:
|
||||
@@ -676,12 +706,18 @@ jobs:
|
||||
working-directory: /tmp/gateway-digests
|
||||
env:
|
||||
META_TAGS: ${{ steps.meta.outputs.tags }}
|
||||
# :main is held back until provenance is attested; see "Publish :main".
|
||||
run: |
|
||||
set -euo pipefail
|
||||
tags=(); while IFS= read -r tag; do [ -n "$tag" ] && tags+=("-t" "$tag"); done <<< "$META_TAGS"
|
||||
tags=(); first_tag=""; main=false
|
||||
while IFS= read -r tag; do
|
||||
[ -n "$tag" ] || continue
|
||||
if [ "$tag" = "ghcr.io/block/buzz-push-gateway:main" ]; then main=true; continue; fi
|
||||
tags+=("-t" "$tag"); first_tag=${first_tag:-$tag}
|
||||
done <<< "$META_TAGS"
|
||||
echo "main=${main}" >> "$GITHUB_OUTPUT"
|
||||
digests=(); for digest in *; do digests+=("ghcr.io/block/buzz-push-gateway@sha256:${digest}"); done
|
||||
docker buildx imagetools create "${tags[@]}" "${digests[@]}"
|
||||
first_tag=$(echo "$META_TAGS" | head -n1)
|
||||
digest=$(docker buildx imagetools inspect "$first_tag" --format '{{json .Manifest}}' | jq -r '.digest')
|
||||
echo "digest=${digest}" >> "$GITHUB_OUTPUT"
|
||||
- name: Attest gateway image provenance
|
||||
@@ -690,6 +726,13 @@ jobs:
|
||||
subject-name: ghcr.io/block/buzz-push-gateway
|
||||
subject-digest: ${{ steps.manifest.outputs.digest }}
|
||||
push-to-registry: true
|
||||
# Main pushes compare with the source of :main to decide whether to build
|
||||
# (push-gateway-inputs), so :main moves only once the image is attested.
|
||||
- name: Publish :main
|
||||
if: steps.manifest.outputs.main == 'true'
|
||||
env:
|
||||
GATEWAY_DIGEST: ${{ steps.manifest.outputs.digest }}
|
||||
run: docker buildx imagetools create -t ghcr.io/block/buzz-push-gateway:main "ghcr.io/block/buzz-push-gateway@${GATEWAY_DIGEST}"
|
||||
- name: Gateway publication summary
|
||||
env:
|
||||
GATEWAY_DIGEST: ${{ steps.manifest.outputs.digest }}
|
||||
|
||||
Reference in New Issue
Block a user