This downloads a specific image ID of `busybox:latest` from the Hub directly (within the `Dockerfile`, ready for `docker load`) instead of grabbing the source from GitHub and doing a `docker build` at daemon start time. This ensures the test suite runs more consistently.
Signed-off-by: Andrew "Tianon" Page <admwiggin@gmail.com>
... | ... |
@@ -107,9 +107,6 @@ RUN go get golang.org/x/tools/cmd/cover |
107 | 107 |
# TODO replace FPM with some very minimal debhelper stuff |
108 | 108 |
RUN gem install --no-rdoc --no-ri fpm --version 1.3.2 |
109 | 109 |
|
110 |
-# Get the "busybox" image source so we can build locally instead of pulling |
|
111 |
-RUN git clone -b buildroot-2014.02 https://github.com/jpetazzo/docker-busybox.git /docker-busybox |
|
112 |
- |
|
113 | 110 |
# Install registry |
114 | 111 |
ENV REGISTRY_COMMIT c448e0416925a9876d5576e412703c9b8b865e19 |
115 | 112 |
RUN set -x \ |
... | ... |
@@ -145,6 +142,10 @@ ENV DOCKER_BUILDTAGS apparmor selinux btrfs_noversion |
145 | 145 |
# Let us use a .bashrc file |
146 | 146 |
RUN ln -sfv $PWD/.bashrc ~/.bashrc |
147 | 147 |
|
148 |
+# Get the "busybox" image so we can "docker load" locally instead of pulling |
|
149 |
+COPY contrib/download-frozen-image.sh /go/src/github.com/docker/docker/contrib/ |
|
150 |
+RUN ./contrib/download-frozen-image.sh /docker-busybox busybox@4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125 |
|
151 |
+ |
|
148 | 152 |
# Install man page generator |
149 | 153 |
COPY vendor /go/src/github.com/docker/docker/vendor |
150 | 154 |
# (copy vendor/ because go-md2man needs golang.org/x/net) |
151 | 155 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,90 @@ |
0 |
+#!/bin/bash |
|
1 |
+set -e |
|
2 |
+ |
|
3 |
+# hello-world latest ef872312fe1b 3 months ago 910 B |
|
4 |
+# hello-world latest ef872312fe1bbc5e05aae626791a47ee9b032efa8f3bda39cc0be7b56bfe59b9 3 months ago 910 B |
|
5 |
+ |
|
6 |
+# debian latest f6fab3b798be 10 weeks ago 85.1 MB |
|
7 |
+# debian latest f6fab3b798be3174f45aa1eb731f8182705555f89c9026d8c1ef230cbf8301dd 10 weeks ago 85.1 MB |
|
8 |
+ |
|
9 |
+usage() { |
|
10 |
+ echo "usage: $0 dir image[:tag][@image-id] ..." |
|
11 |
+ echo " ie: $0 /tmp/hello-world hello-world" |
|
12 |
+ echo " $0 /tmp/debian-jessie debian:jessie" |
|
13 |
+ echo " $0 /tmp/old-hello-world hello-world@ef872312fe1bbc5e05aae626791a47ee9b032efa8f3bda39cc0be7b56bfe59b9" |
|
14 |
+ echo " $0 /tmp/old-debian debian:latest@f6fab3b798be3174f45aa1eb731f8182705555f89c9026d8c1ef230cbf8301dd" |
|
15 |
+ [ -z "$1" ] || exit "$1" |
|
16 |
+} |
|
17 |
+ |
|
18 |
+dir="$1" # dir for building tar in |
|
19 |
+shift || usage 1 >&2 |
|
20 |
+ |
|
21 |
+[ $# -gt 0 -a "$dir" ] || usage 2 >&2 |
|
22 |
+mkdir -p "$dir" |
|
23 |
+ |
|
24 |
+declare -A repositories=() |
|
25 |
+ |
|
26 |
+while [ $# -gt 0 ]; do |
|
27 |
+ imageTag="$1" |
|
28 |
+ shift |
|
29 |
+ image="${imageTag%%[:@]*}" |
|
30 |
+ tag="${imageTag#*:}" |
|
31 |
+ imageId="${tag##*@}" |
|
32 |
+ [ "$imageId" != "$tag" ] || imageId= |
|
33 |
+ [ "$tag" != "$imageTag" ] || tag='latest' |
|
34 |
+ tag="${tag%@*}" |
|
35 |
+ |
|
36 |
+ token="$(curl -sSL -o /dev/null -D- -H 'X-Docker-Token: true' "https://index.docker.io/v1/repositories/$image/images" | tr -d '\r' | awk -F ': *' '$1 == "X-Docker-Token" { print $2 }')" |
|
37 |
+ |
|
38 |
+ if [ -z "$imageId" ]; then |
|
39 |
+ imageId="$(curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/repositories/$image/tags/$tag")" |
|
40 |
+ imageId="${imageId//\"/}" |
|
41 |
+ fi |
|
42 |
+ |
|
43 |
+ ancestryJson="$(curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$imageId/ancestry")" |
|
44 |
+ if [ "${ancestryJson:0:1}" != '[' ]; then |
|
45 |
+ echo >&2 "error: /v1/images/$imageId/ancestry returned something unexpected:" |
|
46 |
+ echo >&2 " $ancestryJson" |
|
47 |
+ exit 1 |
|
48 |
+ fi |
|
49 |
+ |
|
50 |
+ IFS=',' |
|
51 |
+ ancestry=( ${ancestryJson//[\[\] \"]/} ) |
|
52 |
+ unset IFS |
|
53 |
+ |
|
54 |
+ [ -z "${repositories[$image]}" ] || repositories[$image]+=', ' |
|
55 |
+ repositories[$image]+='"'"$tag"'": "'"$imageId"'"' |
|
56 |
+ |
|
57 |
+ echo "Downloading '$imageTag' (${#ancestry[@]} layers)..." |
|
58 |
+ for imageId in "${ancestry[@]}"; do |
|
59 |
+ mkdir -p "$dir/$imageId" |
|
60 |
+ echo '1.0' > "$dir/$imageId/VERSION" |
|
61 |
+ |
|
62 |
+ curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$imageId/json" -o "$dir/$imageId/json" -C - |
|
63 |
+ |
|
64 |
+ # TODO figure out why "-C -" doesn't work here |
|
65 |
+ # "curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume." |
|
66 |
+ # "HTTP/1.1 416 Requested Range Not Satisfiable" |
|
67 |
+ if [ -f "$dir/$imageId/layer.tar" ]; then |
|
68 |
+ # TODO hackpatch for no -C support :'( |
|
69 |
+ echo "skipping existing ${imageId:0:12}" |
|
70 |
+ continue |
|
71 |
+ fi |
|
72 |
+ curl -SL --progress -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$imageId/layer" -o "$dir/$imageId/layer.tar" # -C - |
|
73 |
+ done |
|
74 |
+ echo |
|
75 |
+done |
|
76 |
+ |
|
77 |
+echo -n '{' > "$dir/repositories" |
|
78 |
+firstImage=1 |
|
79 |
+for image in "${!repositories[@]}"; do |
|
80 |
+ [ "$firstImage" ] || echo -n ',' >> "$dir/repositories" |
|
81 |
+ firstImage= |
|
82 |
+ echo -n $'\n\t' >> "$dir/repositories" |
|
83 |
+ echo -n '"'"$image"'": { '"${repositories[$image]}"' }' >> "$dir/repositories" |
|
84 |
+done |
|
85 |
+echo -n $'\n}\n' >> "$dir/repositories" |
|
86 |
+ |
|
87 |
+echo "Download of images into '$dir' complete." |
|
88 |
+echo "Use something like the following to load the result into a Docker daemon:" |
|
89 |
+echo " tar -cC '$dir' . | docker load" |
... | ... |
@@ -2,8 +2,19 @@ |
2 | 2 |
set -e |
3 | 3 |
|
4 | 4 |
if ! docker inspect busybox &> /dev/null; then |
5 |
- if [ -d /docker-busybox ]; then |
|
6 |
- ( set -x; docker build -t busybox /docker-busybox ) |
|
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 ) |
|
7 | 18 |
else |
8 | 19 |
( set -x; docker pull busybox ) |
9 | 20 |
fi |