@@ -17,8 +17,8 @@ get_manifests() {
17
17
local digest=$2
18
18
local token=$3
19
19
20
- manifest_list=$( curl -sSL -H " Authorization: Bearer $token " \
21
- -H " Accept: application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.oci.image.index.v1+json" \
20
+ manifest_list=$( curl -sSL --dump-header headers - H " Authorization: Bearer $token " \
21
+ -H " Accept: application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.oci.image.index.v1+json,application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.manifest.v1+json " \
22
22
" https://index.docker.io/v2/${repo} /manifests/${digest} " 2> /dev/null)
23
23
24
24
if jq -e -r ' .errors[0].code' <<< " $manifest_list" > /dev/null; then
@@ -27,6 +27,13 @@ get_manifests() {
27
27
error " Response from $repo \n code: $error_code \n message: $message "
28
28
fi
29
29
30
+ headers=$( cat headers | awk -F ' : ' ' {sub(/\r/,"\n",$2); print $1","$2}' | grep ' docker-content-digest\|content-type' | jq -R ' split(",") | {(if .[0] == "content-type" then "type" else "digest" end): .[1]}' | jq -s ' reduce .[] as $item ({}; . * $item)' )
31
+ manifest_v2=$( jq -r ' . | select(.type == "application/vnd.docker.distribution.manifest.v2+json" or .type == "application/vnd.oci.image.manifest.v1+json") | [{digest: .digest, platform: "linux/amd64"}]' <<< " $headers" )
32
+ if [ ! -z " $manifest_v2 " ]; then
33
+ echo " $manifest_v2 "
34
+ return
35
+ fi
36
+
30
37
jq -r ' [.manifests[] | select(.platform.architecture | contains ("unknown") | not) | {digest: .digest, platform: (.platform.os +"/"+ .platform.architecture)}]' <<< " $manifest_list"
31
38
32
39
}
@@ -37,7 +44,7 @@ get_layers() {
37
44
local token=$3
38
45
39
46
digestOutput=$( curl -sSL -H " Authorization: Bearer $token " \
40
- -H " Accept: application/vnd.docker.distribution.manifest.v1 +json,application/vnd.oci.image.manifest.v1+json" \
47
+ -H " Accept: application/vnd.docker.distribution.manifest.v2 +json,application/vnd.oci.image.manifest.v1+json" \
41
48
" https://index.docker.io/v2/${repo} /manifests/${digest} " 2> /dev/null)
42
49
43
50
if jq -e -r ' .errors[0].code' <<< " $digestOutput" > /dev/null; then
@@ -102,7 +109,7 @@ manifests_image=$(get_manifests $image_repo ${image_tag:-latest} $image_token)
102
109
103
110
diff=false
104
111
# loop through plafforms split by comma
105
- for platform in $( echo $platforms | tr ' ,' ' ' ) ; do
112
+ for platform in $( echo $platforms | tr -s ' ,' ' ' ) ; do
106
113
# get the digest for the platform
107
114
digest_base=$( jq -r " .[] | select(.platform == \" $platform \" ) | .digest" <<< " $manifests_base" )
108
115
0 commit comments