Skip to content

Automate Artifact Registry image cleanup + purge dead image repos#3742

Merged
anth-volk merged 3 commits into
masterfrom
feat/artifact-registry-image-cleanup
Jul 7, 2026
Merged

Automate Artifact Registry image cleanup + purge dead image repos#3742
anth-volk merged 3 commits into
masterfrom
feat/artifact-registry-image-cleanup

Conversation

@anth-volk

@anth-volk anth-volk commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Fixes #3743

What & why

policyengine-api Artifact 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-flexible orphans — is a manual operation run out-of-band, not shipped here.)

Ongoing cleanup (in the deploy pipeline)

  • Cloud Run images — keep 15. New cleanup_cloud_run_images.sh + a cleanup-cloud-run-images job (after deploy-cloud-run-candidate): keeps the 15 most recent images in the policyengine-api repo, deletes older. Sorts in-script by createTime — gcloud's Artifact Registry --sort-by proved unreliable.
  • App Engine Flex images — version-aware. Extended cleanup_app_engine_versions.sh: when it deletes a version, it also deletes that version's gae-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

  • Dry-run against live: Cloud Run cleanup keeps 15 / deletes 3 (in-script sort works); the extended App Engine cleanup runs clean.
  • Tests extended (test_app_engine_cleanup_scripts.py, stubbed gcloud artifacts): keep-15, version-aware gae-flexible deletion, and the disable toggle — 15 passing, ruff clean.

Safety notes

  • Confirmed gae-flexible is the live App Engine image store (staging-2411…/gae-flexible/default.staging-2411-…), so it is pruned version-aware, never wholesale.
  • Deleting an image an old Cloud Run revision still references stops that revision from restarting — acceptable; Cloud Run is the non-primary migration candidate and 15 is a generous window.

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

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

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.89%. Comparing base (4407075) to head (08176b4).
⚠️ Report is 26 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

anth-volk and others added 2 commits July 7, 2026 22:34
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>
@anth-volk anth-volk marked this pull request as ready for review July 7, 2026 22:00
@anth-volk anth-volk merged commit 51b7b04 into master Jul 7, 2026
10 checks passed
@anth-volk anth-volk deleted the feat/artifact-registry-image-cleanup branch July 7, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Artifact Registry image repos grow unbounded (~628 GiB, ~$45/mo)

1 participant