OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 2 # Copyright 2015-2016, Google Inc. |
| 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 |
| 36 cd $(dirname $0)/../.. |
| 37 git_root=$(pwd) |
| 38 cd - |
| 39 |
| 40 # Ensure existence of ccache directory |
| 41 mkdir -p /tmp/ccache |
| 42 |
| 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 |
| 47 # Create a local branch so the child Docker script won't complain |
| 48 git branch -f jenkins-docker |
| 49 |
| 50 # Inputs |
| 51 # DOCKERFILE_DIR - Directory in which Dockerfile file is located. |
| 52 # DOCKER_RUN_SCRIPT - Script to run under docker (relative to grpc repo root) |
| 53 |
| 54 # Use image name based on Dockerfile location checksum |
| 55 DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfi
le | cut -f1 -d\ ) |
| 56 |
| 57 # Make sure docker image has been built. Should be instantaneous if so. |
| 58 docker build -t $DOCKER_IMAGE_NAME $DOCKERFILE_DIR |
| 59 |
| 60 # Choose random name for docker container |
| 61 CONTAINER_NAME="run_tests_$(uuidgen)" |
| 62 |
| 63 # Git root as seen by the docker instance |
| 64 docker_instance_git_root=/var/local/jenkins/grpc |
| 65 |
| 66 # Run tests inside docker |
| 67 docker run \ |
| 68 -e "RUN_TESTS_COMMAND=$RUN_TESTS_COMMAND" \ |
| 69 -e "config=$config" \ |
| 70 -e "arch=$arch" \ |
| 71 -e CCACHE_DIR=/tmp/ccache \ |
| 72 -e XDG_CACHE_HOME=/tmp/xdg-cache-home \ |
| 73 -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 fo
r why docker is awful' \ |
| 74 -e HOST_GIT_ROOT=$git_root \ |
| 75 -e LOCAL_GIT_ROOT=$docker_instance_git_root \ |
| 76 -e "BUILD_ID=$BUILD_ID" \ |
| 77 -i $TTY_FLAG \ |
| 78 -v "$git_root:$docker_instance_git_root" \ |
| 79 -v /tmp/ccache:/tmp/ccache \ |
| 80 -v /tmp/npm-cache:/tmp/npm-cache \ |
| 81 -v /tmp/xdg-cache-home:/tmp/xdg-cache-home \ |
| 82 -v /var/run/docker.sock:/var/run/docker.sock \ |
| 83 -v $(which docker):/bin/docker \ |
| 84 -w /var/local/git/grpc \ |
| 85 --name=$CONTAINER_NAME \ |
| 86 $DOCKER_IMAGE_NAME \ |
| 87 bash -l "/var/local/jenkins/grpc/$DOCKER_RUN_SCRIPT" || DOCKER_FAILED="true" |
| 88 |
| 89 docker cp "$CONTAINER_NAME:/var/local/git/grpc/reports.zip" $git_root || true |
| 90 unzip -o $git_root/reports.zip -d $git_root || true |
| 91 rm -f reports.zip |
| 92 |
| 93 # remove the container, possibly killing it first |
| 94 docker rm -f $CONTAINER_NAME || true |
| 95 |
| 96 if [ "$DOCKER_FAILED" != "" ] && [ "$XML_REPORT" == "" ] |
| 97 then |
| 98 exit 1 |
| 99 fi |
OLD | NEW |