github.com/shiroyuki/docker@v1.9.0/hack/make/.ensure-frozen-images (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  # this list should match roughly what's in the Dockerfile (minus the explicit image IDs, of course)
     5  images=(
     6  	busybox:latest
     7  	hello-world:frozen
     8  	jess/unshare:latest
     9  )
    10  
    11  if ! docker inspect "${images[@]}" &> /dev/null; then
    12  	hardCodedDir='/docker-frozen-images'
    13  	if [ -d "$hardCodedDir" ]; then
    14  		( set -x; tar -cC "$hardCodedDir" . | docker load )
    15  	else
    16  		dir="$DEST/frozen-images"
    17  		# extract the exact "RUN download-frozen-image.sh" line from the Dockerfile itself for consistency
    18  		# NOTE: this will fail if either "curl" is not installed or if the Dockerfile is not available/readable
    19  		awk '
    20  			$1 == "RUN" && $2 == "./contrib/download-frozen-image.sh" {
    21  				for (i = 2; i < NF; i++)
    22  					printf ( $i == "'"$hardCodedDir"'" ? "'"$dir"'" : $i ) " ";
    23  				print $NF;
    24  				if (/\\$/) {
    25  					inCont = 1;
    26  					next;
    27  				}
    28  			}
    29  			inCont {
    30  				print;
    31  				if (!/\\$/) {
    32  					inCont = 0;
    33  				}
    34  			}
    35  		' Dockerfile | sh -x
    36  		( set -x; tar -cC "$dir" . | docker load )
    37  	fi
    38  fi