Deleting temporary docker images from ghcr.io using actions

We use a github action to automatically build and deploy an image on creation and updating of a PR, so that we can test the running code imemdiately. We host the images on github container registry for now.

The images are tagged with the pr-number as such:

: pr-{{ github.event.number }}-{{ steps.short-sha.outputs.short-sha }} #short-sha is computed earlier

so that they are like myPackage:pr-1-be12a4f

these accumulate quite quickly, so that I am wondering how we can trigger deletion of all images tagged with pr-1-xxxxxxx within a workflow when an action is triggered on pull_request: closed

so far this is a manual option from the GUI and that’s time consuming to say the least.

2 Likes

I tried using skopeo delete --creds 'docwhat:PATSEKRET' docker://ghcr.io/... with a PAT with delete:package:

$ skopeo delete docker://ghcr.io/docwhat/blog:sha-be6ac34c
FATA[0000] Failed to delete /v2/docwhat/blog/manifests/sha256:8ada6a8bfd29e8f8c2af7c9637e76889adca0744b2715f8175828e0220873012: {"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}
 (405 Method Not Allowed)

The web UI is painful to delete more than one or two images.