Skip to content

Commit

Permalink
No need to get the manifest list, just use tag
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacome committed Jul 23, 2021
1 parent 86c726e commit 9fa663f
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions docker.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
#!/usr/bin/env bash

get_digest() {
local repo=$1
local tag=$2

manifestOutput=$(curl -H "Authorization: Bearer $(get_token $repo)" -H "Accept: application/vnd.docker.distribution.manifest.list.v2+json" "https://index.docker.io/v2/${repo}/manifests/${tag}" 2>/dev/null)

manifest_lists=$(jq -r '.manifests' <<<"$manifestOutput")

for manifest in $(jq -r '.[] | @text' <<<"$manifest_lists"); do
platform=$(jq -r '.platform.architecture' <<<"$manifest")
if [ $platform == "amd64" ]; then
echo $(jq -r '.digest' <<<"$manifest")
break
fi
done
}

get_layers() {
local repo=$1
local digest=$2

digestOutput=$(curl -H "Authorization: Bearer $(get_token $repo)" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" "https://index.docker.io/v2/${repo}/manifests/${digest}" 2>/dev/null)

jq -r '[.layers[].digest]' <<<$digestOutput
jq -r '[.layers[].digest]' <<<"$digestOutput"
}

get_token() {
Expand All @@ -34,10 +17,7 @@ get_token() {
IFS=: read base base_tag <<<$base
IFS=: read image image_tag <<<$image

digest_base=$(get_digest $base ${base_tag:-latest})
layers_base=$(get_layers $base $digest_base)

digest_image=$(get_digest $image ${image_tag:-latest})
layers_image=$(get_layers $image $digest_image)
layers_base=$(get_layers $base ${base_tag:-latest})
layers_image=$(get_layers $image ${image_tag:-latest})

jq '.base-.image | .!=[]' <<<"{\"base\": $layers_base, \"image\": $layers_image }"

0 comments on commit 9fa663f

Please sign in to comment.