Skip to content

Commit 38ce26f

Browse files
ci(framework-build-base): tag every published digest immutably, refuse a silent re-point (#31784)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbQgi7dUkYVi8dx5rSP1DjCP)_ Fixes #31756 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:framework-build-base 发布工作流现在给每个发布出去的镜像 digest 打一个专属标签 `SHA-DIGEST12`(提交号加 digest 前 12 位),永不删除、永不改指向;已发布但没有这个标签的旧 digest,下次被请求时自动补上;`rebuild: true` 覆盖已发布标签时直接拒绝,除非同时给 `replace_published: true`。 - **为什么改**:cloud 按 digest 钉住这个基础镜像。GHCR 清理无标签版本,或同一提交重建把 SHA 标签挪走,都会让钉住的 digest 不再可拉,cloud 的每个镜像就退回约 20 分钟的源码构建。只有发布方能让 digest 常驻。 - **风险与回滚**:只动发布 job 的标签步骤和一个默认关闭的新输入;PR 的 verify 干跑不推送,发布路径只在 main 上手动或 repository_dispatch 时运行。回滚即还原本 PR;已写出的 digest 标签是额外标签,留着无害。 - **先看**:`.github/workflows/framework-build-base.yml` 的 `Is this commit already packaged` 步骤(新的拒绝分支),然后两个打标签步骤(`kept`、`digest_tag`,脚本逐字相同,含 `--prefer-index=false`)。 - **两分钟验证**:看下方 Verification 的本地运行记录:六个分支逐一给出预期退出码和 registry 状态;合并后一次 `workflow_dispatch` 已发布的 pin,应看到 Summary 打印 digest 标签,且匿名可读 `$IMAGE:SHA-DIGEST12`。 - **需要你做的**:审阅并手动合并(Tier H by path);合并后由席位征得你同意,再对一个已发布 pin 做一次 dispatch 补标签。 ## What changes `.github/workflows/framework-build-base.yml`, `publish` job only: 1. **A digest tag of its own, never deleted or re-pointed.** After the build, a new step `Tag the pushed digest under its own name` writes `$IMAGE:$SHA-${DIGEST:7:12}` onto the pushed digest with `docker buildx imagetools create --prefer-index=false`, then reads the tag back and refuses (`::error::`, exit 1) unless it holds exactly that digest. A digest that does not match `^sha256:[0-9a-f]{64}$` is refused before anything is written. DIGEST and SHA reach the script through `env:` only. 2. **Backfill.** A step `Keep the published digest served under its own tag` runs whenever the `SHA` tag already exists, with the same script against the existing digest. On the skip path it still builds nothing; a pin published before this change gains its digest tag the next time it is requested. On the replace path it runs before the build, so the old digest is held by its own tag before the `SHA` tag moves. 3. **No silent re-point.** New boolean `workflow_dispatch` input `replace_published` (default false). In `Is this commit already packaged`, `rebuild: true` over a published tag without `replace_published: true` prints `::error::` naming the existing digest and the downstream step (in the cloud repository, `framework-base-image.sh write`, then commit `.objectstack-base-image`) and exits 1. `repository_dispatch` carries neither input, so it is unaffected; the header says so. 4. **Header and Summary.** Next to "A tag is written once", the header states that the digest tag is never deleted or re-pointed and why. The Summary prints the digest tag (and, on a replace, the tag that keeps the replaced digest served). The "Pin it by digest" line is kept. 5. **Only a real not-found reads as unpublished** (contract review should-fix). `Is this commit already packaged` used to read every failed `imagetools inspect` as "not published", so a registry, token or network error rebuilt the commit and moved its `SHA` tag past both guards, before the backfill. The tag is now absent only when buildx answers `ERROR: REF: not found` (containerd's resolver wraps a 404 for the tag as `REF: ` plus `errdefs.ErrNotFound`, the text `not found`; the step comment cites both sources). Any other failure prints `::error::` naming the ref and the error and exits 1; a read that names no digest fails the same way. 6. `scripts/pm/dispatch-gates.self-test.mjs`: the census row `framework-build-base.yml:32 no-check-families` re-anchored to `:44` (the declaration moved down 12 header lines). The declaration's own reason now also names the digest-tag writes, so it stays true. ## Tests No test file is added: the publish path cannot run from a PR (the `verify` dry run pushes nothing), so the proof is a local run of the workflow's own `run:` bodies, extracted verbatim from the YAML at head, against a fake `docker` that keeps a registry in a text file (`echo` instead of a registry write). The harness first asserts the two tag steps run byte-identical scripts. <details><summary>Eight branches at 65fc33f, each with its expected exit</summary> ```text kept and digest_tag run byte-identical scripts ===== case fresh (no SHA tag yet) existing: skip=false digest_tag: imagetools create --prefer-index=false --tag IMAGE:1111...1111-aaaaaaaaaaaa IMAGE@sha256:aaaaaaaaaaaa...0001 digest_tag: IMAGE:1111...1111-aaaaaaaaaaaa holds sha256:aaaaaaaaaaaa...0001 job exit 0; registry: SHA and SHA-aaaaaaaaaaaa both hold D1 ===== case backfill (SHA at D1, published before this change, no digest tag) existing: already exists at D1; nothing to build. digest=D1 skip=true kept: imagetools create ... -aaaaaaaaaaaa ... ; holds D1 job exit 0 requested again: kept: holds D1 (no create, idempotent) job exit 0 ===== case refuse (SHA at D1, rebuild: true, replace_published: false) ::error::IMAGE:SHA is published at sha256:aaaaaaaaaaaa...0001, 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 (in the cloud repository: run framework-base-image.sh write from its scripts directory, then commit .objectstack-base-image). job exit 1; registry unchanged ===== case replace (SHA at D1, rebuild: true, replace_published: true) kept (before the build): SHA-aaaaaaaaaaaa holds D1 build moves SHA to D2; digest_tag: SHA-bbbbbbbbbbbb holds D2 Summary: digest tag SHA-bbbbbbbbbbbb; the replaced digest stays served under SHA-aaaaaaaaaaaa job exit 0 ===== case shape (existing digest sha256:AAAA) ::error::refusing to tag 'sha256:AAAA': a digest is sha256: followed by 64 lowercase hex job exit 1; nothing written ===== case repoint (SHA-aaaaaaaaaaaa already holds another digest D3) ::error::IMAGE:SHA-aaaaaaaaaaaa already holds sha256:cccccccccccc...0003, not sha256:aaaaaaaaaaaa...0001. A digest tag is never re-pointed, so nothing was changed; ... job exit 1; registry unchanged ===== case notfound (registry empty: inspect answers ERROR: REF: not found) existing: skip=false; build; digest_tag: SHA-aaaaaaaaaaaa holds D1 job exit 0 ===== case transient (SHA at D1, but the read fails: token service 503) ::error::cannot tell whether IMAGE:SHA is published, so nothing is built or moved. The registry read failed with: ERROR: failed to authorize: failed to fetch oauth token: unexpected status from GET request to https://ghcr.io/token: 503 Service Unavailable job exit 1; registry unchanged ``` IMAGE is `ghcr.io/objectstack-ai/framework-build-base`; SHA is forty 1s; long digests are shortened here with `...`, the run printed them whole. </details> <details><summary>Red on main, and one mutation leg</summary> - **The harm on main (c2bb879):** main's `Is this commit already packaged` script, same fake registry with SHA at D1, `REBUILD=true`: exit 0, outputs `skip=false`. The build then pushes and moves the SHA tag, and D1 is left untagged. On this branch the same input is the `refuse` case above, exit 1. - **The transient-read harm on the previous head (dd539bd):** the `transient` case exits 0. `existing` reads the failed inspect as unpublished (skip=false), the build moves the SHA tag from D1 to D2, and D1 is left untagged. At 65fc33f the same case exits 1 with the registry unchanged. - **Why `--prefer-index=false`:** with the flag removed from a temp copy (2 lines changed, 0 left carrying it), the fake `docker` mimics buildx's default for a lone image manifest, wrapping it in a new index with its own digest. The `fresh` case then goes red: `::error::wrote IMAGE:SHA-aaaaaaaaaaaa, but it reads back as sha256:f895effb..., not sha256:aaaaaaaaaaaa...0001, so sha256:aaaaaaaaaaaa...0001 is not yet held by a tag of its own.` (exit 1). The buildx behaviour it mimics is read from buildx's `util/imagetools/create.go` (`combine`: a single non-index source is carbon-copied only when `preferIndex` is false) and the flag's help text in `commands/imagetools/create.go` (default true). The publish job pushes a single-platform image with `provenance: false` and `sbom: false`, so its digest names a plain image manifest. </details> ## Acceptance notes - The brief's command was `imagetools create --tag ... IMAGE@DIGEST`. Without `--prefer-index=false`, buildx wraps a lone image manifest in a new index, so the tag would hold a different digest and the pinned one would stay untagged. The flag is added, and the read-back makes any such drift loud. - The brief placed the backfill on the skip path. The same step also runs on the `replace_published` path, before the build, so a pin rebuilt on purpose never leaves its old digest untagged, even when a later step fails. - The digest-tag step on the fresh path sits after `Note the build wall`, so the build-wall reading still measures the build only. - No error text names an issue number. ## Verification - Dispatch gates at 65fc33f (main merged in): `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 46 commands. All 46 exit 0 (`check:pm-dispatch-gates`: 2205 fast-tier cases pass, 328.5 s). `--ran` reconciliation: 46 derived, 46 run, 0 NOT-MEASURED, 0 UNRUN. - `node scripts/check-self-test-wired.mjs --self-test` went red on this diff's first spelling of the refusal (it named cloud's script as a `scripts/` path, which the live-corpus battery reads as an invocation of a missing file in this tree). It is green on the respelled text. - `verify` (the PR's dry run) is CI's to report on this head. - Owed after landing, not this PR: one `workflow_dispatch` on an already-published pin (it should backfill the digest tag), then an anonymous manifest read of `$IMAGE:SHA-DIGEST12`. The seat asks the maintainer first, because it writes to the registry. --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jSrcejjpWHd8D1fpmZ)_ <!-- signed: domain:devx#2 · zhuangjianguo · session_01QsR2jTo666XXx9e1Gm21C6 --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d9a232f commit 38ce26f

2 files changed

Lines changed: 132 additions & 9 deletions

File tree

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

Lines changed: 131 additions & 8 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,82 @@ 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
195-
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)."
213+
# Only the registry's own "no such tag" answer means unpublished. Any
214+
# other failed read (a registry, token or network error) stops the job:
215+
# read as unpublished it would rebuild and move the tag past both
216+
# guards below. buildx prints that answer as `ERROR: REF: not found`:
217+
# containerd's resolver (core/remotes/docker/resolver.go) wraps a 404
218+
# for the tag as "REF: " plus errdefs.ErrNotFound, whose text is
219+
# "not found", and buildx's main.go prefixes "ERROR: ".
220+
ERR="$(mktemp)"
221+
if READ="$(docker buildx imagetools inspect "$REF" --format '{{json .Manifest}}' 2>"$ERR")"; then
222+
DIGEST="$(printf '%s' "$READ" | jq -r '.digest // empty')"
223+
if [ -z "$DIGEST" ]; then
224+
echo "::error::$REF was read, but the answer names no digest: $READ"
225+
exit 1
226+
fi
227+
elif grep -Fq "$REF: not found" "$ERR"; then
228+
DIGEST=""
229+
else
230+
echo "::error::cannot tell whether $REF is published, so nothing is built or moved. The registry read failed with: $(tr '\n' ' ' < "$ERR")"
231+
exit 1
232+
fi
233+
# A published digest is handed on whatever happens next: the digest-tag
234+
# step below keeps it served under a tag of its own.
235+
if [ -n "$DIGEST" ]; then echo "digest=$DIGEST" >> "$GITHUB_OUTPUT"; fi
236+
if [ -z "$DIGEST" ]; then
237+
echo "skip=false" >> "$GITHUB_OUTPUT"
238+
elif [ "$REBUILD" != true ]; then
239+
echo "$REF already exists at $DIGEST; nothing to build."
198240
echo "skip=true" >> "$GITHUB_OUTPUT"
199-
echo "digest=$DIGEST" >> "$GITHUB_OUTPUT"
241+
elif [ "$REPLACE" != true ]; then
242+
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 (in the cloud repository: run framework-base-image.sh write from its scripts directory, then commit .objectstack-base-image)."
243+
exit 1
200244
else
245+
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."
201246
echo "skip=false" >> "$GITHUB_OUTPUT"
202247
fi
203248
249+
# Every published digest keeps a tag of its own, `<sha>-<12 hex>`, that is
250+
# never deleted or re-pointed (see the header). The two steps below run the
251+
# same script: this one for the digest already published under `<sha>`
252+
# (the backfill, before a replace can move the `<sha>` tag), the next one
253+
# for the digest this run pushed.
254+
- name: Keep the published digest served under its own tag
255+
if: steps.existing.outputs.digest != ''
256+
id: kept
257+
env:
258+
SHA: ${{ steps.sha.outputs.sha }}
259+
DIGEST: ${{ steps.existing.outputs.digest }}
260+
run: |
261+
set -euo pipefail
262+
if ! printf '%s' "$DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'; then
263+
echo "::error::refusing to tag '$DIGEST': a digest is sha256: followed by 64 lowercase hex"
264+
exit 1
265+
fi
266+
TAG="$IMAGE:$SHA-${DIGEST:7:12}"
267+
held() { docker buildx imagetools inspect "$TAG" --format '{{json .Manifest}}' 2>/dev/null | jq -r '.digest // empty' || true; }
268+
HELD="$(held)"
269+
if [ -z "$HELD" ]; then
270+
# --prefer-index=false copies the manifest as it is. The default
271+
# wraps a lone image manifest in a new index, whose digest differs,
272+
# so the tag would not hold DIGEST at all.
273+
docker buildx imagetools create --prefer-index=false --tag "$TAG" "$IMAGE@$DIGEST"
274+
HELD="$(held)"
275+
if [ "$HELD" != "$DIGEST" ]; then
276+
echo "::error::wrote $TAG, but it reads back as ${HELD:-nothing}, not $DIGEST, so $DIGEST is not yet held by a tag of its own."
277+
exit 1
278+
fi
279+
elif [ "$HELD" != "$DIGEST" ]; then
280+
echo "::error::$TAG already holds $HELD, 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."
281+
exit 1
282+
fi
283+
echo "$TAG holds $DIGEST"
284+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
285+
204286
- name: Free runner disk
205287
if: steps.existing.outputs.skip != 'true'
206288
run: |
@@ -257,6 +339,38 @@ jobs:
257339
START: ${{ steps.clock.outputs.start }}
258340
run: echo "seconds=$(( $(date +%s) - START ))" >> "$GITHUB_OUTPUT"
259341

