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" \ | |
37 -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 fo
r why docker is awful' \ | 36 -e THIS_IS_REALLY_NEEDED='see https://github.com/docker/docker/issues/14203 fo
r why docker is awful' \ |
38 -v "$git_root:/var/local/jenkins/protobuf:ro" \ | 37 -v "$git_root:/var/local/jenkins/protobuf:ro" \ |
39 -v $CCACHE_DIR:$CCACHE_DIR \ | 38 -v $CCACHE_DIR:$CCACHE_DIR \ |
40 -w /var/local/git/protobuf \ | 39 -w /var/local/git/protobuf \ |
41 --name=$CONTAINER_NAME \ | 40 --name=$CONTAINER_NAME \ |
42 $DOCKER_IMAGE_NAME \ | 41 $DOCKER_IMAGE_NAME \ |
43 bash -l "/var/local/jenkins/protobuf/$DOCKER_RUN_SCRIPT" || FAILED="true" | 42 bash -l "/var/local/jenkins/protobuf/$DOCKER_RUN_SCRIPT" || FAILED="true" |
44 | 43 |
45 # Copy output artifacts | 44 # Copy output artifacts |
46 if [ "$OUTPUT_DIR" != "" ] | 45 if [ "$OUTPUT_DIR" != "" ] |
47 then | 46 then |
48 docker cp "$CONTAINER_NAME:/var/local/git/protobuf/$OUTPUT_DIR" "$git_root" ||
FAILED="true" | 47 docker cp "$CONTAINER_NAME:/var/local/git/protobuf/$OUTPUT_DIR" "$git_root" ||
FAILED="true" |
49 fi | 48 fi |
50 | 49 |
51 # remove the container, possibly killing it first | 50 # remove the container, possibly killing it first |
52 docker rm -f $CONTAINER_NAME || true | 51 docker rm -f $CONTAINER_NAME || true |
53 | 52 |
54 if [ "$FAILED" != "" ] | 53 if [ "$FAILED" != "" ] |
55 then | 54 then |
56 exit 1 | 55 exit 1 |
57 fi | 56 fi |
OLD | NEW |