Created
May 24, 2017 14:09
-
-
Save cirocosta/fb6b90cb7651ff21eda4838a73e3710b to your computer and use it in GitHub Desktop.
Retrieve image configuration from Docker Hub Registry
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
#!/bin/bash | |
set -o errexit | |
main() { | |
check_args "$@" | |
local image=$1 | |
local tag=$2 | |
local token=$(get_token $image) | |
local digest=$(get_digest $image $tag $token) | |
get_image_configuration $image $token $digest | |
} | |
get_image_configuration() { | |
local image=$1 | |
local token=$2 | |
local digest=$3 | |
echo "Retrieving Image Configuration. | |
IMAGE: $image | |
TOKEN: $token | |
DIGEST: $digest | |
" >&2 | |
curl \ | |
--silent \ | |
--location \ | |
--header "Authorization: Bearer $token" \ | |
"https://registry-1.docker.io/v2/$image/blobs/$digest" \ | |
| jq -r '.container_config' | |
} | |
get_token() { | |
local image=$1 | |
echo "Retrieving Docker Hub token. | |
IMAGE: $image | |
" >&2 | |
curl \ | |
--silent \ | |
"https://auth.docker.io/token?scope=repository:$image:pull&service=registry.docker.io" \ | |
| jq -r '.token' | |
} | |
get_digest() { | |
local image=$1 | |
local tag=$2 | |
local token=$3 | |
echo "Retrieving image digest. | |
IMAGE: $image | |
TAG: $tag | |
TOKEN: $token | |
" >&2 | |
curl \ | |
--silent \ | |
--header "Accept: application/vnd.docker.distribution.manifest.v2+json" \ | |
--header "Authorization: Bearer $token" \ | |
"https://registry-1.docker.io/v2/$image/manifests/$tag" \ | |
| jq -r '.config.digest' | |
} | |
check_args() { | |
if (($# != 2)); then | |
echo "Error: | |
Two arguments must be provided - $# provided. | |
Usage: | |
./get-image-config.sh <image> <tag> | |
Aborting." | |
exit 1 | |
fi | |
} | |
main "$@" |
Author
cirocosta
commented
May 24, 2017
Thank you, you saved my day. 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment