Skip to content

Commit

Permalink
Refactor busybox downloading as generic "frozen-images"
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tianon committed Mar 10, 2015
1 parent c5af44e commit 09b4c25
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 25 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ ENV DOCKER_BUILDTAGS apparmor selinux btrfs_noversion
# Let us use a .bashrc file
RUN ln -sfv $PWD/.bashrc ~/.bashrc

# Get the "busybox" image so we can "docker load" locally instead of pulling
# Get useful and necessary Hub images so we can "docker load" locally instead of pulling
COPY contrib/download-frozen-image.sh /go/src/github.com/docker/docker/contrib/
RUN ./contrib/download-frozen-image.sh /docker-busybox busybox@4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
RUN ./contrib/download-frozen-image.sh /docker-frozen-images \
busybox:latest@4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
# see also "hack/make/.ensure-frozen-images" (which needs to be updated any time this list is)

# Install man page generator
COPY vendor /go/src/github.com/docker/docker/vendor
Expand Down
2 changes: 1 addition & 1 deletion contrib/download-frozen-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ while [ $# -gt 0 ]; do
mkdir -p "$dir/$imageId"
echo '1.0' > "$dir/$imageId/VERSION"

curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$imageId/json" -o "$dir/$imageId/json" -C -
curl -sSL -H "Authorization: Token $token" "https://registry-1.docker.io/v1/images/$imageId/json" -o "$dir/$imageId/json"

# TODO figure out why "-C -" doesn't work here
# "curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume."
Expand Down
21 changes: 0 additions & 21 deletions project/make/.ensure-busybox

This file was deleted.

42 changes: 42 additions & 0 deletions project/make/.ensure-frozen-images
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash
set -e

# this list should match roughly what's in the Dockerfile (minus the explicit image IDs, of course)
images=(
busybox:latest
)

if ! docker inspect "${images[@]}" &> /dev/null; then
hardCodedDir='/docker-frozen-images'
if [ -d "$hardCodedDir" ]; then
( set -x; tar -cC "$hardCodedDir" . | docker load )
elif [ -e Dockerfile ] && command -v curl > /dev/null; then
# testing for "curl" because "download-frozen-image.sh" is built around curl
dir="$DEST/frozen-images"
# extract the exact "RUN download-frozen-image.sh" line from the Dockerfile itself for consistency
awk '
$1 == "RUN" && $2 == "./contrib/download-frozen-image.sh" {
for (i = 2; i < NF; i++)
printf ( $i == "'"$hardCodedDir"'" ? "'"$dir"'" : $i ) " ";
print $NF;
if (/\\$/) {
inCont = 1;
next;
}
}
inCont {
print;
if (!/\\$/) {
inCont = 0;
}
}
' Dockerfile | sh -x
( set -x; tar -cC "$dir" . | docker load )
else
for image in "${images[@]}"; do
if ! docker inspect "$image" &> /dev/null; then
( set -x; docker pull "$image" )
fi
done
fi
fi
2 changes: 1 addition & 1 deletion project/make/test-integration-cli
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bundle_test_integration_cli() {
# even and especially on test failures
didFail=
if ! {
source "$(dirname "$BASH_SOURCE")/.ensure-busybox"
source "$(dirname "$BASH_SOURCE")/.ensure-frozen-images"
source "$(dirname "$BASH_SOURCE")/.ensure-httpserver"
source "$(dirname "$BASH_SOURCE")/.ensure-emptyfs"

Expand Down

0 comments on commit 09b4c25

Please sign in to comment.