Last active
June 2, 2021 18:19
-
-
Save ake-persson/1ca682f258d4ab43569b5b550bc0e66e to your computer and use it in GitHub Desktop.
Revisions
-
Michael Persson revised this gist
Sep 17, 2016 . No changes.There are no files selected for viewing
-
Michael Persson revised this gist
Sep 17, 2016 . 1 changed file with 55 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,68 @@ #!/bin/bash set -eu reg="registry.hub.docker.com" repo="gliderlabs" image="alpine" name="${repo}/${image}" tag="latest" parallel=4 INFO="\033[1;32m" WARN="\033[0;33m" FATAL="\033[0;31m" CLEAR='\033[0m' info() { if [ -n "${QUIET:-}" ]; then return fi printf "* ${INFO}${1}${CLEAR}\n" } warn() { printf "! ${WARN}${1}${CLEAR}\n" } fatal() { printf "!! ${FATAL}${1}${CLEAR}\n" exit 1 } # Get auth token token=$( curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${name}:pull" | jq -r .token ) # Get layers resp=$(curl -s -H "Authorization: Bearer $token" "https://${reg}/v2/${name}/manifests/${tag}" | jq -r .fsLayers[].blobSum ) layers=( $( echo $resp | tr ' ' '\n' | sort -u ) ) prun() { while (( "$#" )); do for (( i=0; i<$parallel; i++ )); do if [ -n "${1:-}" ]; then if [ -f "${1}.tar.gz" ]; then checksum=$( shasum -a 256 $1.tar.gz | awk '{ print $1 }' ) if [ "$checksum" != "${1##sha256:}" ]; then warn "File exist checksum doesn't match, download again: ${1}.tar.gz" curl -s -o $1.tar.gz -L -H "Authorization: Bearer $token" "https://${reg}/v2/${name}/blobs/${1}" & else info "Skip file: ${1}.tar.gz" fi else info "Download: ${1}.tar.gz" curl -s -o $1.tar.gz -L -H "Authorization: Bearer $token" "https://${reg}/v2/${name}/blobs/${1}" & fi shift fi done wait done } prun ${layers[@]} # Run twice in-case of failure QUIET="true" prun ${layers[@]} -
Michael Persson created this gist
Sep 16, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ #!/bin/bash reg="registry.hub.docker.com" repo="gliderlabs" image="alpine" name="${repo}/${image}" tag="latest" # Get auth token token=$( curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${name}:pull" | jq -r .token ) echo "$token" # Get layers layers=$(curl -s -H "Authorization: Bearer $token" "https://${reg}/v2/${name}/manifests/${tag}" | jq -r .fsLayers[].blobSum ) # Download layers for layer in $layers; do curl -s -o $layer.tar.gz -L -H "Authorization: Bearer $token" "https://${reg}/v2/${name}/blobs/${layer}" done