Browse code

Refactor busybox downloading as generic "frozen-images"

This makes it much simpler to add new "frozen" images -- simply add them to the `Dockerfile` and in `hack/make/.ensure-frozen-images` and you're off to the races.

Signed-off-by: Andrew "Tianon" Page <admwiggin@gmail.com>

Tianon Gravi authored on 2015/03/07 10:12:41
Showing 5 changed files
... ...
@@ -142,9 +142,11 @@ ENV DOCKER_BUILDTAGS apparmor selinux btrfs_noversion
142 142
 # Let us use a .bashrc file
143 143
 RUN ln -sfv $PWD/.bashrc ~/.bashrc
144 144
 
145
-# Get the "busybox" image so we can "docker load" locally instead of pulling
145
+# Get useful and necessary Hub images so we can "docker load" locally instead of pulling
146 146
 COPY contrib/download-frozen-image.sh /go/src/github.com/docker/docker/contrib/
147
-RUN ./contrib/download-frozen-image.sh /docker-busybox busybox@4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
147
+RUN ./contrib/download-frozen-image.sh /docker-frozen-images \
148
+	busybox:latest@4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
149
+# see also "hack/make/.ensure-frozen-images" (which needs to be updated any time this list is)
148 150
 
149 151
 # Install man page generator
150 152
 COPY vendor /go/src/github.com/docker/docker/vendor
... ...
@@ -60,7 +60,7 @@ while [ $# -gt 0 ]; do
60 60
 		mkdir -p "$dir/$imageId"
61 61
 		echo '1.0' > "$dir/$imageId/VERSION"
62 62
 		
63
-		curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$imageId/json" -o "$dir/$imageId/json" -C -
63
+		curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$imageId/json" -o "$dir/$imageId/json"
64 64
 		
65 65
 		# TODO figure out why "-C -" doesn't work here
66 66
 		# "curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume."
67 67
deleted file mode 100644
... ...
@@ -1,21 +0,0 @@
1
-#!/bin/bash
2
-set -e
3
-
4
-if ! docker inspect busybox &> /dev/null; then
5
-	hardCodedDir='/docker-busybox'
6
-	if [ -d "$hardCodedDir" ]; then
7
-		( set -x; tar -cC "$hardCodedDir" . | docker load )
8
-	elif [ -e Dockerfile ] && command -v curl > /dev/null; then
9
-		# testing for "curl" because "download-frozen-image.sh" is built around curl
10
-		dir="$DEST/busybox"
11
-		# extract the exact "download-frozen-image.sh" line from the Dockerfile itself for consistency
12
-		awk '$1 == "RUN" && $2 == "./contrib/download-frozen-image.sh" && /busybox@/ {
13
-			for (i = 2; i < NF; i++)
14
-				printf ( $i == "'"$hardCodedDir"'" ? "'"$dir"'" : $i ) " ";
15
-			print $NF;
16
-		}' Dockerfile | sh -x
17
-		( set -x; tar -cC "$dir" . | docker load )
18
-	else
19
-		( set -x; docker pull busybox )
20
-	fi
21
-fi
22 1
new file mode 100644
... ...
@@ -0,0 +1,42 @@
0
+#!/bin/bash
1
+set -e
2
+
3
+# this list should match roughly what's in the Dockerfile (minus the explicit image IDs, of course)
4
+images=(
5
+	busybox:latest
6
+)
7
+
8
+if ! docker inspect "${images[@]}" &> /dev/null; then
9
+	hardCodedDir='/docker-frozen-images'
10
+	if [ -d "$hardCodedDir" ]; then
11
+		( set -x; tar -cC "$hardCodedDir" . | docker load )
12
+	elif [ -e Dockerfile ] && command -v curl > /dev/null; then
13
+		# testing for "curl" because "download-frozen-image.sh" is built around curl
14
+		dir="$DEST/frozen-images"
15
+		# extract the exact "RUN download-frozen-image.sh" line from the Dockerfile itself for consistency
16
+		awk '
17
+			$1 == "RUN" && $2 == "./contrib/download-frozen-image.sh" {
18
+				for (i = 2; i < NF; i++)
19
+					printf ( $i == "'"$hardCodedDir"'" ? "'"$dir"'" : $i ) " ";
20
+				print $NF;
21
+				if (/\\$/) {
22
+					inCont = 1;
23
+					next;
24
+				}
25
+			}
26
+			inCont {
27
+				print;
28
+				if (!/\\$/) {
29
+					inCont = 0;
30
+				}
31
+			}
32
+		' Dockerfile | sh -x
33
+		( set -x; tar -cC "$dir" . | docker load )
34
+	else
35
+		for image in "${images[@]}"; do
36
+			if ! docker inspect "$image" &> /dev/null; then
37
+				( set -x; docker pull "$image" )
38
+			fi
39
+		done
40
+	fi
41
+fi
... ...
@@ -16,7 +16,7 @@ bundle_test_integration_cli() {
16 16
 	# even and especially on test failures
17 17
 	didFail=
18 18
 	if ! {
19
-		source "$(dirname "$BASH_SOURCE")/.ensure-busybox"
19
+		source "$(dirname "$BASH_SOURCE")/.ensure-frozen-images"
20 20
 		source "$(dirname "$BASH_SOURCE")/.ensure-httpserver"
21 21
 		source "$(dirname "$BASH_SOURCE")/.ensure-emptyfs"
22 22