Skip to content

Instantly share code, notes, and snippets.

@msva
Forked from eggplants/ghcr.sh
Created November 11, 2024 10:47
Show Gist options
  • Save msva/e5bca4f794a7dbb6c549df62bb47dde7 to your computer and use it in GitHub Desktop.
Save msva/e5bca4f794a7dbb6c549df62bb47dde7 to your computer and use it in GitHub Desktop.
How to get information from ghcr Docker Registry HTTP API V2 with curl
#!/usr/bin/env bash
# ref: https://git.521000.bestmunity/t/how-to-check-if-a-container-image-exists-on-ghcr/154836/3
# public image's {USER}/{IMAGE}
USER_IMAGE=eggplants/asciiquarium-docker
# get token ('{"token":"***"}' -> '***')
TOKEN="$(
curl "https://ghcr.io/token?scope=repository:${USER_IMAGE}:pull" |
awk -F'"' '$0=$4'
)"
_curl(){ curl -H "Authorization: Bearer ${TOKEN}" "$1" }
# get tags
_curl "https://ghcr.io/v2/${USER_IMAGE}/tags/list"
# get manifest of the latest image
_curl "https://ghcr.io/v2/${USER_IMAGE}/manifests/latest"
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"schemaVersion": 2,
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"digest": "sha256:fb4552eacdc8e01082f87bae6a0fec6e1b61630f0a1e5a0e6a699d05ff0337fd",
"size": 5551
},
"layers": [
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"digest": "sha256:4be315f6562fccf08fd6c749557e31e45ab6d987370e20e2c4933ddb04ddd5ff",
"size": 27140664
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"digest": "sha256:f6722131500bb303e9a66464a1d7a3805efaa2db3715d5204f5bdb89656a0589",
"size": 200
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"digest": "sha256:ac65630ca76f500df10c4676ec0fe8623070f1ab3394b8c2f4c6db4a48ebfa6c",
"size": 14894913
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"digest": "sha256:380348d1c396f3eb3c542ccc62b73383297b6a48b625f9671f59c109d964954e",
"size": 43915124
},
{
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
"digest": "sha256:49470ea4d7663bcafd377eeeeda4d15445b09043f2dbf7d5f2865a66fbadcc44",
"size": 604613
}
]
}
{"name":"eggplants/asciiquarium-docker","tags":["0.0.0","0.0","latest"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment