blob: acb566f5d54840fea001cba2cad72aebb77a7add [file] [log] [blame]
Sree Kuchibhotlae3717422016-01-04 10:14:38 -08001#!/bin/bash
Jan Tattermusch7897ae92017-06-07 22:57:36 +02002# Copyright 2015 gRPC authors.
Sree Kuchibhotlae3717422016-01-04 10:14:38 -08003#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02004# 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 Kuchibhotlae3717422016-01-04 10:14:38 -08007#
Jan Tattermusch7897ae92017-06-07 22:57:36 +02008# http://www.apache.org/licenses/LICENSE-2.0
Sree Kuchibhotlae3717422016-01-04 10:14:38 -08009#
Jan Tattermusch7897ae92017-06-07 22:57:36 +020010# 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 Kuchibhotlae3717422016-01-04 10:14:38 -080015#
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
19set -x
20
21# Params:
Sree Kuchibhotla95a137b2016-03-21 11:10:42 -070022# INTEROP_IMAGE - Name of tag of the final interop image
Sree Kuchibhotla7a054362016-04-04 14:08:02 -070023# INTEROP_IMAGE_REPOSITORY_TAG - Optional. If set, the created image will be tagged using
Sree Kuchibhotlada25fdb2016-02-26 13:41:06 -080024# the command: 'docker tag $INTEROP_IMAGE $INTEROP_IMAGE_REPOSITORY_TAG'
Sree Kuchibhotla95a137b2016-03-21 11:10:42 -070025# 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 Kuchibhotlae3717422016-01-04 10:14:38 -080028# 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 Tattermusch26ca7762016-04-29 14:51:35 -070032cd `dirname $0`/../../..
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080033GRPC_ROOT=`pwd`
34MOUNT_ARGS="-v $GRPC_ROOT:/var/local/jenkins/grpc:ro"
35
Sree Kuchibhotlaedaa6eb2016-04-18 10:56:26 -070036GRPC_JAVA_ROOT=`cd ../grpc-java && pwd`
37if [ "$GRPC_JAVA_ROOT" != "" ]
38then
39 MOUNT_ARGS+=" -v $GRPC_JAVA_ROOT:/var/local/jenkins/grpc-java:ro"
40else
41 echo "WARNING: grpc-java not found, it won't be mounted to the docker container."
42fi
43
44GRPC_GO_ROOT=`cd ../grpc-go && pwd`
45if [ "$GRPC_GO_ROOT" != "" ]
46then
47 MOUNT_ARGS+=" -v $GRPC_GO_ROOT:/var/local/jenkins/grpc-go:ro"
48else
49 echo "WARNING: grpc-go not found, it won't be mounted to the docker container."
50fi
51
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080052mkdir -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.
57if [ -e $HOME/service_account ]
58then
59 MOUNT_ARGS+=" -v $HOME/service_account:/var/local/jenkins/service_account:ro"
60fi
61
62# Use image name based on Dockerfile checksum
Sree Kuchibhotla7a054362016-04-04 14:08:02 -070063BASE_IMAGE=${BASE_NAME}_base:`sha1sum tools/dockerfile/stress_test/$BASE_NAME/Dockerfile | cut -f1 -d\ `
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080064
65# Make sure base docker image has been built. Should be instantaneous if so.
Sree Kuchibhotla7a054362016-04-04 14:08:02 -070066docker build -t $BASE_IMAGE --force-rm=true tools/dockerfile/stress_test/$BASE_NAME || exit $?
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080067
68# Create a local branch so the child Docker script won't complain
69git branch -f jenkins-docker
70
71CONTAINER_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 Kuchibhotla95a137b2016-03-21 11:10:42 -070077 -e BUILD_TYPE=${BUILD_TYPE:=opt} \
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080078 -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 Kuchibhotla7a054362016-04-04 14:08:02 -070084 bash -l /var/local/jenkins/grpc/tools/dockerfile/stress_test/$BASE_NAME/build_interop_stress.sh \
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080085 && docker commit $CONTAINER_NAME $INTEROP_IMAGE \
Sree Kuchibhotla081b6032017-02-02 16:52:30 -080086 && ( if [ -n "$INTEROP_IMAGE_REPOSITORY_TAG" ]; then docker tag $INTEROP_IMAGE $INTEROP_IMAGE_REPOSITORY_TAG ; fi ) \
Sree Kuchibhotlae3717422016-01-04 10:14:38 -080087 && echo "Successfully built image $INTEROP_IMAGE")
88EXITCODE=$?
89
90# remove intermediate container, possibly killing it first
91docker rm -f $CONTAINER_NAME
92
93exit $EXITCODE