From 09b4c2585284d1125d4d299a7d58b36c1d0baf17 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 6 Mar 2015 18:12:41 -0700 Subject: [PATCH] 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 --- Dockerfile | 6 +++-- contrib/download-frozen-image.sh | 2 +- project/make/.ensure-busybox | 21 --------------- project/make/.ensure-frozen-images | 42 ++++++++++++++++++++++++++++++ project/make/test-integration-cli | 2 +- 5 files changed, 48 insertions(+), 25 deletions(-) delete mode 100644 project/make/.ensure-busybox create mode 100644 project/make/.ensure-frozen-images diff --git a/Dockerfile b/Dockerfile index a7cbf468d6..412fff4716 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/contrib/download-frozen-image.sh b/contrib/download-frozen-image.sh index 2e3eb98e54..1b9d3d22c7 100755 --- a/contrib/download-frozen-image.sh +++ b/contrib/download-frozen-image.sh @@ -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." diff --git a/project/make/.ensure-busybox b/project/make/.ensure-busybox deleted file mode 100644 index fef9a0135c..0000000000 --- a/project/make/.ensure-busybox +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -set -e - -if ! docker inspect busybox &> /dev/null; then - hardCodedDir='/docker-busybox' - 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/busybox" - # extract the exact "download-frozen-image.sh" line from the Dockerfile itself for consistency - awk '$1 == "RUN" && $2 == "./contrib/download-frozen-image.sh" && /busybox@/ { - for (i = 2; i < NF; i++) - printf ( $i == "'"$hardCodedDir"'" ? "'"$dir"'" : $i ) " "; - print $NF; - }' Dockerfile | sh -x - ( set -x; tar -cC "$dir" . | docker load ) - else - ( set -x; docker pull busybox ) - fi -fi diff --git a/project/make/.ensure-frozen-images b/project/make/.ensure-frozen-images new file mode 100644 index 0000000000..ee3e92bd65 --- /dev/null +++ b/project/make/.ensure-frozen-images @@ -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 diff --git a/project/make/test-integration-cli b/project/make/test-integration-cli index 23283968b0..3ef41d919e 100644 --- a/project/make/test-integration-cli +++ b/project/make/test-integration-cli @@ -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"