-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a cleanup of old Docker images and untagged images #2302
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Have you had a chance to test this yet? Do you want me to merge in and test on a few PR? |
Sort of, is the best answer. It's one of those difficult to test things. I linked a couple places in a run above, where I pointed the script to read from immich-app/immich instead of the fork. The output there all made sense. Merging it (with the PAT setup) and without the |
Maybe it is better to use GitHub provided action Pros:
|
That would be great if it worked but I can see a few problems there. It doesn't look really geared towards containers.
It'd be great if an action was provided for this, or a retention setting or something, but at this point I haven't found anything for it |
I'm going to convert this back to a draft to do a little rework on it. All this logic and code is 99% the same as what I used in paperless-ngx for cleaning up our old images. And if it's going to be doubled, I might as well make it reusable in a action (or two). My apologies this won't unsubscribe people from the thread. I'll keep any testing to a different branch until I'm ready with this one again. |
Overall, I think this would be a good clean up step to take, not only helping surface released versions, but also just being good stewards and not storing images forever. |
This adds a workflow to clean containers when the pull request closes and remove untagged images generated as tags are updated
This PR adds a new workflow which will runs when a PR closes to remove the associated Docker image which was built from the PR and images which are untagged. In an ideal world, this would be something built into github, but until that day... This helps keep the packages with tags down to just the released versions and those PRs which are still in some sort of active state.
Stale Images
I've tested this with a read PAT in a sample repository here: https://github.com/stumpylog/immich-sample-repo/actions/runs/4791378901
Taking
immich-server
as the example, the list of images which would be removed.The logic is pretty simple (and encapsulated into an action). It filters to packages with 1 tag (extra security), with match the regex
^pr-(\d+)$|^(\d+)$
. The capturing groups are used to get a PR number. If the PR is closed (which also means merged), the package is considered done with and can be removedUntagged Images
Requires a little more knowledge of Docker and registries to understand, but not terrible.
Basically, when a tag is updated to point to a newly built image (say the PR or branch was updated), the old image doesn't get removed. In fact, it could still be accessed via a tag of the form
@sha256:<digest>
. But most people are using:main
or:pr-1234
, not a SHA.So the action looks for images with no tags applied and not pointed to by a multi-arch manifest and removes those.
TBD
delete
option to be set to actually delete anything. For now, it's more like a dry run