Skip to content

Commit 9287977

Browse files
committed
ci(framework-build-base): tag every published digest immutably, refuse a silent re-point
Every digest the publish job pushes, and the digest already published under a requested sha, now carries its own tag SHA-DIGEST12 that is never deleted or re-pointed, so a GHCR cleanup of untagged versions or a rebuild of the same pin never takes a pinned digest away. A rebuild over a published tag is refused unless replace_published is also true. Re-anchors the dispatch-gates self-test row for the moved no-check-families declaration (line 32 to 44). Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jSrcejjpWHd8D1fpmZ
1 parent c2bb879 commit 9287977

2 files changed

Lines changed: 106 additions & 8 deletions

File tree

‎.github/workflows/framework-build-base.yml‎

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,20 @@ name: Framework Build Base Image
1717
# with the PR's Dockerfile and pushes nothing; its job has no packages grant.
1818
#
1919
# A tag is written once. A request for a commit whose tag already exists reports
20-
# the existing digest and builds nothing (dispatch with `rebuild: true` to
21-
# replace it), so a downstream can ask on every pin move at no cost.
20+
# the existing digest and builds nothing, so a downstream can ask on every pin
21+
# move at no cost. Replacing a published tag takes a dispatch with BOTH
22+
# `rebuild: true` and `replace_published: true`: `rebuild: true` alone over a
23+
# published tag is refused, naming the digest it would move. A
24+
# repository_dispatch carries neither input, so it never replaces anything.
25+
#
26+
# Every digest this workflow publishes also carries a tag of its own,
27+
# `<sha>-<the first 12 hex of the digest>`, and that tag is never deleted or
28+
# re-pointed. A downstream pins this image by digest (cloud's committed
29+
# .objectstack-base-image), and a registry serves a digest only while some tag
30+
# holds it: a cleanup of untagged versions, or a replace that moves the `<sha>`
31+
# tag, would otherwise take the pinned digest away. A request whose `<sha>` tag
32+
# already exists writes its missing digest tag too, so a digest published
33+
# before this rule becomes durable the next time it is requested.
2234
#
2335
# The image definition always comes from THIS run's checkout of main; only the
2436
# build context is the requested commit. So a commit that predates this file can
@@ -29,7 +41,7 @@ name: Framework Build Base Image
2941
# settings (Danger Zone, Change visibility; it cannot be made private again).
3042
# Until then the anonymous-pull step below is red and names that fix.
3143

32-
# dispatch-gates: no-check-families -- the steps are an image build, a registry read and an in-image check script (docker/framework-build-base/check-image.sh, which needs the built image), not named local checks
44+
# dispatch-gates: no-check-families -- the steps are an image build and push, registry reads and digest-tag writes, and an in-image check script (docker/framework-build-base/check-image.sh, which needs the built image), not named local checks
3345

3446
on:
3547
workflow_dispatch:
@@ -39,7 +51,12 @@ on:
3951
required: true
4052
type: string
4153
rebuild:
42-
description: 'Rebuild and re-push even when the tag already exists (the digest changes)'
54+
description: 'Rebuild and re-push even when the tag already exists (the digest changes); over a published tag it also needs replace_published'
55+
required: false
56+
type: boolean
57+
default: false
58+
replace_published:
59+
description: 'With rebuild, move a published tag to the new digest (the old digest stays served under its own sha-digest tag; downstream pins must then be rewritten)'
4360
required: false
4461
type: boolean
4562
default: false
@@ -190,17 +207,60 @@ jobs:
190207
env:
191208
REF: ${{ env.IMAGE }}:${{ steps.sha.outputs.sha }}
192209
REBUILD: ${{ inputs.rebuild && 'true' || 'false' }}
210+
REPLACE: ${{ inputs.replace_published && 'true' || 'false' }}
193211
run: |
194212
set -euo pipefail
195213
DIGEST="$(docker buildx imagetools inspect "$REF" --format '{{json .Manifest}}' 2>/dev/null | jq -r '.digest // empty' || true)"
196-
if [ -n "$DIGEST" ] && [ "$REBUILD" != true ]; then
197-
echo "$REF already exists at $DIGEST; nothing to build (dispatch with rebuild: true to replace it)."
214+
# A published digest is handed on whatever happens next: the digest-tag
215+
# step below keeps it served under a tag of its own.
216+
if [ -n "$DIGEST" ]; then echo "digest=$DIGEST" >> "$GITHUB_OUTPUT"; fi
217+
if [ -z "$DIGEST" ]; then
218+
echo "skip=false" >> "$GITHUB_OUTPUT"
219+
elif [ "$REBUILD" != true ]; then
220+
echo "$REF already exists at $DIGEST; nothing to build."
198221
echo "skip=true" >> "$GITHUB_OUTPUT"
199-
echo "digest=$DIGEST" >> "$GITHUB_OUTPUT"
222+
elif [ "$REPLACE" != true ]; then
223+
echo "::error::$REF is published at $DIGEST, and rebuild: true would move it to a new digest. To replace it on purpose, dispatch again with rebuild: true and replace_published: true; then rewrite every downstream pin (cloud: scripts/framework-base-image.sh write, then commit .objectstack-base-image)."
224+
exit 1
200225
else
226+
echo "$REF is published at $DIGEST; replace_published: true, so it is rebuilt and the tag moves. The old digest stays served under its digest tag."
201227
echo "skip=false" >> "$GITHUB_OUTPUT"
202228
fi
203229
230+
# Every published digest keeps a tag of its own, `<sha>-<12 hex>`, that is
231+
# never deleted or re-pointed (see the header). The two steps below run the
232+
# same script: this one for the digest already published under `<sha>`
233+
# (the backfill, before a replace can move the `<sha>` tag), the next one
234+
# for the digest this run pushed.
235+
- name: Keep the published digest served under its own tag
236+
if: steps.existing.outputs.digest != ''
237+
id: kept
238+
env:
239+
SHA: ${{ steps.sha.outputs.sha }}
240+
DIGEST: ${{ steps.existing.outputs.digest }}
241+
run: |
242+
set -euo pipefail
243+
if ! printf '%s' "$DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'; then
244+
echo "::error::refusing to tag '$DIGEST': a digest is sha256: followed by 64 lowercase hex"
245+
exit 1
246+
fi
247+
TAG="$IMAGE:$SHA-${DIGEST:7:12}"
248+
held() { docker buildx imagetools inspect "$TAG" --format '{{json .Manifest}}' 2>/dev/null | jq -r '.digest // empty' || true; }
249+
HELD="$(held)"
250+
if [ -z "$HELD" ]; then
251+
# --prefer-index=false copies the manifest as it is. The default
252+
# wraps a lone image manifest in a new index, whose digest differs,
253+
# so the tag would not hold DIGEST at all.
254+
docker buildx imagetools create --prefer-index=false --tag "$TAG" "$IMAGE@$DIGEST"
255+
HELD="$(held)"
256+
fi
257+
if [ "$HELD" != "$DIGEST" ]; then
258+
echo "::error::$TAG holds ${HELD:-nothing}, not $DIGEST. A digest tag is never re-pointed, so nothing was changed; read the tag's history in the package's settings before touching it."
259+
exit 1
260+
fi
261+
echo "$TAG holds $DIGEST"
262+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
263+
204264
- name: Free runner disk
205265
if: steps.existing.outputs.skip != 'true'
206266
run: |
@@ -257,6 +317,35 @@ jobs:
257317
START: ${{ steps.clock.outputs.start }}
258318
run: echo "seconds=$(( $(date +%s) - START ))" >> "$GITHUB_OUTPUT"
259319

