From c16b7e1cc217dd211db109d774bd9def65b9f735 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Thu, 12 Nov 2015 16:13:31 -0800 Subject: [PATCH] Fix "docker-build.sh" wrapper to handle images with ONBUILD instructions more automatically The way we handle this semi-gracefully is to create a fake "docker save" tarball that contains just a single layer whose parent is the image we're wanting to test, and whose "config" is the same as the parent image, but with "OnBuild" nulled out, and adjust the build to use that new layer as the base for the build instead. --- test/tests/docker-build.sh | 21 ++++++++++-- test/tests/jetty-hello-web/run.sh | 2 +- test/tests/mysql-initdb/run.sh | 2 +- test/tests/php-fpm-hello-web/run.sh | 2 +- test/tests/postgres-initdb/run.sh | 2 +- test/tests/remove-onbuild.sh | 53 +++++++++++++++++++++++++++++ test/tests/run-in-container.sh | 2 +- 7 files changed, 76 insertions(+), 8 deletions(-) create mode 100755 test/tests/remove-onbuild.sh diff --git a/test/tests/docker-build.sh b/test/tests/docker-build.sh index 67391beafa..30d7ec88ac 100755 --- a/test/tests/docker-build.sh +++ b/test/tests/docker-build.sh @@ -3,11 +3,11 @@ set -e # wrapper around "docker build" that creates a temporary directory and copies files into it first so that arbitrary host directories can be copied into containers without bind mounts, but accepts a Dockerfile on stdin -# usage: ./docker-build.sh some-host-directory -t some-new-image:some-tag < "$tmp/Dockerfile" + +from="$(awk -F '[[:space:]]+' 'toupper($1) == "FROM" { print $2; exit }' "$tmp/Dockerfile")" +onbuilds="$(docker inspect -f '{{len .Config.OnBuild}}' "$from")" +if [ "$onbuilds" -gt 0 ]; then + # crap, the image we want to build has some ONBUILD instructions + # those are kind of going to ruin our day + # let's do some hacks to strip those bad boys out in a new fake layer + "$(dirname "$(readlink -f "$BASH_SOURCE")")/remove-onbuild.sh" "$from" "$imageTag" + awk -F '[[:space:]]+' 'toupper($1) == "FROM" { $2 = "'"$imageTag"'" } { print }' "$tmp/Dockerfile" > "$tmp/Dockerfile.new" + mv "$tmp/Dockerfile.new" "$tmp/Dockerfile" +fi + cp -a "$dir" "$tmp/dir" -docker build "$@" "$tmp" > /dev/null + +docker build -t "$imageTag" "$tmp" > /dev/null diff --git a/test/tests/jetty-hello-web/run.sh b/test/tests/jetty-hello-web/run.sh index fb52d030aa..4435988053 100755 --- a/test/tests/jetty-hello-web/run.sh +++ b/test/tests/jetty-hello-web/run.sh @@ -13,7 +13,7 @@ clientImage="$image" # Create an instance of the container-under-test serverImage="$("$dir/../image-name.sh" librarytest/jetty-hello-web "$image")" -"$dir/../docker-build.sh" "$dir" -t "$serverImage" < "$tmp/$newId/json" +echo -n '1.0' > "$tmp/$newId/VERSION" +dd if=/dev/zero of="$tmp/$newId/layer.tar" bs=1k count=1 &> /dev/null # empty tar file +cat > "$tmp/repositories" <