github.com/endocode/docker@v1.4.2-0.20160113120958-46eb4700391e/hack/make/.ensure-frozen-images (about) 1 #!/bin/bash 2 set -e 3 4 # image list should match what's in the Dockerfile (minus the explicit images IDs) 5 images=( 6 busybox:latest 7 debian:jessie 8 hello-world:latest 9 ) 10 11 imagePrefix= 12 case "$DOCKER_ENGINE_OSARCH" in 13 linux/arm) 14 imagePrefix='armhf' 15 ;; 16 linux/ppc64le) 17 imagePrefix='ppc64le' 18 ;; 19 linux/s390x) 20 imagePrefix='s390x' 21 ;; 22 esac 23 24 if [ "$imagePrefix" ]; then 25 for (( i = 0; i < ${#images[@]}; i++ )); do 26 images[$i]="$imagePrefix/${images[$i]}" 27 done 28 fi 29 30 if ! docker inspect "${images[@]}" &> /dev/null; then 31 hardCodedDir='/docker-frozen-images' 32 if [ -d "$hardCodedDir" ]; then 33 # Do not use a subshell for the following command. Windows CI 34 # runs bash 3.x so will not trap an error in a subshell. 35 # http://stackoverflow.com/questions/22630363/how-does-set-e-work-with-subshells 36 set -x; tar -cC "$hardCodedDir" . | docker load; set +x 37 else 38 dir="$DEST/frozen-images" 39 # extract the exact "RUN download-frozen-image-v2.sh" line from the Dockerfile itself for consistency 40 # NOTE: this will fail if either "curl" or "jq" is not installed or if the Dockerfile is not available/readable 41 awk ' 42 $1 == "RUN" && $2 == "./contrib/download-frozen-image-v2.sh" { 43 for (i = 2; i < NF; i++) 44 printf ( $i == "'"$hardCodedDir"'" ? "'"$dir"'" : $i ) " "; 45 print $NF; 46 if (/\\$/) { 47 inCont = 1; 48 next; 49 } 50 } 51 inCont { 52 print; 53 if (!/\\$/) { 54 inCont = 0; 55 } 56 } 57 ' "${DOCKERFILE:=Dockerfile}" | sh -x 58 # Do not use a subshell for the following command. Windows CI 59 # runs bash 3.x so will not trap an error in a subshell. 60 # http://stackoverflow.com/questions/22630363/how-does-set-e-work-with-subshells 61 set -x; tar -cC "$dir" . | docker load; set +x 62 fi 63 fi 64 65 if [ "$imagePrefix" ]; then 66 for image in "${images[@]}"; do 67 target="${image#$imagePrefix/}" 68 if [ "$target" != "$image" ]; then 69 # tag images to ensure that all integrations work with the defined image names 70 docker tag "$image" "$target" 71 # then remove original tags as these make problems with later tests (e.g., TestInspectApiImageResponse) 72 docker rmi "$image" 73 fi 74 done 75 fi 76 77 # explicitly rename "hello-world:latest" to ":frozen" for the test that uses it 78 docker tag hello-world:latest hello-world:frozen 79 docker rmi hello-world:latest