342+
- name: Tag the pushed digest under its own name
343+
if: steps.existing.outputs.skip != 'true'
344+
id: digest_tag
345+
env:
346+
SHA: ${{ steps.sha.outputs.sha }}
347+
DIGEST: ${{ steps.build.outputs.digest }}
348+
run: |
349+
set -euo pipefail
350+
if ! printf '%s' "$DIGEST" | grep -Eq '^sha256:[0-9a-f]{64}$'; then
351+
echo "::error::refusing to tag '$DIGEST': a digest is sha256: followed by 64 lowercase hex"
352+
exit 1
353+
fi
354+
TAG="$IMAGE:$SHA-${DIGEST:7:12}"
355+
held() { docker buildx imagetools inspect "$TAG" --format '{{json .Manifest}}' 2>/dev/null | jq -r '.digest // empty' || true; }
356+
HELD="$(held)"
357+
if [ -z "$HELD" ]; then
358+
# --prefer-index=false copies the manifest as it is. The default
359+
# wraps a lone image manifest in a new index, whose digest differs,
360+
# so the tag would not hold DIGEST at all.
361+
docker buildx imagetools create --prefer-index=false --tag "$TAG" "$IMAGE@$DIGEST"
362+
HELD="$(held)"
363+
if [ "$HELD" != "$DIGEST" ]; then
364+
echo "::error::wrote $TAG, but it reads back as ${HELD:-nothing}, not $DIGEST, so $DIGEST is not yet held by a tag of its own."
365+
exit 1
366+
fi
367+
elif [ "$HELD" != "$DIGEST" ]; then
368+
echo "::error::$TAG already holds $HELD, 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."
369+
exit 1
370+
fi
371+
echo "$TAG holds $DIGEST"
372+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
373+
260374
# The image is for anyone to pull, so it is read back the way a stranger
261375
# would: logged out. A fresh build is pulled whole and looked inside; an
262376
# existing tag only has its manifest read, anonymously.
@@ -292,13 +406,22 @@ jobs:
292406
SKIPPED: ${{ steps.existing.outputs.skip }}
293407
WALL: ${{ steps.wall.outputs.seconds }}
294408
PULL: ${{ steps.pull.outcome }}
409+
BUILT: ${{ steps.build.outputs.digest }}
410+
PUSHED_TAG: ${{ steps.digest_tag.outputs.tag }}
411+
KEPT_TAG: ${{ steps.kept.outputs.tag }}
295412
run: |
296413
{
297414
echo "### $IMAGE"
298415
echo
299416
echo "- framework commit: \`$SHA\`"
300417
echo "- tag: \`$IMAGE:$SHA\`"
301418
echo "- digest: \`${DIGEST:-none}\`"
419+
if [ -n "$BUILT" ]; then
420+
echo "- digest tag (never deleted or re-pointed): \`${PUSHED_TAG:-not written}\`"
421+
if [ -n "$KEPT_TAG" ]; then echo "- the replaced digest stays served under: \`$KEPT_TAG\`"; fi
422+
else
423+
echo "- digest tag (never deleted or re-pointed): \`${KEPT_TAG:-not written}\`"
424+
fi
302425
if [ "$SKIPPED" = true ]; then
303426
echo "- build: skipped, the tag already existed"
304427
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)