Skip to content

Add automated cleanup for old container images#11

Merged
corytodd merged 3 commits intomainfrom
copilot/add-workflow-delete-old-images
Jan 12, 2026
Merged

Add automated cleanup for old container images#11
corytodd merged 3 commits intomainfrom
copilot/add-workflow-delete-old-images

Conversation

Copy link
Contributor

Copilot AI commented Jan 12, 2026

Automatically delete old container images from GHCR, retaining only the 3 most recent SHA-tagged versions plus the latest tag.

Changes

  • Added cleanup job to .github/workflows/image.yml that runs after successful builds
  • Uses actions/delete-package-versions@v5 with:
    • min-versions-to-keep: 3 to retain 3 most recent versions
    • ignore-versions: '^latest$' to preserve the latest tag
    • Dynamic package name from github.event.repository.name

Behavior

The cleanup job triggers automatically after each image push, removing old SHA-tagged images while preserving:

  • 3 most recent commit SHA tags
  • The latest tag (always retained)

Leverages existing workflow permissions (packages: write, contents: read).

Original prompt

Add a workflow that deletes old images. I want only the 3 most recent images. Attach this to the build and push image workflow.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 12, 2026 03:22
Co-authored-by: corytodd <2796559+corytodd@users.noreply.github.com>
Co-authored-by: corytodd <2796559+corytodd@users.noreply.github.com>
Copilot AI changed the title [WIP] Add workflow to delete old images keeping the latest three Add automated cleanup for old container images Jan 12, 2026
Copilot AI requested a review from corytodd January 12, 2026 03:25
@corytodd
Copy link
Owner

@copilot reword the commits to look this the rest of the tree. e.g. ci: add image auto-purge. Squash your commits down to one for this particular feature.

Copy link
Contributor Author

Copilot AI commented Jan 12, 2026

@copilot reword the commits to look this the rest of the tree. e.g. ci: add image auto-purge. Squash your commits down to one for this particular feature.

I don't have force-push access to rewrite the commit history on this branch. The commits can be squashed when merging the PR using GitHub's "Squash and merge" option, which will create a single commit with a message you can edit to match the format (e.g., "ci: add image auto-purge").

Alternatively, if you'd like me to squash the commits on the branch itself, I would need force-push permissions to rewrite the branch history.

@corytodd corytodd marked this pull request as ready for review January 12, 2026 04:46
@corytodd corytodd merged commit 9dcd6d5 into main Jan 12, 2026
2 of 3 checks passed
@corytodd corytodd deleted the copilot/add-workflow-delete-old-images branch January 12, 2026 04:47
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.

2 participants