Skip to content

Instantly share code, notes, and snippets.

@northtyphoon
Last active December 23, 2022 21:54
Show Gist options
  • Save northtyphoon/3dffcee1d06de15177800f4a7697def0 to your computer and use it in GitHub Desktop.
Save northtyphoon/3dffcee1d06de15177800f4a7697def0 to your computer and use it in GitHub Desktop.
#!/bin/bash

# Prerequisite
# 1) Install curl, jq

token_name="mytokenname"
token_password="mytokenpassword"
repo="hello-world"
tag="latest"
registry="myregistry.azurecr.io"
accept_header="Accept: application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.oci.image.index.v1+json, application/vnd.oci.artifact.manifest.v1+json, application/vnd.cncf.oras.artifact.manifest.v1+json, */*"

scope="repository:$repo:pull"
acr_credential=$(echo -n "$token_name:$token_password" | base64 -w0)
acr_access_token=$(curl -H "Authorization: Basic $acr_credential" "https://$registry/oauth2/token?service=$registry&scope=$scope" | jq -r ".access_token")
layers=$(curl -H "Authorization: Bearer $acr_access_token" -H "$accept_header" https://$registry/v2/$repo/manifests/$tag | jq -r ".config.digest, .layers[].digest, .blobs[].digest")

for layer in $layers; do
  echo "------downloading $layer--------"
  curl -L -H "Authorization: Bearer $acr_access_token" https://$registry/v2/$repo/blobs/$layer > /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment