Repository navigation
Commit 38ce26f
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
22 | 34 | | |
23 | 35 | | |
24 | 36 | | |
| |||
29 | 41 | | |
30 | 42 | | |
31 | 43 | | |
32 | | - | |
| 44 | + | |
33 | 45 | | |
34 | 46 | | |
35 | 47 | | |
| |||
39 | 51 | | |
40 | 52 | | |
41 | 53 | | |
42 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
43 | 60 | | |
44 | 61 | | |
45 | 62 | | |
| |||
190 | 207 | | |
191 | 208 | | |
192 | 209 | | |
| 210 | + | |
193 | 211 | | |
194 | 212 | | |
195 | | - | |
196 | | - | |
197 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
198 | 240 | | |
199 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
200 | 244 | | |
| 245 | + | |
201 | 246 | | |
202 | 247 | | |
203 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
204 | 286 | | |
205 | 287 | | |
206 | 288 | | |
| |||
257 | 339 | | |
258 | 340 | | |
259 | 341 | | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
260 | 374 | | |
261 | 375 | | |
262 | 376 | | |
| |||
292 | 406 | | |
293 | 407 | | |
294 | 408 | | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
295 | 412 | | |
296 | 413 | | |
297 | 414 | | |
298 | 415 | | |
299 | 416 | | |
300 | 417 | | |
301 | 418 | | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
302 | 425 | | |
303 | 426 | | |
304 | 427 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8067 | 8067 | | |
8068 | 8068 | | |
8069 | 8069 | | |
8070 | | - | |
| 8070 | + | |
8071 | 8071 | | |
8072 | 8072 | | |
8073 | 8073 | | |
| |||
0 commit comments