blob: 772eab0c6189cb75eead7664619f57251531f51d [file] [log] [blame]
Sree Kuchibhotlae3717422016-01-04 10:14:38 -08001#!/bin/bash
Craig Tiller6169d5f2016-03-31 07:46:18 -07002# Copyright 2015, Google Inc.
Sree Kuchibhotlae3717422016-01-04 10:14:38 -08003# 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
34set -x
35
36# Params:
Sree Kuchibhotla95a137b2016-03-21 11:10:42 -070037# INTEROP_IMAGE - Name of tag of the final interop image
Sree Kuchibhotla7a054362016-04-04 14:08:02 -070038# INTEROP_IMAGE_REPOSITORY_TAG - Optional. If set, the created image will be tagged using
Sree Kuchibhotlada25fdb2016-02-26 13:41:06 -080039# the command: 'docker tag $INTEROP_IMAGE $INTEROP_IMAGE_REPOSITORY_TAG'
Sree Kuchibhotla95a137b2016-03-21 11:10:42 -070040# BASE_NAME - Base name used to locate the base Dockerfile and build script
41# BUILD_TYPE - The 'CONFIG' variable passed to the 'make' command (example:
42# asan, tsan. Default value: opt).
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080043# TTY_FLAG - optional -t flag to make docker allocate tty
44# BUILD_INTEROP_DOCKER_EXTRA_ARGS - optional args to be passed to the
45# docker run command
46
Jan Tattermusch26ca7762016-04-29 14:51:35 -070047cd `dirname $0`/../../..
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080048GRPC_ROOT=`pwd`
49MOUNT_ARGS="-v $GRPC_ROOT:/var/local/jenkins/grpc:ro"
50
Sree Kuchibhotlaedaa6eb2016-04-18 10:56:26 -070051GRPC_JAVA_ROOT=`cd ../grpc-java && pwd`
52if [ "$GRPC_JAVA_ROOT" != "" ]
53then
54 MOUNT_ARGS+=" -v $GRPC_JAVA_ROOT:/var/local/jenkins/grpc-java:ro"
55else
56 echo "WARNING: grpc-java not found, it won't be mounted to the docker container."
57fi
58
59GRPC_GO_ROOT=`cd ../grpc-go && pwd`
60if [ "$GRPC_GO_ROOT" != "" ]
61then
62 MOUNT_ARGS+=" -v $GRPC_GO_ROOT:/var/local/jenkins/grpc-go:ro"
63else
64 echo "WARNING: grpc-go not found, it won't be mounted to the docker container."
65fi
66
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080067mkdir -p /tmp/ccache
68
69# Mount service account dir if available.
70# If service_directory does not contain the service account JSON file,
71# some of the tests will fail.
72if [ -e $HOME/service_account ]
73then
74 MOUNT_ARGS+=" -v $HOME/service_account:/var/local/jenkins/service_account:ro"
75fi
76
77# Use image name based on Dockerfile checksum
Sree Kuchibhotla7a054362016-04-04 14:08:02 -070078BASE_IMAGE=${BASE_NAME}_base:`sha1sum tools/dockerfile/stress_test/$BASE_NAME/Dockerfile | cut -f1 -d\ `
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080079
80# Make sure base docker image has been built. Should be instantaneous if so.
Sree Kuchibhotla7a054362016-04-04 14:08:02 -070081docker build -t $BASE_IMAGE --force-rm=true tools/dockerfile/stress_test/$BASE_NAME || exit $?
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080082
83# Create a local branch so the child Docker script won't complain
84git branch -f jenkins-docker
85
86CONTAINER_NAME="build_${BASE_NAME}_$(uuidgen)"
87
88# Prepare image for interop tests, commit it on success.
89(docker run \
90 -e CCACHE_DIR=/tmp/ccache \
91 -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 for why docker is awful' \
Sree Kuchibhotla95a137b2016-03-21 11:10:42 -070092 -e BUILD_TYPE=${BUILD_TYPE:=opt} \
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080093 -i $TTY_FLAG \
94 $MOUNT_ARGS \
95 $BUILD_INTEROP_DOCKER_EXTRA_ARGS \
96 -v /tmp/ccache:/tmp/ccache \
97 --name=$CONTAINER_NAME \
98 $BASE_IMAGE \
Sree Kuchibhotla7a054362016-04-04 14:08:02 -070099 bash -l /var/local/jenkins/grpc/tools/dockerfile/stress_test/$BASE_NAME/build_interop_stress.sh \
Sree Kuchibhotlae3717422016-01-04 10:14:38 -0800100 && docker commit $CONTAINER_NAME $INTEROP_IMAGE \
Sree Kuchibhotla081b6032017-02-02 16:52:30 -0800101 && ( if [ -n "$INTEROP_IMAGE_REPOSITORY_TAG" ]; then docker tag $INTEROP_IMAGE $INTEROP_IMAGE_REPOSITORY_TAG ; fi ) \
Sree Kuchibhotlae3717422016-01-04 10:14:38 -0800102 && echo "Successfully built image $INTEROP_IMAGE")
103EXITCODE=$?
104
105# remove intermediate container, possibly killing it first
106docker rm -f $CONTAINER_NAME
107
108exit $EXITCODE