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