@@ -186,6 +186,22 @@ handle_single_manifest_v2() {
186186 fetch_blob " $token " " $image " " $layerDigest " " $dir /$layerTar " --progress-bar
187187 ;;
188188
189+ application/vnd.oci.image.layer.v1.tar+gzip)
190+ local layerTar=" $layerId /layer.tar.gz"
191+ layerFiles=(" ${layerFiles[@]} " " $layerTar " )
192+ # TODO figure out why "-C -" doesn't work here
193+ # "curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume."
194+ # "HTTP/1.1 416 Requested Range Not Satisfiable"
195+ if [ -f " $dir /$layerTar " ]; then
196+ # TODO hackpatch for no -C support :'(
197+ echo " skipping existing ${layerId: 0: 12} "
198+ continue
199+ fi
200+ local token
201+ token=" $( curl -fsSL " $authBase /token?service=$authService &scope=repository:$image :pull" | jq --raw-output ' .token' ) "
202+ fetch_blob " $token " " $image " " $layerDigest " " $dir /$layerTar " --progress-bar
203+ ;;
204+
189205 * )
190206 echo >&2 " error: unknown layer mediaType ($imageIdentifier , $layerDigest ): '$layerMediaType '"
191207 exit 1
@@ -203,10 +219,10 @@ handle_single_manifest_v2() {
203219
204220 local manifestJsonEntry
205221 manifestJsonEntry=" $(
206- echo ' {}' | jq --raw-output ' . + {
222+ echo ' {}' | jq -rjc ' . + {
207223 Config: "' " $configFile " ' ",
208224 RepoTags: ["' " ${image# library\/ } :$tag " ' "],
209- Layers: ' " $( echo ' []' | jq --raw-output " .$( for layerFile in " ${layerFiles[@]} " ; do echo " + [ \" $layerFile \" ]" ; done) " ) " '
225+ Layers: ' " $( echo ' []' | jq -rjc " .$( for layerFile in " ${layerFiles[@]} " ; do echo " + [ \" $layerFile \" ]" ; done) " ) " '
210226 }'
211227 ) "
212228 manifestJsonEntries=(" ${manifestJsonEntries[@]} " " $manifestJsonEntry " )
@@ -301,6 +317,7 @@ while [ $# -gt 0 ]; do
301317 -H ' Accept: application/vnd.docker.distribution.manifest.v2+json' \
302318 -H ' Accept: application/vnd.docker.distribution.manifest.list.v2+json' \
303319 -H ' Accept: application/vnd.docker.distribution.manifest.v1+json' \
320+ -H ' Accept: application/vnd.oci.image.manifest.v1+json' \
304321 " $registryBase /v2/$image /manifests/$digest "
305322 ) "
306323 if [ " ${manifestJson: 0: 1} " != ' {' ]; then
@@ -355,6 +372,42 @@ while [ $# -gt 0 ]; do
355372 exit 1
356373 fi
357374 ;;
375+ application/vnd.oci.image.manifest.v1+json)
376+ handle_single_manifest_v2 " $manifestJson "
377+ ;;
378+ application/vnd.oci.image.index.v1+json)
379+ layersFs=" $( echo " $manifestJson " | jq --raw-output --compact-output ' .manifests[]' ) "
380+ IFS=" $newlineIFS "
381+ mapfile -t layers <<< " $layersFs"
382+ unset IFS
383+
384+ found=" "
385+ targetArch=" $( get_target_arch) "
386+ targetVariant=" $( get_target_variant) "
387+ # parse first level multi-arch manifest
388+ for i in " ${! layers[@]} " ; do
389+ layerMeta=" ${layers[$i]} "
390+ maniArch=" $( echo " $layerMeta " | jq --raw-output ' .platform.architecture' ) "
391+ maniVariant=" $( echo " $layerMeta " | jq --raw-output ' .platform.variant' ) "
392+ if [[ " $maniArch " = " ${targetArch} " ]] && [[ -z " ${targetVariant} " || " $maniVariant " = " ${targetVariant} " ]]; then
393+ digest=" $( echo " $layerMeta " | jq --raw-output ' .digest' ) "
394+ # get second level single manifest
395+ submanifestJson=" $(
396+ curl -fsSL \
397+ -H " Authorization: Bearer $token " \
398+ -H ' Accept: application/vnd.oci.image.manifest.v1+json' \
399+ " $registryBase /v2/$image /manifests/$digest "
400+ ) "
401+ handle_single_manifest_v2 " $submanifestJson "
402+ found=" found"
403+ break
404+ fi
405+ done
406+ if [ -z " $found " ]; then
407+ echo >&2 " error: manifest for ${targetArch}${targetVariant: +/ ${targetVariant} } is not found"
408+ exit 1
409+ fi
410+ ;;
358411 * )
359412 echo >&2 " error: unknown manifest mediaType ($imageIdentifier ): '$mediaType '"
360413 exit 1
@@ -434,7 +487,7 @@ echo -n $'\n}\n' >> "$dir/repositories"
434487rm -f " $dir " /tags-* .tmp
435488
436489if [ -z " $doNotGenerateManifestJson " ] && [ " ${# manifestJsonEntries[@]} " -gt 0 ]; then
437- echo ' []' | jq --raw-output " .$( for entry in " ${manifestJsonEntries[@]} " ; do echo " + [ $entry ]" ; done) " > " $dir /manifest.json"
490+ echo ' []' | jq -r " .$( for entry in " ${manifestJsonEntries[@]} " ; do echo " + [ $entry ]" ; done) " > " $dir /manifest.json"
438491else
439492 rm -f " $dir /manifest.json"
440493fi
0 commit comments