Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -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 | 91ad018 | 2015-10-01 09:22:03 -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_interop_tests.py to build the docker image |
| 32 | # for interop testing. You should never need to call this script on your own. |
| 33 | |
| 34 | set -x |
| 35 | |
Stanley Cheung | 15bc8e7 | 2015-10-14 10:55:41 -0700 | [diff] [blame] | 36 | # Params: |
| 37 | # INTEROP_IMAGE - name of tag of the final interop image |
| 38 | # BASE_NAME - base name used to locate the base Dockerfile and build script |
| 39 | # TTY_FLAG - optional -t flag to make docker allocate tty |
| 40 | # BUILD_INTEROP_DOCKER_EXTRA_ARGS - optional args to be passed to the |
| 41 | # docker run command |
| 42 | |
Jan Tattermusch | 26ca776 | 2016-04-29 14:51:35 -0700 | [diff] [blame] | 43 | cd `dirname $0`/../../.. |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 44 | GRPC_ROOT=`pwd` |
Jan Tattermusch | 2b778d6 | 2015-10-06 09:03:36 -0700 | [diff] [blame] | 45 | MOUNT_ARGS="-v $GRPC_ROOT:/var/local/jenkins/grpc:ro" |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 46 | |
| 47 | GRPC_JAVA_ROOT=`cd ../grpc-java && pwd` |
| 48 | if [ "$GRPC_JAVA_ROOT" != "" ] |
| 49 | then |
Jan Tattermusch | 2b778d6 | 2015-10-06 09:03:36 -0700 | [diff] [blame] | 50 | MOUNT_ARGS+=" -v $GRPC_JAVA_ROOT:/var/local/jenkins/grpc-java:ro" |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 51 | else |
| 52 | echo "WARNING: grpc-java not found, it won't be mounted to the docker container." |
| 53 | fi |
| 54 | |
| 55 | GRPC_GO_ROOT=`cd ../grpc-go && pwd` |
| 56 | if [ "$GRPC_GO_ROOT" != "" ] |
| 57 | then |
Jan Tattermusch | 2b778d6 | 2015-10-06 09:03:36 -0700 | [diff] [blame] | 58 | MOUNT_ARGS+=" -v $GRPC_GO_ROOT:/var/local/jenkins/grpc-go:ro" |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 59 | else |
| 60 | echo "WARNING: grpc-go not found, it won't be mounted to the docker container." |
| 61 | fi |
| 62 | |
| 63 | mkdir -p /tmp/ccache |
| 64 | |
Jan Tattermusch | 2b778d6 | 2015-10-06 09:03:36 -0700 | [diff] [blame] | 65 | # Mount service account dir if available. |
| 66 | # If service_directory does not contain the service account JSON file, |
| 67 | # some of the tests will fail. |
| 68 | if [ -e $HOME/service_account ] |
| 69 | then |
| 70 | MOUNT_ARGS+=" -v $HOME/service_account:/var/local/jenkins/service_account:ro" |
| 71 | fi |
| 72 | |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 73 | # Use image name based on Dockerfile checksum |
Jan Tattermusch | 24b68cd | 2016-04-27 12:19:56 -0700 | [diff] [blame] | 74 | BASE_IMAGE=${BASE_NAME}_base:`sha1sum tools/dockerfile/interoptest/$BASE_NAME/Dockerfile | cut -f1 -d\ ` |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 75 | |
| 76 | # Make sure base docker image has been built. Should be instantaneous if so. |
Jan Tattermusch | 24b68cd | 2016-04-27 12:19:56 -0700 | [diff] [blame] | 77 | docker build -t $BASE_IMAGE --force-rm=true tools/dockerfile/interoptest/$BASE_NAME || exit $? |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 78 | |
| 79 | # Create a local branch so the child Docker script won't complain |
| 80 | git branch -f jenkins-docker |
| 81 | |
Jan Tattermusch | 9b98121 | 2015-10-08 17:25:52 -0700 | [diff] [blame] | 82 | CONTAINER_NAME="build_${BASE_NAME}_$(uuidgen)" |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 83 | |
| 84 | # Prepare image for interop tests, commit it on success. |
| 85 | (docker run \ |
| 86 | -e CCACHE_DIR=/tmp/ccache \ |
Adele Zhou | 862a4d7 | 2015-11-05 17:14:05 -0800 | [diff] [blame] | 87 | -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 for why docker is awful' \ |
Jan Tattermusch | 49832f2 | 2016-01-22 09:16:06 -0800 | [diff] [blame] | 88 | -e THIS_IS_REALLY_NEEDED_ONCE_AGAIN='For issue 4835. See https://github.com/docker/docker/issues/14203 for why docker is awful' \ |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 89 | -i $TTY_FLAG \ |
| 90 | $MOUNT_ARGS \ |
Stanley Cheung | 15bc8e7 | 2015-10-14 10:55:41 -0700 | [diff] [blame] | 91 | $BUILD_INTEROP_DOCKER_EXTRA_ARGS \ |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 92 | -v /tmp/ccache:/tmp/ccache \ |
Jan Tattermusch | 9b98121 | 2015-10-08 17:25:52 -0700 | [diff] [blame] | 93 | --name=$CONTAINER_NAME \ |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 94 | $BASE_IMAGE \ |
Jan Tattermusch | 24b68cd | 2016-04-27 12:19:56 -0700 | [diff] [blame] | 95 | bash -l /var/local/jenkins/grpc/tools/dockerfile/interoptest/$BASE_NAME/build_interop.sh \ |
Jan Tattermusch | 9b98121 | 2015-10-08 17:25:52 -0700 | [diff] [blame] | 96 | && docker commit $CONTAINER_NAME $INTEROP_IMAGE \ |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 97 | && echo "Successfully built image $INTEROP_IMAGE") |
| 98 | EXITCODE=$? |
| 99 | |
| 100 | # remove intermediate container, possibly killing it first |
Jan Tattermusch | 9b98121 | 2015-10-08 17:25:52 -0700 | [diff] [blame] | 101 | docker rm -f $CONTAINER_NAME |
Jan Tattermusch | 91ad018 | 2015-10-01 09:22:03 -0700 | [diff] [blame] | 102 | |
| 103 | exit $EXITCODE |