Created
March 27, 2024 00:18
-
-
Save ahachete/8e9255bbd3834d7f3b0ad7c0cbb6069f to your computer and use it in GitHub Desktop.
A simple script to demonstrate how to fetch and unpack a container image from a registry. Used here with the latest version of the Postgres image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
TOKEN=$( curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/postgres:pull" \ | |
| jq -r .token ) | |
MANIFEST_INDEX=$( curl -s -H "Authorization: Bearer $TOKEN" \ | |
https://registry-1.docker.io/v2/library/postgres/manifests/latest ) | |
AMD64_MANIFEST_DIGEST=$( echo $MANIFEST_INDEX \ | |
|jq -r '.manifests[] | select(.platform.architecture == "amd64") .digest' ) | |
AMD64_MANIFEST=$( curl -s -H "Authorization: Bearer $TOKEN" \ | |
-H "Accept: application/vnd.oci.image.manifest.v1+json" \ | |
https://registry-1.docker.io/v2/library/postgres/manifests/$AMD64_MANIFEST_DIGEST ) | |
LAYERS=$( echo $AMD64_MANIFEST \ | |
|jq -r '.layers[] | select(.mediaType == "application/vnd.oci.image.layer.v1.tar+gzip") .digest' ) | |
tempfile=/tmp/$(date +%N) | |
mkdir $tempfile | |
cd $tempfile | |
for layer in $LAYERS | |
do | |
curl -s -H "Authorization: Bearer $TOKEN" --location \ | |
https://registry-1.docker.io/v2/library/postgres/blobs/$layer \ | |
| tar xzf - | |
done | |
echo "Image unpackaged at $tempfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment