mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
## 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>
62 lines
2.1 KiB
Bash
Executable File
62 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Print `build=true` when the push gateway image must be built for HEAD_REV,
|
|
# and `build=false` when its build inputs match the source of the current :main
|
|
# gateway image. docker.yml appends the line to $GITHUB_OUTPUT, so a failure
|
|
# here fails the step instead of leaving the decision empty.
|
|
#
|
|
# Usage: MAIN_PUSH=true|false scripts/push-gateway-image-inputs-changed.sh HEAD_REV
|
|
#
|
|
# Only a main push (MAIN_PUSH=true) may skip; every other event builds. The
|
|
# docker.yml merge job moves :main only after the image's provenance is
|
|
# attested, so its source label names a completed publication. Comparing with
|
|
# it, not the previous push, keeps a change from being lost when a main run is
|
|
# replaced while pending or fails. The gateway crate depends on no other
|
|
# workspace crate, so only the paths below can change its image. Any doubt
|
|
# builds: an unreadable image, or a source that is unknown or not an ancestor
|
|
# of HEAD_REV.
|
|
set -euo pipefail
|
|
|
|
if [[ $# -ne 1 ]]; then
|
|
echo "usage: MAIN_PUSH=true|false $0 HEAD_REV" >&2
|
|
exit 2
|
|
fi
|
|
head_rev=$1
|
|
|
|
if [[ "${MAIN_PUSH:-}" != "true" ]]; then
|
|
echo build=true
|
|
exit 0
|
|
fi
|
|
|
|
inputs=(
|
|
crates/buzz-push-gateway
|
|
Cargo.toml
|
|
Cargo.lock
|
|
.cargo
|
|
rust-toolchain.toml
|
|
Dockerfile.push-gateway
|
|
.dockerignore
|
|
.github/workflows/docker.yml
|
|
scripts/push-gateway-image-inputs-changed.sh
|
|
)
|
|
|
|
# A multi-platform index reports one image per platform; a single image
|
|
# reports its config directly.
|
|
published_rev=$(docker buildx imagetools inspect ghcr.io/block/buzz-push-gateway:main \
|
|
--format '{{json .Image}}' 2>/dev/null |
|
|
jq -r '(if has("config") then . else .["linux/amd64"] end)
|
|
| .config.Labels["org.opencontainers.image.revision"] // empty' 2>/dev/null || true)
|
|
echo "Published :main gateway source: ${published_rev:-unknown}" >&2
|
|
|
|
if [[ ! "$published_rev" =~ ^[0-9a-f]{40}$ ]] ||
|
|
! git cat-file -e "${published_rev}^{commit}" 2>/dev/null ||
|
|
! git merge-base --is-ancestor "$published_rev" "$head_rev" 2>/dev/null; then
|
|
echo build=true
|
|
exit 0
|
|
fi
|
|
|
|
if git diff --quiet "$published_rev" "$head_rev" -- "${inputs[@]}"; then
|
|
echo build=false
|
|
else
|
|
echo build=true
|
|
fi
|