Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 1 | #!/bin/bash |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 2 | # Copyright 2015 gRPC authors. |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 3 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 7 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 9 | # |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 15 | # |
| 16 | # This script is invoked by run_interop_tests.py to build the docker image |
| 17 | # for interop testing. You should never need to call this script on your own. |
| 18 | |
| 19 | set -x |
| 20 | |
| 21 | # Params: |
Sree Kuchibhotla | 95a137b | 2016-03-21 11:10:42 -0700 | [diff] [blame] | 22 | # INTEROP_IMAGE - Name of tag of the final interop image |
Sree Kuchibhotla | 7a05436 | 2016-04-04 14:08:02 -0700 | [diff] [blame] | 23 | # INTEROP_IMAGE_REPOSITORY_TAG - Optional. If set, the created image will be tagged using |
Sree Kuchibhotla | da25fdb | 2016-02-26 13:41:06 -0800 | [diff] [blame] | 24 | # the command: 'docker tag $INTEROP_IMAGE $INTEROP_IMAGE_REPOSITORY_TAG' |
Sree Kuchibhotla | 95a137b | 2016-03-21 11:10:42 -0700 | [diff] [blame] | 25 | # BASE_NAME - Base name used to locate the base Dockerfile and build script |
| 26 | # BUILD_TYPE - The 'CONFIG' variable passed to the 'make' command (example: |
| 27 | # asan, tsan. Default value: opt). |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 28 | # TTY_FLAG - optional -t flag to make docker allocate tty |
| 29 | # BUILD_INTEROP_DOCKER_EXTRA_ARGS - optional args to be passed to the |
| 30 | # docker run command |
| 31 | |
Jan Tattermusch | 26ca776 | 2016-04-29 14:51:35 -0700 | [diff] [blame] | 32 | cd `dirname $0`/../../.. |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 33 | GRPC_ROOT=`pwd` |
| 34 | MOUNT_ARGS="-v $GRPC_ROOT:/var/local/jenkins/grpc:ro" |
| 35 | |
Sree Kuchibhotla | edaa6eb | 2016-04-18 10:56:26 -0700 | [diff] [blame] | 36 | GRPC_JAVA_ROOT=`cd ../grpc-java && pwd` |
| 37 | if [ "$GRPC_JAVA_ROOT" != "" ] |
| 38 | then |
| 39 | MOUNT_ARGS+=" -v $GRPC_JAVA_ROOT:/var/local/jenkins/grpc-java:ro" |
| 40 | else |
| 41 | echo "WARNING: grpc-java not found, it won't be mounted to the docker container." |
| 42 | fi |
| 43 | |
| 44 | GRPC_GO_ROOT=`cd ../grpc-go && pwd` |
| 45 | if [ "$GRPC_GO_ROOT" != "" ] |
| 46 | then |
| 47 | MOUNT_ARGS+=" -v $GRPC_GO_ROOT:/var/local/jenkins/grpc-go:ro" |
| 48 | else |
| 49 | echo "WARNING: grpc-go not found, it won't be mounted to the docker container." |
| 50 | fi |
| 51 | |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 52 | mkdir -p /tmp/ccache |
| 53 | |
| 54 | # Mount service account dir if available. |
| 55 | # If service_directory does not contain the service account JSON file, |
| 56 | # some of the tests will fail. |
| 57 | if [ -e $HOME/service_account ] |
| 58 | then |
| 59 | MOUNT_ARGS+=" -v $HOME/service_account:/var/local/jenkins/service_account:ro" |
| 60 | fi |
| 61 | |
| 62 | # Use image name based on Dockerfile checksum |
Sree Kuchibhotla | 7a05436 | 2016-04-04 14:08:02 -0700 | [diff] [blame] | 63 | BASE_IMAGE=${BASE_NAME}_base:`sha1sum tools/dockerfile/stress_test/$BASE_NAME/Dockerfile | cut -f1 -d\ ` |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 64 | |
| 65 | # Make sure base docker image has been built. Should be instantaneous if so. |
Sree Kuchibhotla | 7a05436 | 2016-04-04 14:08:02 -0700 | [diff] [blame] | 66 | docker build -t $BASE_IMAGE --force-rm=true tools/dockerfile/stress_test/$BASE_NAME || exit $? |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 67 | |
| 68 | # Create a local branch so the child Docker script won't complain |
| 69 | git branch -f jenkins-docker |
| 70 | |
| 71 | CONTAINER_NAME="build_${BASE_NAME}_$(uuidgen)" |
| 72 | |
| 73 | # Prepare image for interop tests, commit it on success. |
| 74 | (docker run \ |
| 75 | -e CCACHE_DIR=/tmp/ccache \ |
| 76 | -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 for why docker is awful' \ |
Sree Kuchibhotla | 95a137b | 2016-03-21 11:10:42 -0700 | [diff] [blame] | 77 | -e BUILD_TYPE=${BUILD_TYPE:=opt} \ |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 78 | -i $TTY_FLAG \ |
| 79 | $MOUNT_ARGS \ |
| 80 | $BUILD_INTEROP_DOCKER_EXTRA_ARGS \ |
| 81 | -v /tmp/ccache:/tmp/ccache \ |
| 82 | --name=$CONTAINER_NAME \ |
| 83 | $BASE_IMAGE \ |
Sree Kuchibhotla | 7a05436 | 2016-04-04 14:08:02 -0700 | [diff] [blame] | 84 | bash -l /var/local/jenkins/grpc/tools/dockerfile/stress_test/$BASE_NAME/build_interop_stress.sh \ |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 85 | && docker commit $CONTAINER_NAME $INTEROP_IMAGE \ |
Sree Kuchibhotla | 081b603 | 2017-02-02 16:52:30 -0800 | [diff] [blame] | 86 | && ( if [ -n "$INTEROP_IMAGE_REPOSITORY_TAG" ]; then docker tag $INTEROP_IMAGE $INTEROP_IMAGE_REPOSITORY_TAG ; fi ) \ |
Sree Kuchibhotla | e371742 | 2016-01-04 10:14:38 -0800 | [diff] [blame] | 87 | && echo "Successfully built image $INTEROP_IMAGE") |
| 88 | EXITCODE=$? |
| 89 | |
| 90 | # remove intermediate container, possibly killing it first |
| 91 | docker rm -f $CONTAINER_NAME |
| 92 | |
| 93 | exit $EXITCODE |