From 98d74e3a3c778eb20ffdb677859f18a9c9814b57 Mon Sep 17 00:00:00 2001 From: jjimbo137 <115816493+jjimbo137@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:53:53 -0400 Subject: [PATCH] Update download-frozen-image-v2.sh added OCI v1 support Shortened to minimum code because OCI v1 is essentially equivalent to Docker v2.2 format. Also fixed formatting issue with jq where it wouldn't accept newline character in chained jq commands. Co-authored-by: Tianon Gravi Signed-off-by: Jimbo Jones Signed-off-by: Sebastiaan van Stijn --- contrib/download-frozen-image-v2.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/contrib/download-frozen-image-v2.sh b/contrib/download-frozen-image-v2.sh index 86f26e42c3..e4abca2f6a 100755 --- a/contrib/download-frozen-image-v2.sh +++ b/contrib/download-frozen-image-v2.sh @@ -170,7 +170,7 @@ handle_single_manifest_v2() { fi case "$layerMediaType" in - application/vnd.docker.image.rootfs.diff.tar.gzip) + application/vnd.oci.image.layer.v1.tar+gzip | application/vnd.docker.image.rootfs.diff.tar.gzip) local layerTar="$layerId/layer.tar" layerFiles=("${layerFiles[@]}" "$layerTar") # TODO figure out why "-C -" doesn't work here @@ -203,10 +203,10 @@ handle_single_manifest_v2() { local manifestJsonEntry manifestJsonEntry="$( - echo '{}' | jq --raw-output '. + { + echo '{}' | jq --raw-output --compact-output '. + { Config: "'"$configFile"'", RepoTags: ["'"${image#library\/}:$tag"'"], - Layers: '"$(echo '[]' | jq --raw-output ".$(for layerFile in "${layerFiles[@]}"; do echo " + [ \"$layerFile\" ]"; done)")"' + Layers: '"$(echo '[]' | jq --raw-output --compact-output ".$(for layerFile in "${layerFiles[@]}"; do echo " + [ \"$layerFile\" ]"; done)")"' }' )" manifestJsonEntries=("${manifestJsonEntries[@]}" "$manifestJsonEntry") @@ -298,6 +298,8 @@ while [ $# -gt 0 ]; do manifestJson="$( curl -fsSL \ -H "Authorization: Bearer $token" \ + -H 'Accept: application/vnd.oci.image.manifest.v1+json' \ + -H 'Accept: application/vnd.oci.image.index.v1+json' \ -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \ -H 'Accept: application/vnd.docker.distribution.manifest.list.v2+json' \ -H 'Accept: application/vnd.docker.distribution.manifest.v1+json' \ @@ -317,10 +319,10 @@ while [ $# -gt 0 ]; do mediaType="$(echo "$manifestJson" | jq --raw-output '.mediaType')" case "$mediaType" in - application/vnd.docker.distribution.manifest.v2+json) + application/vnd.oci.image.manifest.v1+json | application/vnd.docker.distribution.manifest.v2+json) handle_single_manifest_v2 "$manifestJson" ;; - application/vnd.docker.distribution.manifest.list.v2+json) + application/vnd.oci.image.index.v1+json | application/vnd.docker.distribution.manifest.list.v2+json) layersFs="$(echo "$manifestJson" | jq --raw-output --compact-output '.manifests[]')" IFS="$newlineIFS" mapfile -t layers <<< "$layersFs" @@ -340,6 +342,8 @@ while [ $# -gt 0 ]; do submanifestJson="$( curl -fsSL \ -H "Authorization: Bearer $token" \ + -H 'Accept: application/vnd.oci.image.manifest.v1+json' \ + -H 'Accept: application/vnd.oci.image.index.v1+json' \ -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' \ -H 'Accept: application/vnd.docker.distribution.manifest.list.v2+json' \ -H 'Accept: application/vnd.docker.distribution.manifest.v1+json' \