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