Make it possible to pass --debug through to the script run inside the Docker
[arvados-dev.git] / jenkins / run-build-packages-all-targets.sh
1 #!/bin/bash
2
3 read -rd "\000" helpmessage <<EOF
4 $(basename $0): Orchestrate run-build-packages.sh for every target
5
6 Syntax:
7         WORKSPACE=/path/to/arvados $(basename $0) [options]
8
9 Options:
10
11 --command
12     Build command to execute (default: use built-in Docker image command)
13 --debug
14     Output debug information (default: false)
15
16 WORKSPACE=path         Path to the Arvados source tree to build packages from
17
18 EOF
19
20 if ! [[ -n "$WORKSPACE" ]]; then
21   echo >&2 "$helpmessage"
22   echo >&2
23   echo >&2 "Error: WORKSPACE environment variable not set"
24   echo >&2
25   exit 1
26 fi
27
28 if ! [[ -d "$WORKSPACE" ]]; then
29   echo >&2 "$helpmessage"
30   echo >&2
31   echo >&2 "Error: $WORKSPACE is not a directory"
32   echo >&2
33   exit 1
34 fi
35
36 set -e
37
38 PARSEDOPTS=$(getopt --name "$0" --longoptions \
39     help,debug,command: \
40     -- "" "$@")
41 if [ $? -ne 0 ]; then
42     exit 1
43 fi
44
45 COMMAND=
46 DEBUG=
47
48 eval set -- "$PARSEDOPTS"
49 while [ $# -gt 0 ]; do
50     case "$1" in
51         --help)
52             echo >&2 "$helpmessage"
53             echo >&2
54             exit 1
55             ;;
56         --debug)
57             DEBUG=" --debug"
58             ;;
59         --command)
60             COMMAND="$2"; shift
61             ;;
62         --)
63             if [ $# -gt 1 ]; then
64                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
65                 exit 1
66             fi
67             ;;
68     esac
69     shift
70 done
71
72 if [[ "$COMMAND" != "" ]]; then
73   COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND$DEBUG"
74 fi
75
76 FINAL_EXITCODE=0
77 JENKINS_DIR=$(dirname "$(readlink -e "$0")")
78
79 run_docker() {
80     local tag=$1; shift
81     if [[ "$COMMAND" != "" ]]; then
82       COMMAND="$COMMAND --target $tag"
83     fi
84     if docker run -v "$JENKINS_DIR:/jenkins" -v "$WORKSPACE:/arvados" \
85           --env ARVADOS_DEBUG=1 "arvados/build:$tag" $COMMAND; then
86         # Success - nothing more to do.
87         true
88     else
89         FINAL_EXITCODE=$?
90         echo "ERROR: $tag build failed with exit status $FINAL_EXITCODE." >&2
91     fi
92 }
93
94 # In case it's needed, build the containers. This costs just a few
95 # seconds when the containers already exist, so it's not a big deal to
96 # do it on each run.
97 cd "$JENKINS_DIR/dockerfiles"
98 time ./build-all-build-containers.sh
99
100 for dockerfile_path in $(find -name Dockerfile); do
101     run_docker "$(basename $(dirname "$dockerfile_path"))"
102 done
103
104 exit $FINAL_EXITCODE