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 <admwiggin@gmail.com>
Signed-off-by: Jimbo Jones <jjjimbo137@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
jjimbo137
2024-09-19 14:53:53 -04:00
committed by Sebastiaan van Stijn
parent c7e42d855e
commit 98d74e3a3c

View File

@@ -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' \