Skip to content

Instantly share code, notes, and snippets.

@sajayantony
Last active October 12, 2021 22:45
Show Gist options
  • Save sajayantony/ddc32e8e19dd97f4355a7d1a3b9183fc to your computer and use it in GitHub Desktop.
Save sajayantony/ddc32e8e19dd97f4355a7d1a3b9183fc to your computer and use it in GitHub Desktop.

Downloading a tarball from ACR with anonymous access

  • Create a registry with anonymous access enabled.
export REGISTRY_NAME=sphere
export REGISTRY=${REGISTRY_NAME}".azurecr.io"
az acr create --name $REGISTRY_NAME  --sku Premium --resource-group test --location wcus
az acr update -n $REGISTRY_NAME --anonymous-pull-enabled true
  • Push something with oras (alphine rootfs for example)
export REPO=alphine-tar
export TAG=3.9

curl -LO http://dl-cdn.alpinelinux.org/alpine/v3.9/releases/x86_64/alpine-minirootfs-3.9.4-x86_64.tar.gz
az acr login -n $REGISTRY_NAME 

# oras push registry/repo:tag FILE_NAME:mediaType
oras push $REGISTRY/$REPO:$TAG ./alpine-minirootfs-3.9.4-x86_64.tar.gz:application/vnd.oci.image.layer.v1.tar+gzip
  • The following are the steps to download the files.
  1. Get Anonymous Token
  2. Get Manifest and digest of tarball from the manifest.
  3. Download tarball and extract
export TOKEN=$(curl -s "https://$REGISTRY/oauth2/token?scope=repository%3A$REPO%3Apull&service=$REGISTRY" | jq -r '.access_token')

export DIGEST=$(curl -s -H "Authorization: Bearer $TOKEN" -H 'Accept: application/vnd.oci.image.manifest.v1+json' https://$REGISTRY/v2/$REPO/manifests/$TAG | jq -r '.layers[0].digest')

export FILE_NAME=$(echo $DIGEST |  sed s/:/_/g)

#download and extract 
curl -v -L -o $FILE_NAME -H "Authorization: Bearer $TOKEN" https://$REGISTRY/v2/$REPO/blobs/$DIGEST
mkdir extract
tar -xvf $FILE_NAME -C ./extract
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment