Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 1 | #!/bin/bash |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 2 | # Copyright 2015, Google Inc. |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 3 | # All rights reserved. |
| 4 | # |
| 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are |
| 7 | # met: |
| 8 | # |
| 9 | # * Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # * Redistributions in binary form must reproduce the above |
| 12 | # copyright notice, this list of conditions and the following disclaimer |
| 13 | # in the documentation and/or other materials provided with the |
| 14 | # distribution. |
| 15 | # * Neither the name of Google Inc. nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | # |
| 31 | # This script is invoked by run_tests.py to accommodate "test under docker" |
| 32 | # scenario. You should never need to call this script on your own. |
| 33 | |
| 34 | set -ex |
| 35 | |
Jan Tattermusch | 26ca776 | 2016-04-29 14:51:35 -0700 | [diff] [blame] | 36 | cd $(dirname $0)/../../.. |
Jan Tattermusch | a810876 | 2016-02-07 14:30:43 -0800 | [diff] [blame] | 37 | git_root=$(pwd) |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 38 | cd - |
| 39 | |
Masood Malekghassemi | 60e5f91 | 2015-10-05 15:26:26 -0700 | [diff] [blame] | 40 | # Ensure existence of ccache directory |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 41 | mkdir -p /tmp/ccache |
| 42 | |
Masood Malekghassemi | 60e5f91 | 2015-10-05 15:26:26 -0700 | [diff] [blame] | 43 | # Ensure existence of the home directory for XDG caches (e.g. what pip uses for |
| 44 | # its cache location now that --download-cache is deprecated). |
| 45 | mkdir -p /tmp/xdg-cache-home |
| 46 | |
Jan Tattermusch | 4dc9e72 | 2016-01-25 17:00:54 -0800 | [diff] [blame] | 47 | # Inputs |
| 48 | # DOCKERFILE_DIR - Directory in which Dockerfile file is located. |
| 49 | # DOCKER_RUN_SCRIPT - Script to run under docker (relative to grpc repo root) |
Jan Tattermusch | b10a193 | 2017-02-23 23:39:30 +0100 | [diff] [blame] | 50 | # DOCKERHUB_ORGANIZATION - If set, pull a prebuilt image from given dockerhub org. |
Jan Tattermusch | 4dc9e72 | 2016-01-25 17:00:54 -0800 | [diff] [blame] | 51 | |
| 52 | # Use image name based on Dockerfile location checksum |
| 53 | DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ ) |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 54 | |
Jan Tattermusch | b10a193 | 2017-02-23 23:39:30 +0100 | [diff] [blame] | 55 | if [ "$DOCKERHUB_ORGANIZATION" != "" ] |
| 56 | then |
| 57 | DOCKER_IMAGE_NAME=$DOCKERHUB_ORGANIZATION/$DOCKER_IMAGE_NAME |
| 58 | docker pull $DOCKER_IMAGE_NAME |
| 59 | else |
| 60 | # Make sure docker image has been built. Should be instantaneous if so. |
| 61 | docker build -t $DOCKER_IMAGE_NAME $DOCKERFILE_DIR |
| 62 | fi |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 63 | |
Jan Tattermusch | 65854eb | 2015-10-08 17:35:44 -0700 | [diff] [blame] | 64 | # Choose random name for docker container |
| 65 | CONTAINER_NAME="run_tests_$(uuidgen)" |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 66 | |
Craig Tiller | eb841e2 | 2016-02-11 15:49:16 -0800 | [diff] [blame] | 67 | # Git root as seen by the docker instance |
| 68 | docker_instance_git_root=/var/local/jenkins/grpc |
| 69 | |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 70 | # Run tests inside docker |
Jan Tattermusch | e480a6a | 2016-10-07 12:59:08 +0200 | [diff] [blame] | 71 | DOCKER_EXIT_CODE=0 |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 72 | docker run \ |
| 73 | -e "RUN_TESTS_COMMAND=$RUN_TESTS_COMMAND" \ |
| 74 | -e "config=$config" \ |
| 75 | -e "arch=$arch" \ |
| 76 | -e CCACHE_DIR=/tmp/ccache \ |
Masood Malekghassemi | 60e5f91 | 2015-10-05 15:26:26 -0700 | [diff] [blame] | 77 | -e XDG_CACHE_HOME=/tmp/xdg-cache-home \ |
Craig Tiller | 2dfd2de | 2015-11-05 13:14:39 -0800 | [diff] [blame] | 78 | -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 for why docker is awful' \ |
Craig Tiller | 64195a7 | 2016-01-04 15:05:35 -0800 | [diff] [blame] | 79 | -e HOST_GIT_ROOT=$git_root \ |
Craig Tiller | eb841e2 | 2016-02-11 15:49:16 -0800 | [diff] [blame] | 80 | -e LOCAL_GIT_ROOT=$docker_instance_git_root \ |
Craig Tiller | c18cbbc | 2016-01-21 13:13:42 -0800 | [diff] [blame] | 81 | -e "BUILD_ID=$BUILD_ID" \ |
Jan Tattermusch | 261b58c | 2015-09-18 17:15:48 -0700 | [diff] [blame] | 82 | -i $TTY_FLAG \ |
Craig Tiller | eb841e2 | 2016-02-11 15:49:16 -0800 | [diff] [blame] | 83 | -v "$git_root:$docker_instance_git_root" \ |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 84 | -v /tmp/ccache:/tmp/ccache \ |
murgatroid99 | 28c06d8 | 2015-10-09 16:07:36 -0700 | [diff] [blame] | 85 | -v /tmp/npm-cache:/tmp/npm-cache \ |
Masood Malekghassemi | 60e5f91 | 2015-10-05 15:26:26 -0700 | [diff] [blame] | 86 | -v /tmp/xdg-cache-home:/tmp/xdg-cache-home \ |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 87 | -w /var/local/git/grpc \ |
Jan Tattermusch | 65854eb | 2015-10-08 17:35:44 -0700 | [diff] [blame] | 88 | --name=$CONTAINER_NAME \ |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 89 | $DOCKER_IMAGE_NAME \ |
Jan Tattermusch | e480a6a | 2016-10-07 12:59:08 +0200 | [diff] [blame] | 90 | bash -l "/var/local/jenkins/grpc/$DOCKER_RUN_SCRIPT" || DOCKER_EXIT_CODE=$? |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 91 | |
Jan Tattermusch | a1906d5 | 2016-09-19 18:37:17 +0200 | [diff] [blame] | 92 | # use unique name for reports.zip to prevent clash between concurrent |
| 93 | # run_tests.py runs |
| 94 | TEMP_REPORTS_ZIP=`mktemp` |
| 95 | docker cp "$CONTAINER_NAME:/var/local/git/grpc/reports.zip" ${TEMP_REPORTS_ZIP} || true |
| 96 | unzip -o ${TEMP_REPORTS_ZIP} -d $git_root || true |
| 97 | rm -f ${TEMP_REPORTS_ZIP} |
Nicolas "Pixel" Noble | 4d97707 | 2015-10-02 23:52:38 +0200 | [diff] [blame] | 98 | |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 99 | # remove the container, possibly killing it first |
Jan Tattermusch | 65854eb | 2015-10-08 17:35:44 -0700 | [diff] [blame] | 100 | docker rm -f $CONTAINER_NAME || true |
Jan Tattermusch | c95eead | 2015-09-18 13:03:50 -0700 | [diff] [blame] | 101 | |
Jan Tattermusch | e480a6a | 2016-10-07 12:59:08 +0200 | [diff] [blame] | 102 | exit $DOCKER_EXIT_CODE |