From cffd9885e8e77a2150a3faf0425996d758cf63bd Mon Sep 17 00:00:00 2001 From: Jonas Finnemann Jensen Date: Tue, 22 Nov 2016 14:13:15 -0800 Subject: [PATCH] Bug 1319449 - Set -o pipefail and other robustness improvements for image_builder. r=dustin MozReview-Commit-ID: 5oIdvcrScRt --HG-- extra : rebase_source : 6b6dd2dc3b3e8465127d33fb428877f68537ad5b --- testing/docker/image_builder/VERSION | 2 +- testing/docker/image_builder/build-image.sh | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/testing/docker/image_builder/VERSION b/testing/docker/image_builder/VERSION index 9084fa2f716a..26aaba0e8663 100644 --- a/testing/docker/image_builder/VERSION +++ b/testing/docker/image_builder/VERSION @@ -1 +1 @@ -1.1.0 +1.2.0 diff --git a/testing/docker/image_builder/build-image.sh b/testing/docker/image_builder/build-image.sh index 6286bd7b525a..1df0e470f0d0 100755 --- a/testing/docker/image_builder/build-image.sh +++ b/testing/docker/image_builder/build-image.sh @@ -4,7 +4,7 @@ # print a trace of commands, and make output verbose (print shell input as it's # read) # See https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html -set -x -e -v +set -x -e -v -o pipefail # Prefix errors with taskcluster error prefix so that they are parsed by Treeherder raise_error() { @@ -50,14 +50,30 @@ if cat /tmp/docker-build.log | jq -se 'add | .error' > /dev/null; then raise_error "Image build failed: `cat /tmp/docker-build.log | jq -rse 'add | .error'`"; fi +# Sanity check that image was built successfully +if ! cat /tmp/docker-build.log | tail -n 1 | jq -r '.stream' | grep '^Successfully built' > /dev/null; then + echo 'docker-build.log for debugging:'; + cat /tmp/docker-build.log | tail -n 50; + raise_error "Image build log didn't with 'Successfully built'"; +fi + # Get image from docker daemon (try up to 10 times) # This interacts directly with the docker remote API, see: # https://docs.docker.com/engine/reference/api/docker_remote_api_v1.18/ +IMAGE_FILE=/home/worker/workspace/image.tar count=0 while ! curl -s --fail -X GET \ --unix-socket /var/run/docker.sock "http:/images/$IMAGE_NAME:$HASH/get" \ - | zstd -3 -c -o /home/worker/workspace/artifacts/image.tar.zst; do + -o "$IMAGE_FILE"; do ((c++)) && ((c==10)) && echo 'Failed to get image from docker' && exit 1; echo 'Waiting for image to be ready'; sleep 5; done + +# Test that image was exported +if [ ! -s "$IMAGE_FILE" ]; then + raise_error "Failed to export docker image"; +fi + +# Compress image with zst +zstd -3 -c -o /home/worker/workspace/artifacts/image.tar.zst "$IMAGE_FILE"