Skip to main content
ertius.org

listing tags on GitHub Container Registry aka GHCR

Now that Debian Trixie is out and thus stable has podman's quadlets, I've been converting some Ansible manifests over, and so also noticed that I hadn't hard set all containers to a particular version; some were just using :latest. Never one to just do the thing, let's fix that.

DockerHub is of course annoying, but it at least makes it easy to see what tags an image has. For GHCR, I couldn't find such an easy view, but I did find this, which becomes this shell function:

ghcr-list-tags() {
  if [[ $# -ne 1 ]]; then
    echo "Usage: ghcr-list-tags someuser/someimage"
    return 1
  fi
  # -r is so jq unquotes the token, so it's bare when we put it in the next curl call
  token=$(curl -s https://ghcr.io/token\?scope\="repository:$1:pull" | jq -r .token)
  tags=$(curl -s -H "Authorization: Bearer $token" https://ghcr.io/v2/$1/tags/list | jq -r .tags)
  echo "$tags"
}

As a highly proficient bash hacker, these ten lines took me a mere 20 minutes to get correct.