Browse code

Fix downloading image fails when build docker

Generate a token for each download process to avoid token expired.

Closes: #33441

Signed-off-by: vanderliang <lansheng@meili-inc.com>

vanderliang authored on 2017/05/31 15:18:42
Showing 1 changed files
... ...
@@ -157,6 +157,7 @@ while [ $# -gt 0 ]; do
157 157
 									echo "skipping existing ${layerId:0:12}"
158 158
 									continue
159 159
 								fi
160
+								token="$(curl -fsSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$image:pull" | jq --raw-output '.token')"
160 161
 								curl -fSL --progress \
161 162
 									-H "Authorization: Bearer $token" \
162 163
 									"https://registry-1.docker.io/v2/$image/blobs/$layerDigest" \
... ...
@@ -229,6 +230,7 @@ while [ $# -gt 0 ]; do
229 229
 					echo "skipping existing ${layerId:0:12}"
230 230
 					continue
231 231
 				fi
232
+				token="$(curl -fsSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$image:pull" | jq --raw-output '.token')"
232 233
 				curl -fSL --progress -H "Authorization: Bearer $token" "https://registry-1.docker.io/v2/$image/blobs/$imageLayer" -o "$dir/$layerId/layer.tar" # -C -
233 234
 			done
234 235
 			;;