OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 2 # Copyright 2016, Google Inc. |
| 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 # Builds docker image and runs a command under it. |
| 32 # You should never need to call this script on your own. |
| 33 |
| 34 set -ex |
| 35 |
| 36 cd $(dirname $0)/../.. |
| 37 git_root=$(pwd) |
| 38 cd - |
| 39 |
| 40 # Inputs |
| 41 # DOCKERFILE_DIR - Directory in which Dockerfile file is located. |
| 42 # DOCKER_RUN_SCRIPT - Script to run under docker (relative to grpc repo root) |
| 43 # OUTPUT_DIR - Directory that will be copied from inside docker after finishing. |
| 44 # $@ - Extra args to pass to docker run |
| 45 |
| 46 # Use image name based on Dockerfile location checksum |
| 47 DOCKER_IMAGE_NAME=$(basename $DOCKERFILE_DIR)_$(sha1sum $DOCKERFILE_DIR/Dockerfi
le | cut -f1 -d\ ) |
| 48 |
| 49 # Make sure docker image has been built. Should be instantaneous if so. |
| 50 docker build -t $DOCKER_IMAGE_NAME $DOCKERFILE_DIR |
| 51 |
| 52 # Choose random name for docker container |
| 53 CONTAINER_NAME="build_and_run_docker_$(uuidgen)" |
| 54 |
| 55 # Run command inside docker |
| 56 docker run \ |
| 57 "$@" \ |
| 58 -e EXTERNAL_GIT_ROOT="/var/local/jenkins/grpc" \ |
| 59 -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 fo
r why docker is awful' \ |
| 60 -v "$git_root:/var/local/jenkins/grpc:ro" \ |
| 61 -w /var/local/git/grpc \ |
| 62 --name=$CONTAINER_NAME \ |
| 63 $DOCKER_IMAGE_NAME \ |
| 64 bash -l "/var/local/jenkins/grpc/$DOCKER_RUN_SCRIPT" || FAILED="true" |
| 65 |
| 66 # Copy output artifacts |
| 67 if [ "$OUTPUT_DIR" != "" ] |
| 68 then |
| 69 docker cp "$CONTAINER_NAME:/var/local/git/grpc/$OUTPUT_DIR" "$git_root" || FAI
LED="true" |
| 70 fi |
| 71 |
| 72 # remove the container, possibly killing it first |
| 73 docker rm -f $CONTAINER_NAME || true |
| 74 |
| 75 if [ "$FAILED" != "" ] |
| 76 then |
| 77 exit 1 |
| 78 fi |
OLD | NEW |