Signed-off-by: Alexander Midlash <amidlash@docker.com>
| ... | ... |
@@ -44,6 +44,17 @@ if [ "$(go env GOHOSTOS)" = 'windows' ]; then |
| 44 | 44 |
fi |
| 45 | 45 |
fi |
| 46 | 46 |
|
| 47 |
+fetch_blob() {
|
|
| 48 |
+ url=$1 |
|
| 49 |
+ token=$2 |
|
| 50 |
+ dest=$3 |
|
| 51 |
+ echo "Attempting to download blob $url" |
|
| 52 |
+ target=$(curl -sS -v -H "Authorization: Bearer $token" "$url" 2>&1 | grep "Location:" | sed 's/< Location: \(.*\)\r/\1/') |
|
| 53 |
+ # curl blob (exclude auth token) |
|
| 54 |
+ curl -fsS --progress "${target}" -o "$dest"
|
|
| 55 |
+} |
|
| 56 |
+ |
|
| 57 |
+ |
|
| 47 | 58 |
while [ $# -gt 0 ]; do |
| 48 | 59 |
imageTag="$1" |
| 49 | 60 |
shift |
| ... | ... |
@@ -87,10 +98,7 @@ while [ $# -gt 0 ]; do |
| 87 | 87 |
imageId="${configDigest#*:}" # strip off "sha256:"
|
| 88 | 88 |
|
| 89 | 89 |
configFile="$imageId.json" |
| 90 |
- curl -fsSL \ |
|
| 91 |
- -H "Authorization: Bearer $token" \ |
|
| 92 |
- "https://registry-1.docker.io/v2/$image/blobs/$configDigest" \ |
|
| 93 |
- -o "$dir/$configFile" |
|
| 90 |
+ fetch_blob "https://registry-1.docker.io/v2/$image/blobs/$configDigest" $token "$dir/$configFile" |
|
| 94 | 91 |
|
| 95 | 92 |
layersFs="$(echo "$manifestJson" | jq --raw-output --compact-output '.layers[]')" |
| 96 | 93 |
IFS="$newlineIFS" |
| ... | ... |
@@ -158,10 +166,7 @@ while [ $# -gt 0 ]; do |
| 158 | 158 |
continue |
| 159 | 159 |
fi |
| 160 | 160 |
token="$(curl -fsSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$image:pull" | jq --raw-output '.token')" |
| 161 |
- curl -fSL --progress \ |
|
| 162 |
- -H "Authorization: Bearer $token" \ |
|
| 163 |
- "https://registry-1.docker.io/v2/$image/blobs/$layerDigest" \ |
|
| 164 |
- -o "$dir/$layerTar" |
|
| 161 |
+ fetch_blob "https://registry-1.docker.io/v2/$image/blobs/$layerDigest" $token "$dir/$layerTar" |
|
| 165 | 162 |
;; |
| 166 | 163 |
|
| 167 | 164 |
*) |
| ... | ... |
@@ -231,7 +236,8 @@ while [ $# -gt 0 ]; do |
| 231 | 231 |
continue |
| 232 | 232 |
fi |
| 233 | 233 |
token="$(curl -fsSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$image:pull" | jq --raw-output '.token')" |
| 234 |
- curl -fSL --progress -H "Authorization: Bearer $token" "https://registry-1.docker.io/v2/$image/blobs/$imageLayer" -o "$dir/$layerId/layer.tar" # -C - |
|
| 234 |
+ # find redirect using token: |
|
| 235 |
+ fetch_blob "https://registry-1.docker.io/v2/$image/blobs/$imageLayer" $token "$dir/$layerId/layer.tar" |
|
| 235 | 236 |
done |
| 236 | 237 |
;; |
| 237 | 238 |
|