github.com/lafolle/docker@v1.6.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  )
     9  
    10  if ! docker inspect "${images[@]}" &> /dev/null; then
    11  	hardCodedDir='/docker-frozen-images'
    12  	if [ -d "$hardCodedDir" ]; then
    13  		( set -x; tar -cC "$hardCodedDir" . | docker load )
    14  	else
    15  		dir="$DEST/frozen-images"
    16  		# extract the exact "RUN download-frozen-image.sh" line from the Dockerfile itself for consistency
    17  		# NOTE: this will fail if either "curl" is not installed or if the Dockerfile is not available/readable
    18  		awk '
    19  			$1 == "RUN" && $2 == "./contrib/download-frozen-image.sh" {
    20  				for (i = 2; i < NF; i++)
    21  					printf ( $i == "'"$hardCodedDir"'" ? "'"$dir"'" : $i ) " ";
    22  				print $NF;
    23  				if (/\\$/) {
    24  					inCont = 1;
    25  					next;
    26  				}
    27  			}
    28  			inCont {
    29  				print;
    30  				if (!/\\$/) {
    31  					inCont = 0;
    32  				}
    33  			}
    34  		' Dockerfile | sh -x
    35  		( set -x; tar -cC "$dir" . | docker load )
    36  	fi
    37  fi