320+
- name: Tag the pushed digest under its own name
321+
if: steps.existing.outputs.skip != 'true'
322+
id: digest_tag
323+
env:
324+
SHA: ${{ steps.sha.outputs.sha }}
325+
DIGEST: ${{ steps.build.outputs.digest }}
326+
run: |
327+
set -euo pipefail
328+
if ! printf '%s' "$DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'; then
329+
echo "::error::refusing to tag '$DIGEST': a digest is sha256: followed by 64 lowercase hex"
330+
exit 1
331+
fi
332+
TAG="$IMAGE:$SHA-${DIGEST:7:12}"
333+
held() { docker buildx imagetools inspect "$TAG" --format '{{json .Manifest}}' 2>/dev/null | jq -r '.digest // empty' || true; }
334+
HELD="$(held)"
335+
if [ -z "$HELD" ]; then
336+
# --prefer-index=false copies the manifest as it is. The default
337+
# wraps a lone image manifest in a new index, whose digest differs,
338+
# so the tag would not hold DIGEST at all.
339+
docker buildx imagetools create --prefer-index=false --tag "$TAG" "$IMAGE@$DIGEST"
340+
HELD="$(held)"
341+
fi
342+
if [ "$HELD" != "$DIGEST" ]; then
343+
echo "::error::$TAG holds ${HELD:-nothing}, not $DIGEST. A digest tag is never re-pointed, so nothing was changed; read the tag's history in the package's settings before touching it."
344+
exit 1
345+
fi
346+
echo "$TAG holds $DIGEST"
347+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
348+
260349
# The image is for anyone to pull, so it is read back the way a stranger
261350
# would: logged out. A fresh build is pulled whole and looked inside; an
262351
# existing tag only has its manifest read, anonymously.
@@ -292,13 +381,22 @@ jobs:
292381
SKIPPED: ${{ steps.existing.outputs.skip }}
293382
WALL: ${{ steps.wall.outputs.seconds }}
294383
PULL: ${{ steps.pull.outcome }}
384+
BUILT: ${{ steps.build.outputs.digest }}
385+
PUSHED_TAG: ${{ steps.digest_tag.outputs.tag }}
386+
KEPT_TAG: ${{ steps.kept.outputs.tag }}
295387
run: |
296388
{
297389
echo "### $IMAGE"
298390
echo
299391
echo "- framework commit: \`$SHA\`"
300392
echo "- tag: \`$IMAGE:$SHA\`"
301393
echo "- digest: \`${DIGEST:-none}\`"
394+
if [ -n "$BUILT" ]; then
395+
echo "- digest tag (never deleted or re-pointed): \`${PUSHED_TAG:-not written}\`"
396+
if [ -n "$KEPT_TAG" ]; then echo "- the replaced digest stays served under: \`$KEPT_TAG\`"; fi
397+
else
398+
echo "- digest tag (never deleted or re-pointed): \`${KEPT_TAG:-not written}\`"
399+
fi
302400
if [ "$SKIPPED" = true ]; then
303401
echo "- build: skipped, the tag already existed"
304402
else

‎scripts/pm/dispatch-gates.self-test.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8067,7 +8067,7 @@ export function selfTest({ tier = 'full' } = {}) {
80678067
// is paths-filtered (its own file and docker/framework-build-base/) and builds
80688068
// an image, then checks it with a script that needs the built image, so it
80698069
// discovers no `check:` family.
8070-
'.github/workflows/framework-build-base.yml:32 no-check-families',
8070+
'.github/workflows/framework-build-base.yml:44 no-check-families',
80718071
'.github/workflows/merged-branch-reaper.yml:212 no-check-families',
80728072
'.github/workflows/os-create-smoke.yml:48 no-check-families',
80738073
'.github/workflows/scaffold-e2e.yml:23 no-check-families',

0 commit comments

Comments
 (0)