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