Repository navigation
ci: prune old continuous main builds from GHCR daily - #2293
Conversation
Nashon-Steffen
left a comment
There was a problem hiding this comment.
Summary
This PR adds a daily, CI-only job that prunes the four main/ GHCR packages with a pinned dataaxiom/ghcr-cleanup-action. The approach is sound. The action applies the age filter before keep-n, so "everything younger than 7 days plus the newest N older" is what actually happens. Slash-containing package names are encoded correctly, the dry-run expression gives the right value on both triggers, and the permissions are minimal.
One retention bug needs fixing before the schedule deletes anything. Because of how ko publishes main/mecak8s, that package keeps about 10 older builds rather than 30, so older kept charts point at deleted images. The other comments are smaller: one about failure visibility and some comment accuracy.
| # | Finding | Severity | Score |
|---|---|---|---|
| 1 | ko per-platform .sbom tags count toward keep-n-tagged, so main/mecak8s keeps about 10 older builds |
HIGH | 8/10 |
| 2 | The existence check reports a permission 404 as a green "nothing to prune" | MEDIUM | 9/10 |
| 3 | The header comment describes cleanup inaccurately (orphans aren't age-gated; there are no .sig/.att tags) |
LOW | 8/10 |
| 4 | Retention guarantees are stated without their conditions | LOW | 8/10 |
| 5 | A live (non-dry-run) dispatch isn't restricted to main |
LOW | 7/10 |
| 6 | validate: true only warns, after deleting |
LOW | 8/10 |
Verifying #1: the dry run in the PR used mecatl/studio, which buildx publishes and which has no per-platform SBOM tags. Running the same dry run against the release package mecatl/mecak8s, which ko publishes the same way continuous.yml does, with keep-n-tagged: 5 should list sha256-<child>.sbom entries among the tagged versions it keeps and deletes.
Hardening (optional): packages: write can also delete release-package versions. Lowering this repository's role from Admin to Write on the release packages would make "release packages are never named" an enforced boundary rather than a convention. A separate Renovate rule for this action, with a release-age delay, would keep its bumps out of the grouped actions PR.
🤖 Generated with Claude Code
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - {package: mecatl/main/mecak8s, keep: 30} |
There was a problem hiding this comment.
ko's per-platform SBOM tags count toward keep-n-tagged, so this package keeps about 10 older builds, not 30. (HIGH)
continuous.yml builds this image with ko build --platform=linux/amd64,linux/arm64 --sbom=spdx. ko pushes one SBOM per platform child, each under a sha256-<child>.sbom tag. You can see this in the release package mecatl/mecak8s: every release has an index plus two tagged sha256-<child>.sbom versions (for example, v0.0.47 has sha256-a6e49b…sbom and sha256-b4b95c…sbom).
In v1.2.2, initFilterSet (manifest-analyzer.ts:125-151) iterates a Set and deletes from it as it goes. The API lists the index before its children, so when it visits the index it deletes the children from the set before visiting them. Their .sbom referrer tags are only removed when the child itself is visited, so those SBOM versions stay in the filter set as top-level tagged images. collectKeepNTaggedCandidates (deletion-strategy.ts:264-276) counts any version with a tag. Each mecak8s build therefore uses 3 of the 30 slots, so about 10 older builds survive while each chart package keeps 20. Older kept charts then pin mecak8s digests that have been deleted, which breaks the guarantee in the header and README. main/studio (buildx, no per-child SBOMs) isn't affected.
Possible fixes:
- Drop
--sbom=spdxfrom the ko step in ci: publish signed main builds of mecak8s, Studio, and their charts #2292. The anchore SBOM is already attested withcosign attest. - Or limit what keep-n counts, for example with a per-package
delete-tagsmatching only the version tags. Whilekeep-n-taggedis set, keep-n counts only the matched tags and nothing is deleted by tag alone (deletion-strategy.ts:91-93, 248-262).
Either way, dry-run against mecatl/mecak8s to confirm.
There was a problem hiding this comment.
Addressed in ced717d. Added delete-tags: '*-main.*' so keep-n-tagged counts only the version tags (v<version> images, <version> charts). The per-platform sha256-<child>.sbom versions no longer take slots and are removed as orphans the run after their image goes.
| encoded=$(jq -rn --arg p "$PACKAGE" '$p | @uri') | ||
| if gh api "/orgs/${OWNER}/packages/container/${encoded}" --silent 2> lookup.err; then | ||
| echo "found=true" >> "$GITHUB_OUTPUT" | ||
| elif grep -q 'HTTP 404' lookup.err; then |
There was a problem hiding this comment.
A permission 404 is reported as "not published yet" and the job stays green. (MEDIUM)
The Packages API returns 404 both for a package that doesn't exist and for a private package the token can't see. If this repository loses Actions access to a main/ package, or a path here drifts from continuous.yml, this leg posts a notice and succeeds every day. Pruning stops and storage grows without anyone noticing. Without this check, the action would have failed loudly on the same 404 (package-repo.ts:232-252).
continuous.yml publishes all four packages in its first run, so the bootstrap window this check covers is short. Suggestion: once #2292 has published, remove the check or fail on 404. At minimum, use ::warning with "not found or not accessible to this repository".
| # signatures whose image is gone are removed once they pass the same age. | ||
| # | ||
| # ghcr-cleanup-action deletes a multi-arch image together with its platform | ||
| # manifests, its sha256-<digest>.{sig,att,sbom} tags, and its OCI referrers | ||
| # (the build-provenance attestations), so nothing a kept build needs is | ||
| # removed. Deleting a version needs the Admin role on the package, which the |
There was a problem hiding this comment.
The header doesn't match what the action and the publisher actually do. (LOW)
- Line 9: orphaned signatures are not age-gated.
findOrphanedImagesscans every tag and subject referrer in the package (image-validator.ts:199-228), and the orchestrator adds the results straight to the delete set, without checking the age-filtered set (cleanup-orchestrator.ts:206-213). Orphans are removed on the next run, whatever their age. - Line 12: cosign v3 publishes signatures and attestations as a
sha256-<digest>referrer-tag index with no suffix. The only suffixed tags are ko's.sbomtags. The releasemecatl/mecak8spackage has no.sigor.atttags. - Lines 13-14: cascading deletion stops a pruned build from leaving leftovers. What keeps a kept build intact is that children and referrers are never deletion candidates on their own. Also, per-platform
.sbomtags are not cascaded (image-deleter.ts:315-358); they become orphans and go on the following run.
Suggested wording: "…its platform manifests and its signature, SBOM, and attestation artifacts (sha256- tags or OCI referrers). Orphans are removed whenever found."
There was a problem hiding this comment.
Addressed in ced717d. The header now says orphaned artifacts are removed whenever found (not age-gated), describes artifacts as sha256- tags or OCI referrers rather than .sig/.att suffixes, and separates cascade cleanup from why kept builds stay intact.
| # older ones (20 charts, 30 images). Images keep more than charts, so every kept | ||
| # chart still resolves its digest-pinned images even when a few runs failed | ||
| # between pushing an image and pushing the charts. Followers select the newest | ||
| # chart, so they never run a pruned build. Untagged leftovers of failed runs and |
There was a problem hiding this comment.
The retention guarantees are stated without their conditions. (LOW)
- Kept charts: "every kept chart still resolves its digest-pinned images" holds only while there are at most 10 image-only runs in the older window (30 − 20, once mecatui: subagent / Task visibility (agent hierarchy dashboard) #1 on line 49 is fixed). A failed mecak8s run is tagged by ko and uses a slot; a failed studio run stays untagged and doesn't. README line 37 states the guarantee with no condition at all.
- Followers: "they never run a pruned build" holds only for followers that keep up. A paused or stuck follower more than 7 days and 20 builds behind loses its images, and its next pod reschedule fails to pull.
Suggest stating both bounds here and in the README.
There was a problem hiding this comment.
Addressed in ced717d. The header and README now state the 10-failed-run margin and that a follower more than 7 days and 20 builds behind loses its images.
|
|
||
| jobs: | ||
| prune: | ||
| if: github.repository == 'stacklok/mecatl' |
There was a problem hiding this comment.
A live dispatch isn't restricted to main. (LOW)
Anyone with write access can dispatch from any branch. That runs the branch's copy of this workflow with packages: write and dry_run=false, including any edited package names or keep counts. continuous.yml gates its dispatch on github.ref == 'refs/heads/main' (continuous.yml:78). Suggestion:
| if: github.repository == 'stacklok/mecatl' | |
| if: github.repository == 'stacklok/mecatl' && github.ref == 'refs/heads/main' |
There was a problem hiding this comment.
Addressed in ced717d. The job condition now also requires github.ref == 'refs/heads/main'; scheduled runs use the default branch, so they are unaffected.
| keep-n-tagged: ${{ matrix.keep }} | ||
| delete-untagged: true | ||
| delete-orphaned-images: true | ||
| validate: true |
There was a problem hiding this comment.
validate doesn't act as a safety gate. (LOW)
It runs after deletion (cleanup-orchestrator.ts:266-272) and reports problems with core.warning. The orchestrator ignores the hasErrors it returns, so a run that breaks a kept image still finishes green, and on a schedule nobody reads the annotations. Keeping it for diagnostics is fine. If you want a real check that kept charts still resolve, add a follow-up step that resolves the pinned image digest of each kept chart and fails if one is missing.
There was a problem hiding this comment.
Addressed in ced717d. Kept validate for diagnostics and marked it advisory in a comment, and the header no longer claims nothing a kept build needs can be removed.
ko tags each platform image's SBOM as sha256-<digest>.sbom, and the cleanup action counted those versions toward keep-n-tagged, so main/mecak8s kept about 10 older builds instead of 30 and older kept charts pinned deleted images. Restrict keep-n to the *-main.* version tags. Drop the package-existence pre-check so a package this repository can't access fails its job instead of passing with a notice, prune only from main's copy of the workflow, and correct the comments and README on orphan handling, artifact shapes, retention conditions, and validate. Addresses #2293 review comments: - HIGH .github/workflows/prune-main-builds.yml:49 (4262507174): ko per-platform .sbom tags used keep-n-tagged slots - MEDIUM .github/workflows/prune-main-builds.yml:67 (4262507191): permission 404 reported as a green notice - LOW .github/workflows/prune-main-builds.yml:9-14 (4262507204): header misdescribed orphan and artifact cleanup - LOW .github/workflows/prune-main-builds.yml:5-8 (4262507212): retention guarantees stated without conditions - LOW .github/workflows/prune-main-builds.yml:39 (4262507223): live dispatch not restricted to main - LOW .github/workflows/prune-main-builds.yml:86 (4262507244): validate is advisory, not a gate Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
41db157 to
6a72e27
Compare
ko tags each platform image's SBOM as sha256-<digest>.sbom, and the cleanup action counted those versions toward keep-n-tagged, so main/mecak8s kept about 10 older builds instead of 30 and older kept charts pinned deleted images. Restrict keep-n to the *-main.* version tags. Drop the package-existence pre-check so a package this repository can't access fails its job instead of passing with a notice, prune only from main's copy of the workflow, and correct the comments and README on orphan handling, artifact shapes, retention conditions, and validate. Addresses #2293 review comments: - HIGH .github/workflows/prune-main-builds.yml:49 (4262507174): ko per-platform .sbom tags used keep-n-tagged slots - MEDIUM .github/workflows/prune-main-builds.yml:67 (4262507191): permission 404 reported as a green notice - LOW .github/workflows/prune-main-builds.yml:9-14 (4262507204): header misdescribed orphan and artifact cleanup - LOW .github/workflows/prune-main-builds.yml:5-8 (4262507212): retention guarantees stated without conditions - LOW .github/workflows/prune-main-builds.yml:39 (4262507223): live dispatch not restricted to main - LOW .github/workflows/prune-main-builds.yml:86 (4262507244): validate is advisory, not a gate Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ced717d to
d1a7255
Compare
continuous.yml publishes two images and two charts for every main commit that passes CI, roughly a dozen builds a day, and nothing removes them. Add a daily job that prunes only the four main/ packages: each keeps every build younger than 7 days plus the newest 20 older charts and 30 older images, so every kept chart still resolves its digest-pinned images. dataaxiom/ghcr-cleanup-action (pinned by commit) deletes a multi-arch image together with its platform manifests, cosign and SBOM tags, and OCI referrers, and removes untagged leftovers of failed runs and orphaned signatures. A package that has not been published yet is skipped, and a manual dispatch defaults to a dry run. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ko tags each platform image's SBOM as sha256-<digest>.sbom, and the cleanup action counted those versions toward keep-n-tagged, so main/mecak8s kept about 10 older builds instead of 30 and older kept charts pinned deleted images. Restrict keep-n to the *-main.* version tags. Drop the package-existence pre-check so a package this repository can't access fails its job instead of passing with a notice, prune only from main's copy of the workflow, and correct the comments and README on orphan handling, artifact shapes, retention conditions, and validate. Addresses #2293 review comments: - HIGH .github/workflows/prune-main-builds.yml:49 (4262507174): ko per-platform .sbom tags used keep-n-tagged slots - MEDIUM .github/workflows/prune-main-builds.yml:67 (4262507191): permission 404 reported as a green notice - LOW .github/workflows/prune-main-builds.yml:9-14 (4262507204): header misdescribed orphan and artifact cleanup - LOW .github/workflows/prune-main-builds.yml:5-8 (4262507212): retention guarantees stated without conditions - LOW .github/workflows/prune-main-builds.yml:39 (4262507223): live dispatch not restricted to main - LOW .github/workflows/prune-main-builds.yml:86 (4262507244): validate is advisory, not a gate Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
d1a7255 to
4c5c1d0
Compare
Summary
Adds
.github/workflows/prune-main-builds.yml, a daily job that deletes old continuousmainbuilds from GHCR.continuous.yml(#2292) publishes two images and two charts for eachmaincommit that passes CI, which is about 11 builds a day (75 a week), and nothing removed them.Stacked on #2292. The base branch is
Nashon-Steffen/studio-continuous-main; retarget it once that PR merges.Retention. The job only touches the four
main/packages. Release images and charts are never named.mecatl/main/charts/mecak8s,mecatl/main/charts/mecatl-studiomecatl/main/mecak8s,mecatl/main/studio*-main.*version tags (v<version>images,<version>charts). ko also tags each platform image's SBOM assha256-<digest>.sbom; counted as versions, those would take two of every threemain/mecak8sslots.Why
dataaxiom/ghcr-cleanup-action. Deleting untagged GHCR versions naively (for example withactions/delete-package-versions) breaks multi-arch images, whose platform manifests are untagged. This action deletes a multi-arch image together with:sha256-<digest>tag or an OCI referrer links them.It skips any child manifest that another image still uses. It is pinned to the v1.2.2 commit (
d52806a) and runs withpackages: write.Behaviour:
continuous.ymlon its merge commit, so the packages exist before this PR reachesmain.maininstacklok/mecatl, so a dispatch from another branch can't prune with edited inputs.validaterechecks the package after deleting and only warns.Issue relationship
Relates to #2292
Type of change
Test plan
Baseline checks
task lint): no Go changes. actionlint v1.7.7 (with shellcheck) reported nothing for the new workflow.task test): no Go changes.task test:race): no Go changes.go run ./cmd/mecademo): no runtime changes.task docs:checkpassed with 0 broken links or anchors.task site:build)task api:check)task api:update+engine/CHANGELOG.mdExercised locally:
*-main.*pattern, with thewildcard-matchversion the action uses: it matchesv0.0.48-main.123.1.gabcdef12and0.0.48-main.123.1.gabcdef12, and none ofsha256-<digest>.sbom,sha256-<digest>,v0.0.47, orlatest.mecatl/studio, beforedelete-tagswas added, using a token without package write or delete scopes. The 7-day / keep-N rules were the same as here, with N=5 to exercise the keep logic.delete-tags. The release packagemecatl/mecak8shas the same per-platform SBOM tags asmain/mecak8s.Special notes for reviewers
GITHUB_TOKENcreated the package, so it holds for themain/packagescontinuous.ymlcreates. If the first scheduled run fails with a permission error or a 404, grant this repository Admin under each package's "Manage Actions access".packages: writeonGITHUB_TOKENreaches every package this repository administers, release packages included. Pinning by commit is the control; review Renovate bumps of this action with that in mind.main/mecak8sshould all bev*tags, with nosha256-*.sbomentries.🤖 Generated with Claude Code