closes #10518
[arvados.git] / build / run-build-packages-one-target.sh
1 #!/bin/bash
2
3 read -rd "\000" helpmessage <<EOF
4 $(basename $0): Orchestrate run-build-packages.sh for one target
5
6 Syntax:
7         WORKSPACE=/path/to/arvados $(basename $0) [options]
8
9 --target <target>
10     Distribution to build packages for (default: debian7)
11 --command
12     Build command to execute (default: use built-in Docker image command)
13 --test-packages
14     Run package install test script "test-packages-$target.sh"
15 --debug
16     Output debug information (default: false)
17 --only-build <package>
18     Build only a specific package
19 --only-test <package>
20     Test only a specific package
21
22 WORKSPACE=path         Path to the Arvados source tree to build packages from
23
24 EOF
25
26 set -e
27
28 if ! [[ -n "$WORKSPACE" ]]; then
29   echo >&2 "$helpmessage"
30   echo >&2
31   echo >&2 "Error: WORKSPACE environment variable not set"
32   echo >&2
33   exit 1
34 fi
35
36 if ! [[ -d "$WORKSPACE" ]]; then
37   echo >&2 "$helpmessage"
38   echo >&2
39   echo >&2 "Error: $WORKSPACE is not a directory"
40   echo >&2
41   exit 1
42 fi
43
44 PARSEDOPTS=$(getopt --name "$0" --longoptions \
45     help,debug,test-packages,target:,command:,only-test:,only-build: \
46     -- "" "$@")
47 if [ $? -ne 0 ]; then
48     exit 1
49 fi
50
51 TARGET=debian7
52 COMMAND=
53 DEBUG=
54
55 eval set -- "$PARSEDOPTS"
56 while [ $# -gt 0 ]; do
57     case "$1" in
58         --help)
59             echo >&2 "$helpmessage"
60             echo >&2
61             exit 1
62             ;;
63         --target)
64             TARGET="$2"; shift
65             ;;
66         --only-test)
67             test_packages=1
68             packages="$2"; shift
69             ;;
70         --only-build)
71             ONLY_BUILD="$2"; shift
72             ;;
73         --debug)
74             DEBUG=" --debug"
75             ;;
76         --command)
77             COMMAND="$2"; shift
78             ;;
79         --test-packages)
80             test_packages=1
81             ;;
82         --)
83             if [ $# -gt 1 ]; then
84                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
85                 exit 1
86             fi
87             ;;
88     esac
89     shift
90 done
91
92 set -e
93
94 if [[ -n "$test_packages" ]]; then
95     if [[ -n "$(find $WORKSPACE/packages/$TARGET -name '*.rpm')" ]] ; then
96         createrepo $WORKSPACE/packages/$TARGET
97     fi
98
99     if [[ -n "$(find $WORKSPACE/packages/$TARGET -name '*.deb')" ]] ; then
100         (cd $WORKSPACE/packages/$TARGET
101          dpkg-scanpackages .  2> >(grep -v 'warning' 1>&2) | gzip -c > Packages.gz
102         )
103     fi
104
105     COMMAND="/jenkins/package-testing/test-packages-$TARGET.sh"
106     IMAGE="arvados/package-test:$TARGET"
107 else
108     IMAGE="arvados/build:$TARGET"
109     if [[ "$COMMAND" != "" ]]; then
110         COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET$DEBUG"
111     fi
112 fi
113
114 JENKINS_DIR=$(dirname "$(readlink -e "$0")")
115
116 if [[ -n "$test_packages" ]]; then
117     pushd "$JENKINS_DIR/package-test-dockerfiles"
118 else
119     pushd "$JENKINS_DIR/package-build-dockerfiles"
120     make "$TARGET/generated"
121 fi
122
123 echo $TARGET
124 cd $TARGET
125 time docker build --tag=$IMAGE .
126 popd
127
128 if test -z "$packages" ; then
129     packages="arvados-api-server
130         arvados-data-manager
131         arvados-docker-cleaner
132         arvados-git-httpd
133         arvados-node-manager
134         arvados-src
135         arvados-workbench
136         crunch-dispatch-local
137         crunch-dispatch-slurm
138         crunch-run
139         crunchstat
140         keep-balance
141         keep-block-check
142         keepproxy
143         keep-rsync
144         keepstore
145         keep-web
146         libarvados-perl"
147
148     case "$TARGET" in
149         centos6)
150             packages="$packages python27-python-arvados-fuse
151                   python27-python-arvados-python-client python27-python-arvados-cwl-runner"
152             ;;
153         *)
154             packages="$packages python-arvados-fuse
155                   python-arvados-python-client python-arvados-cwl-runner"
156             ;;
157     esac
158 fi
159
160 FINAL_EXITCODE=0
161
162 package_fails=""
163
164 mkdir -p "$WORKSPACE/apps/workbench/vendor/cache-$TARGET"
165 mkdir -p "$WORKSPACE/services/api/vendor/cache-$TARGET"
166
167 docker_volume_args=(
168     -v "$JENKINS_DIR:/jenkins"
169     -v "$WORKSPACE:/arvados"
170     -v /arvados/services/api/vendor/bundle
171     -v /arvados/apps/workbench/vendor/bundle
172     -v "$WORKSPACE/services/api/vendor/cache-$TARGET:/arvados/services/api/vendor/cache"
173     -v "$WORKSPACE/apps/workbench/vendor/cache-$TARGET:/arvados/apps/workbench/vendor/cache"
174 )
175
176 if [[ -n "$test_packages" ]]; then
177     for p in $packages ; do
178         echo
179         echo "START: $p test on $IMAGE" >&2
180         if docker run --rm \
181             "${docker_volume_args[@]}" \
182             --env ARVADOS_DEBUG=1 \
183             --env "TARGET=$TARGET" \
184             --env "WORKSPACE=/arvados" \
185             "$IMAGE" $COMMAND $p
186         then
187             echo "OK: $p test on $IMAGE succeeded" >&2
188         else
189             FINAL_EXITCODE=$?
190             package_fails="$package_fails $p"
191             echo "ERROR: $p test on $IMAGE failed with exit status $FINAL_EXITCODE" >&2
192         fi
193     done
194 else
195     echo
196     echo "START: build packages on $IMAGE" >&2
197     if docker run --rm \
198         "${docker_volume_args[@]}" \
199         --env ARVADOS_DEBUG=1 \
200         --env "ONLY_BUILD=$ONLY_BUILD" \
201         "$IMAGE" $COMMAND
202     then
203         echo
204         echo "OK: build packages on $IMAGE succeeded" >&2
205     else
206         FINAL_EXITCODE=$?
207         echo "ERROR: build packages on $IMAGE failed with exit status $FINAL_EXITCODE" >&2
208     fi
209 fi
210
211 if test -n "$package_fails" ; then
212     echo "Failed package tests:$package_fails" >&2
213 fi
214
215 exit $FINAL_EXITCODE