Skip to content

Instantly share code, notes, and snippets.

@godber
Created February 19, 2025 21:20
Show Gist options
  • Save godber/ade4777fa8d5f185b170fcb5844b3434 to your computer and use it in GitHub Desktop.
Save godber/ade4777fa8d5f185b170fcb5844b3434 to your computer and use it in GitHub Desktop.
Example using the GHCR.IO registry to get Docker Image labels
#!/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"]'
@godber
Copy link
Author

godber commented Feb 19, 2025

Actually this command retrieves a specific label from the image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment