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