Delete image tag from Github Container Registry #26267
-
I’m using the new GHCR and generating docker images for pull requests so I can deploy to a staging environment per-PR. This works great using GitHub actions but I can’t find a way to delete the generated image tags when a PR is merged. Based on the Docker Registry API spec it looks like I would need to fetch the manifest digest for the given tag and then delete the manifest. But trying to do this via the GHCR API gives me The GHCR doc*mentation only describes the process of manually deleting an image and indicates that it may be added to the GraphQL API in the future. Is there currently a way to delete image tags via code? If not, is this going to be part of the GA release? EDIT: I had to censor the word “doc*mentation” because the word filter complained that my post has the word “c*m” in it. I guess someone wasn’t aware of the Sc*nthorpe problem (yeah, that triggers it too). |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 4 replies
-
I think the correct solution for the moment is to use the GitHub REST API and delete the |
Beta Was this translation helpful? Give feedback.
-
The API for that was added very recently: The GitHub BlogPackages: delete and restore for all packages - GitHub ChangelogPackages: delete and restore for all packages I’ve tried the API with a script to clean up old untagged versions, maybe you can get some inspiration from there: github.comairtower-luna/hello-ghcr/blob/e17ebc574711f4bcf85f8bd6b2380e226901778d/ghcr-prune.py
This file has been truncated. show original |
Beta Was this translation helpful? Give feedback.
-
That explains why I didn’t find it when I first checked. Looks like it’s still not possible to do this via the Docker (ghcr.io) API though. At least with the rest API I can do this alongside the other post-PR cleanup stuff. |
Beta Was this translation helpful? Give feedback.
-
If you need delete images by tag you can checkout our action github.combots-house/ghcr-delete-image-action♻️ Delete GitHub Container Registry image by tag. Contribute to bots-house/ghcr-delete-image-action development by creating an account on GitHub. |
Beta Was this translation helpful? Give feedback.
-
I can delete the image using the APIs, is there anyway to just delete the tag? |
Beta Was this translation helpful? Give feedback.
-
GHCR Pruning - GitHub MarketplaceGitHub Action to prune/delete container versions from GitHub Container Registry (ghcr.io) This action supports removing images by tags and also untagged images. |
Beta Was this translation helpful? Give feedback.
-
Looks like ghcr didn’t support delete the tag by api? I also take a look on above actions, it seems the “remove image by tag action” not only cleanup the tag, but also clean the package version. That means if a package version with multi-tags will also be removed. |
Beta Was this translation helpful? Give feedback.
-
Just stumbled over this:: This lists the names of containers like |
Beta Was this translation helpful? Give feedback.
-
@felfert do you mean you are able to delete tag with this kind of request?
I've tried to do same with an organization but have a 404
|
Beta Was this translation helpful? Give feedback.
-
You can try my custom action: |
Beta Was this translation helpful? Give feedback.
The API for that was added very recently:
The GitHub BlogPackages: delete and restore for all packages - GitHub Changelog
Packages: delete and restore for all packages
I’ve tried the API with a script to clean up old untagged versions, maybe you can get some inspiration from there:
github.comairtower-luna/hello-ghcr/blob/e17ebc574711f4bcf85f8bd6b2380e226901778d/ghcr-prune.py