blob: f10916d19235f1284287e9f5111ec76fcc419072 [file] [log] [blame]
Jan Tattermuschc95eead2015-09-18 13:03:50 -07001#!/bin/bash
Craig Tiller6169d5f2016-03-31 07:46:18 -07002# Copyright 2015, Google Inc.
Jan Tattermuschc95eead2015-09-18 13:03:50 -07003# 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
34set -ex
35
Jan Tattermusch26ca7762016-04-29 14:51:35 -070036cd $(dirname $0)/../../..
Jan Tattermuscha8108762016-02-07 14:30:43 -080037git_root=$(pwd)
Jan Tattermuschc95eead2015-09-18 13:03:50 -070038cd -
39
Masood Malekghassemi60e5f912015-10-05 15:26:26 -070040# Ensure existence of ccache directory
Jan Tattermuschc95eead2015-09-18 13:03:50 -070041mkdir -p /tmp/ccache
42
Masood Malekghassemi60e5f912015-10-05 15:26:26 -070043# 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).
45mkdir -p /tmp/xdg-cache-home
46
Jan Tattermusch4dc9e722016-01-25 17:00:54 -080047# Inputs
48# DOCKERFILE_DIR - Directory in which Dockerfile file is located.
49# DOCKER_RUN_SCRIPT - Script to run under docker (relative to grpc repo root)
Jan Tattermuschb10a1932017-02-23 23:39:30 +010050# DOCKERHUB_ORGANIZATION - If set, pull a prebuilt image from given dockerhub org.
Jan Tattermusch4dc9e722016-01-25 17:00:54 -080051
52# Use image name based on Dockerfile location checksum
53DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfile | cut -f1 -d\ )
Jan Tattermuschc95eead2015-09-18 13:03:50 -070054
Jan Tattermuschb10a1932017-02-23 23:39:30 +010055if [ "$DOCKERHUB_ORGANIZATION" != "" ]
56then
57 DOCKER_IMAGE_NAME=$DOCKERHUB_ORGANIZATION/$DOCKER_IMAGE_NAME
58 docker pull $DOCKER_IMAGE_NAME
59else
60 # Make sure docker image has been built. Should be instantaneous if so.
61 docker build -t $DOCKER_IMAGE_NAME $DOCKERFILE_DIR
62fi
Jan Tattermuschc95eead2015-09-18 13:03:50 -070063
Jan Tattermusch65854eb2015-10-08 17:35:44 -070064# Choose random name for docker container
65CONTAINER_NAME="run_tests_$(uuidgen)"
Jan Tattermuschc95eead2015-09-18 13:03:50 -070066
Craig Tillereb841e22016-02-11 15:49:16 -080067# Git root as seen by the docker instance
68docker_instance_git_root=/var/local/jenkins/grpc
69
Jan Tattermuschc95eead2015-09-18 13:03:50 -070070# Run tests inside docker
Jan Tattermusche480a6a2016-10-07 12:59:08 +020071DOCKER_EXIT_CODE=0
Jan Tattermuschc95eead2015-09-18 13:03:50 -070072docker run \
73 -e "RUN_TESTS_COMMAND=$RUN_TESTS_COMMAND" \
74 -e "config=$config" \
75 -e "arch=$arch" \
76 -e CCACHE_DIR=/tmp/ccache \
Masood Malekghassemi60e5f912015-10-05 15:26:26 -070077 -e XDG_CACHE_HOME=/tmp/xdg-cache-home \
Craig Tiller2dfd2de2015-11-05 13:14:39 -080078 -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 for why docker is awful' \
Craig Tiller64195a72016-01-04 15:05:35 -080079 -e HOST_GIT_ROOT=$git_root \
Craig Tillereb841e22016-02-11 15:49:16 -080080 -e LOCAL_GIT_ROOT=$docker_instance_git_root \
Craig Tillerc18cbbc2016-01-21 13:13:42 -080081 -e "BUILD_ID=$BUILD_ID" \
Jan Tattermusch261b58c2015-09-18 17:15:48 -070082 -i $TTY_FLAG \
Craig Tillereb841e22016-02-11 15:49:16 -080083 -v "$git_root:$docker_instance_git_root" \
Jan Tattermuschc95eead2015-09-18 13:03:50 -070084 -v /tmp/ccache:/tmp/ccache \
murgatroid9928c06d82015-10-09 16:07:36 -070085 -v /tmp/npm-cache:/tmp/npm-cache \
Masood Malekghassemi60e5f912015-10-05 15:26:26 -070086 -v /tmp/xdg-cache-home:/tmp/xdg-cache-home \
Jan Tattermuschc95eead2015-09-18 13:03:50 -070087 -w /var/local/git/grpc \
Jan Tattermusch65854eb2015-10-08 17:35:44 -070088 --name=$CONTAINER_NAME \
Jan Tattermuschc95eead2015-09-18 13:03:50 -070089 $DOCKER_IMAGE_NAME \
Jan Tattermusche480a6a2016-10-07 12:59:08 +020090 bash -l "/var/local/jenkins/grpc/$DOCKER_RUN_SCRIPT" || DOCKER_EXIT_CODE=$?
Jan Tattermuschc95eead2015-09-18 13:03:50 -070091
Jan Tattermuscha1906d52016-09-19 18:37:17 +020092# use unique name for reports.zip to prevent clash between concurrent
93# run_tests.py runs
94TEMP_REPORTS_ZIP=`mktemp`
95docker cp "$CONTAINER_NAME:/var/local/git/grpc/reports.zip" ${TEMP_REPORTS_ZIP} || true
96unzip -o ${TEMP_REPORTS_ZIP} -d $git_root || true
97rm -f ${TEMP_REPORTS_ZIP}
Nicolas "Pixel" Noble4d977072015-10-02 23:52:38 +020098
Jan Tattermuschc95eead2015-09-18 13:03:50 -070099# remove the container, possibly killing it first
Jan Tattermusch65854eb2015-10-08 17:35:44 -0700100docker rm -f $CONTAINER_NAME || true
Jan Tattermuschc95eead2015-09-18 13:03:50 -0700101
Jan Tattermusche480a6a2016-10-07 12:59:08 +0200102exit $DOCKER_EXIT_CODE