Created
February 19, 2025 21:20
-
-
Save godber/ade4777fa8d5f185b170fcb5844b3434 to your computer and use it in GitHub Desktop.
Example using the GHCR.IO registry to get Docker Image labels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
IMAGE="terascope/node-base" | |
TAG="22" | |
TOKEN=$(curl -sS https://ghcr.io/token\?scope\="repository:${IMAGE}:pull" | jq -r .token) | |
# echo $TOKEN | |
# get digest of 'amd64' image | |
DIGEST=$(curl -s -H "Authorization: Bearer ${TOKEN}" \ | |
-H "Accept: application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.v2+json" \ | |
https://ghcr.io/v2/$IMAGE/manifests/${TAG} | jq -r '.manifests[] | select(.platform.architecture=="amd64") | .digest') | |
# echo $DIGEST | |
CONFIG_DIGEST=$(curl -s -H "Authorization: Bearer ${TOKEN}" \ | |
-H "Accept: application/vnd.oci.image.manifest.v1+json" \ | |
https://ghcr.io/v2/${IMAGE}/manifests/${DIGEST} | jq -r .config.digest) | |
# echo $CONFIG_DIGEST | |
curl -s -L -H "Authorization: Bearer $TOKEN" \ | |
-H "Accept: application/vnd.oci.image.config.v1+json" \ | |
https://ghcr.io/v2/${IMAGE}/blobs/${CONFIG_DIGEST} | jq -r '.config.Labels.["io.terascope.image.node_version"]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually this command retrieves a specific label from the image.