Automate Artifact Registry image cleanup + purge dead image repos#3742
Merged
Conversation
The image repos accumulated ~628 GiB that nothing prunes (~$45/mo storage). Ongoing (in the deploy pipeline): - cleanup_app_engine_versions.sh: when it deletes an App Engine version, also delete that version's gae-flexible Flex image, so the repo stays in lockstep with the retained versions. Version-aware because a blind keep-N would delete a kept stopped-prod version's image (staging/prod images interleave). - cleanup_cloud_run_images.sh + a cleanup-cloud-run-images job: keep the 15 most recent Cloud Run images, delete older. Sorts in-script by createTime since gcloud's Artifact Registry --sort-by proved unreliable. One-time: - purge_stale_artifact_registry.sh (interactive): after a safety pre-check, delete the dead legacy repos (us.gcr.io ~540 GiB, gcr.io, cloud-run-source- deploy), prune gae-flexible orphans, and prune Cloud Run to 15. Tests extended with a stubbed gcloud artifacts. Cuts AR storage to a few $/mo. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3742 +/- ##
==========================================
+ Coverage 79.82% 79.89% +0.07%
==========================================
Files 70 70
Lines 4336 4332 -4
Branches 808 807 -1
==========================================
Hits 3461 3461
+ Misses 655 652 -3
+ Partials 220 219 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The backlog purge (deleting the dead legacy image repos + gae-flexible orphans) is a one-time manual operation, run out-of-band rather than shipped in the repo. This PR keeps only the ongoing automated pruning. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Derive the prune target's region/project/repository from cloud_run_env.sh (the same config the deploy scripts source) instead of re-declaring the defaults. This removes the config duplication so the cleanup can never drift to a different repo than the pipeline pushes to. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3743
What & why
policyengine-apiArtifact Registry is ~$45/mo, 100% storage — ~628 GiB of Docker images that nothing prunes. Two repos grow on every deploy; three are frozen dead weight.This PR adds the ongoing automated pruning. (The one-time backlog purge — deleting the ~552 GiB of dead legacy repos +
gae-flexibleorphans — is a manual operation run out-of-band, not shipped here.)Ongoing cleanup (in the deploy pipeline)
cleanup_cloud_run_images.sh+ acleanup-cloud-run-imagesjob (afterdeploy-cloud-run-candidate): keeps the 15 most recent images in thepolicyengine-apirepo, deletes older. Sorts in-script bycreateTime— gcloud's Artifact Registry--sort-byproved unreliable.cleanup_app_engine_versions.sh: when it deletes a version, it also deletes that version'sgae-flexible/default.<id>image, keeping the repo in lockstep with the retained versions. This is not a blind keep-15: staging/prod images interleave, so keeping "15 most recent" would delete a kept older stopped-prod version's image and break its rollback.Verification
test_app_engine_cleanup_scripts.py, stubbedgcloud artifacts): keep-15, version-awaregae-flexibledeletion, and the disable toggle — 15 passing,ruffclean.Safety notes
gae-flexibleis the live App Engine image store (staging-2411→…/gae-flexible/default.staging-2411-…), so it is pruned version-aware, never wholesale.Expected impact
Ongoing: both live repos stay bounded to
15 images. Combined with the one-time backlog purge, AR storage **$45/mo → ~$3–5/mo**.🤖 Generated with Claude Code