| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 # | 2 # |
| 3 # Builds docker image and runs a command under it. | 3 # Builds docker image and runs a command under it. |
| 4 # This is a generic script that is configured with the following variables: | 4 # This is a generic script that is configured with the following variables: |
| 5 # | 5 # |
| 6 # DOCKERFILE_DIR - Directory in which Dockerfile file is located. | 6 # DOCKERFILE_DIR - Directory in which Dockerfile file is located. |
| 7 # DOCKER_RUN_SCRIPT - Script to run under docker (relative to protobuf repo root
) | 7 # DOCKER_RUN_SCRIPT - Script to run under docker (relative to protobuf repo root
) |
| 8 # OUTPUT_DIR - Directory that will be copied from inside docker after finishing. | 8 # OUTPUT_DIR - Directory that will be copied from inside docker after finishing. |
| 9 # $@ - Extra args to pass to docker run | 9 # $@ - Extra args to pass to docker run |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 mkdir -p $CCACHE_DIR | 26 mkdir -p $CCACHE_DIR |
| 27 | 27 |
| 28 # Choose random name for docker container | 28 # Choose random name for docker container |
| 29 CONTAINER_NAME="build_and_run_docker_$(uuidgen)" | 29 CONTAINER_NAME="build_and_run_docker_$(uuidgen)" |
| 30 | 30 |
| 31 # Run command inside docker | 31 # Run command inside docker |
| 32 docker run \ | 32 docker run \ |
| 33 "$@" \ | 33 "$@" \ |
| 34 -e CCACHE_DIR=$CCACHE_DIR \ | 34 -e CCACHE_DIR=$CCACHE_DIR \ |
| 35 -e EXTERNAL_GIT_ROOT="/var/local/jenkins/protobuf" \ | 35 -e EXTERNAL_GIT_ROOT="/var/local/jenkins/protobuf" \ |
| 36 -e TEST_SET="$TEST_SET" \ |
| 36 -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 fo
r why docker is awful' \ | 37 -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 fo
r why docker is awful' \ |
| 37 -v "$git_root:/var/local/jenkins/protobuf:ro" \ | 38 -v "$git_root:/var/local/jenkins/protobuf:ro" \ |
| 38 -v $CCACHE_DIR:$CCACHE_DIR \ | 39 -v $CCACHE_DIR:$CCACHE_DIR \ |
| 39 -w /var/local/git/protobuf \ | 40 -w /var/local/git/protobuf \ |
| 40 --name=$CONTAINER_NAME \ | 41 --name=$CONTAINER_NAME \ |
| 41 $DOCKER_IMAGE_NAME \ | 42 $DOCKER_IMAGE_NAME \ |
| 42 bash -l "/var/local/jenkins/protobuf/$DOCKER_RUN_SCRIPT" || FAILED="true" | 43 bash -l "/var/local/jenkins/protobuf/$DOCKER_RUN_SCRIPT" || FAILED="true" |
| 43 | 44 |
| 44 # Copy output artifacts | 45 # Copy output artifacts |
| 45 if [ "$OUTPUT_DIR" != "" ] | 46 if [ "$OUTPUT_DIR" != "" ] |
| 46 then | 47 then |
| 47 docker cp "$CONTAINER_NAME:/var/local/git/protobuf/$OUTPUT_DIR" "$git_root" ||
FAILED="true" | 48 docker cp "$CONTAINER_NAME:/var/local/git/protobuf/$OUTPUT_DIR" "$git_root" ||
FAILED="true" |
| 48 fi | 49 fi |
| 49 | 50 |
| 50 # remove the container, possibly killing it first | 51 # remove the container, possibly killing it first |
| 51 docker rm -f $CONTAINER_NAME || true | 52 docker rm -f $CONTAINER_NAME || true |
| 52 | 53 |
| 53 if [ "$FAILED" != "" ] | 54 if [ "$FAILED" != "" ] |
| 54 then | 55 then |
| 55 exit 1 | 56 exit 1 |
| 56 fi | 57 fi |
| OLD | NEW |