Merge branch 'master' of git.curoverse.com:arvados into 11876-r-sdk
[arvados.git] / build / run-build-packages.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: AGPL-3.0
5
6 . `dirname "$(readlink -f "$0")"`/run-library.sh
7 . `dirname "$(readlink -f "$0")"`/libcloud-pin.sh
8
9 read -rd "\000" helpmessage <<EOF
10 $(basename $0): Build Arvados packages
11
12 Syntax:
13         WORKSPACE=/path/to/arvados $(basename $0) [options]
14
15 Options:
16
17 --build-bundle-packages  (default: false)
18     Build api server and workbench packages with vendor/bundle included
19 --debug
20     Output debug information (default: false)
21 --target <target>
22     Distribution to build packages for (default: debian8)
23 --only-build <package>
24     Build only a specific package (or $ONLY_BUILD from environment)
25 --command
26     Build command to execute (defaults to the run command defined in the
27     Docker image)
28
29 WORKSPACE=path         Path to the Arvados source tree to build packages from
30
31 EOF
32
33 EXITCODE=0
34 DEBUG=${ARVADOS_DEBUG:-0}
35 TARGET=debian8
36 COMMAND=
37
38 PARSEDOPTS=$(getopt --name "$0" --longoptions \
39     help,build-bundle-packages,debug,target:,only-build: \
40     -- "" "$@")
41 if [ $? -ne 0 ]; then
42     exit 1
43 fi
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         --target)
54             TARGET="$2"; shift
55             ;;
56         --only-build)
57             ONLY_BUILD="$2"; shift
58             ;;
59         --debug)
60             DEBUG=1
61             ;;
62         --command)
63             COMMAND="$2"; shift
64             ;;
65         --)
66             if [ $# -gt 1 ]; then
67                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
68                 exit 1
69             fi
70             ;;
71     esac
72     shift
73 done
74
75 if [[ "$COMMAND" != "" ]]; then
76   COMMAND="/usr/local/rvm/bin/rvm-exec default bash /jenkins/$COMMAND --target $TARGET"
77 fi
78
79 STDOUT_IF_DEBUG=/dev/null
80 STDERR_IF_DEBUG=/dev/null
81 DASHQ_UNLESS_DEBUG=-q
82 if [[ "$DEBUG" != 0 ]]; then
83     STDOUT_IF_DEBUG=/dev/stdout
84     STDERR_IF_DEBUG=/dev/stderr
85     DASHQ_UNLESS_DEBUG=
86 fi
87
88 declare -a PYTHON_BACKPORTS PYTHON3_BACKPORTS
89
90 PYTHON2_VERSION=2.7
91 PYTHON3_VERSION=$(python3 -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')
92
93 ## These defaults are suitable for any Debian-based distribution.
94 # You can customize them as needed in distro sections below.
95 PYTHON2_PACKAGE=python$PYTHON2_VERSION
96 PYTHON2_PKG_PREFIX=python
97 PYTHON2_PREFIX=/usr
98 PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/dist-packages
99
100 PYTHON3_PACKAGE=python$PYTHON3_VERSION
101 PYTHON3_PKG_PREFIX=python3
102 PYTHON3_PREFIX=/usr
103 PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/dist-packages
104 ## End Debian Python defaults.
105
106 case "$TARGET" in
107     debian8)
108         FORMAT=deb
109         ;;
110     debian9)
111         FORMAT=deb
112         ;;
113     ubuntu1204)
114         FORMAT=deb
115         ;;
116     ubuntu1404)
117         FORMAT=deb
118         ;;
119     ubuntu1604)
120         FORMAT=deb
121         ;;
122     centos7)
123         FORMAT=rpm
124         PYTHON2_PACKAGE=$(rpm -qf "$(which python$PYTHON2_VERSION)" --queryformat '%{NAME}\n')
125         PYTHON2_PKG_PREFIX=$PYTHON2_PACKAGE
126         PYTHON2_INSTALL_LIB=lib/python$PYTHON2_VERSION/site-packages
127         PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
128         PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
129         PYTHON3_PREFIX=/opt/rh/python33/root/usr
130         PYTHON3_INSTALL_LIB=lib/python$PYTHON3_VERSION/site-packages
131         export PYCURL_SSL_LIBRARY=nss
132         ;;
133     *)
134         echo -e "$0: Unknown target '$TARGET'.\n" >&2
135         exit 1
136         ;;
137 esac
138
139
140 if ! [[ -n "$WORKSPACE" ]]; then
141   echo >&2 "$helpmessage"
142   echo >&2
143   echo >&2 "Error: WORKSPACE environment variable not set"
144   echo >&2
145   exit 1
146 fi
147
148 # Test for fpm
149 fpm --version >/dev/null 2>&1
150
151 if [[ "$?" != 0 ]]; then
152   echo >&2 "$helpmessage"
153   echo >&2
154   echo >&2 "Error: fpm not found"
155   echo >&2
156   exit 1
157 fi
158
159 EASY_INSTALL2=$(find_easy_install -$PYTHON2_VERSION "")
160 EASY_INSTALL3=$(find_easy_install -$PYTHON3_VERSION 3)
161
162 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
163 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`"  # absolutized and normalized
164 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
165   # error; for some reason, the path is not accessible
166   # to the script (e.g. permissions re-evaled after suid)
167   exit 1  # fail
168 fi
169
170 debug_echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
171 debug_echo "Workspace is $WORKSPACE"
172
173 if [[ -f /etc/profile.d/rvm.sh ]]; then
174     source /etc/profile.d/rvm.sh
175     GEM="rvm-exec default gem"
176 else
177     GEM=gem
178 fi
179
180 # Make all files world-readable -- jenkins runs with umask 027, and has checked
181 # out our git tree here
182 chmod o+r "$WORKSPACE" -R
183
184 # More cleanup - make sure all executables that we'll package are 755
185 cd "$WORKSPACE"
186 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
187
188 # Now fix our umask to something better suited to building and publishing
189 # gems and packages
190 umask 0022
191
192 debug_echo "umask is" `umask`
193
194 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
195   mkdir -p $WORKSPACE/packages/$TARGET
196   chown --reference="$WORKSPACE" "$WORKSPACE/packages/$TARGET"
197 fi
198
199 # Perl packages
200 debug_echo -e "\nPerl packages\n"
201
202 if [[ -z "$ONLY_BUILD" ]] || [[ "libarvados-perl" = "$ONLY_BUILD" ]] ; then
203   cd "$WORKSPACE/sdk/perl"
204   libarvados_perl_version="$(version_from_git)"
205
206   cd $WORKSPACE/packages/$TARGET
207   test_package_presence libarvados-perl "$libarvados_perl_version"
208
209   if [[ "$?" == "0" ]]; then
210     cd "$WORKSPACE/sdk/perl"
211
212     if [[ -e Makefile ]]; then
213       make realclean >"$STDOUT_IF_DEBUG"
214     fi
215     find -maxdepth 1 \( -name 'MANIFEST*' -or -name "libarvados-perl*.$FORMAT" \) \
216         -delete
217     rm -rf install
218
219     perl Makefile.PL INSTALL_BASE=install >"$STDOUT_IF_DEBUG" && \
220         make install INSTALLDIRS=perl >"$STDOUT_IF_DEBUG" && \
221         fpm_build install/lib/=/usr/share libarvados-perl \
222         "Curoverse, Inc." dir "$(version_from_git)" install/man/=/usr/share/man \
223         "$WORKSPACE/apache-2.0.txt=/usr/share/doc/libarvados-perl/apache-2.0.txt" && \
224         mv --no-clobber libarvados-perl*.$FORMAT "$WORKSPACE/packages/$TARGET/"
225   fi
226 fi
227
228 # Ruby gems
229 debug_echo -e "\nRuby gems\n"
230
231 FPM_GEM_PREFIX=$($GEM environment gemdir)
232
233 cd "$WORKSPACE/sdk/ruby"
234 handle_ruby_gem arvados
235
236 cd "$WORKSPACE/sdk/cli"
237 handle_ruby_gem arvados-cli
238
239 cd "$WORKSPACE/services/login-sync"
240 handle_ruby_gem arvados-login-sync
241
242 # Python packages
243 debug_echo -e "\nPython packages\n"
244
245 cd "$WORKSPACE/sdk/pam"
246 handle_python_package
247
248 cd "$WORKSPACE/sdk/python"
249 handle_python_package
250
251 cd "$WORKSPACE/sdk/cwl"
252 handle_python_package
253
254 cd "$WORKSPACE/services/fuse"
255 handle_python_package
256
257 cd "$WORKSPACE/services/nodemanager"
258 handle_python_package
259
260 # arvados-src
261 (
262     cd "$WORKSPACE"
263     COMMIT_HASH=$(format_last_commit_here "%H")
264     arvados_src_version="$(version_from_git)"
265
266     cd $WORKSPACE/packages/$TARGET
267     test_package_presence arvados-src $arvados_src_version src ""
268
269     if [[ "$?" == "0" ]]; then
270       cd "$WORKSPACE"
271       SRC_BUILD_DIR=$(mktemp -d)
272       # mktemp creates the directory with 0700 permissions by default
273       chmod 755 $SRC_BUILD_DIR
274       git clone $DASHQ_UNLESS_DEBUG "$WORKSPACE/.git" "$SRC_BUILD_DIR"
275       cd "$SRC_BUILD_DIR"
276
277       # go into detached-head state
278       git checkout $DASHQ_UNLESS_DEBUG "$COMMIT_HASH"
279       echo "$COMMIT_HASH" >git-commit.version
280
281       cd "$SRC_BUILD_DIR"
282       PKG_VERSION=$(version_from_git)
283       cd $WORKSPACE/packages/$TARGET
284       fpm_build $SRC_BUILD_DIR/=/usr/local/arvados/src arvados-src 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--exclude=usr/local/arvados/src/.git" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=The Arvados source code" "--architecture=all"
285
286       rm -rf "$SRC_BUILD_DIR"
287
288     fi
289 )
290
291 # On older platforms we need to publish a backport of libfuse >=2.9.2,
292 # and we need to build and install it here in order to even build an
293 # llfuse package.
294 cd $WORKSPACE/packages/$TARGET
295 if [[ $TARGET =~ ubuntu1204 ]]; then
296     # port libfuse 2.9.2 to Ubuntu 12.04
297     LIBFUSE_DIR=$(mktemp -d)
298     (
299         cd $LIBFUSE_DIR
300         # download fuse 2.9.2 ubuntu 14.04 source package
301         file="fuse_2.9.2.orig.tar.xz" && curl -L -o "${file}" "http://archive.ubuntu.com/ubuntu/pool/main/f/fuse/${file}"
302         file="fuse_2.9.2-4ubuntu4.14.04.1.debian.tar.xz" && curl -L -o "${file}" "http://archive.ubuntu.com/ubuntu/pool/main/f/fuse/${file}"
303         file="fuse_2.9.2-4ubuntu4.14.04.1.dsc" && curl -L -o "${file}" "http://archive.ubuntu.com/ubuntu/pool/main/f/fuse/${file}"
304
305         # install dpkg-source and dpkg-buildpackage commands
306         apt-get install -y --no-install-recommends dpkg-dev
307
308         # extract source and apply patches
309         dpkg-source -x fuse_2.9.2-4ubuntu4.14.04.1.dsc
310         rm -f fuse_2.9.2.orig.tar.xz fuse_2.9.2-4ubuntu4.14.04.1.debian.tar.xz fuse_2.9.2-4ubuntu4.14.04.1.dsc
311
312         # add new version to changelog
313         cd fuse-2.9.2
314         (
315             echo "fuse (2.9.2-5) precise; urgency=low"
316             echo
317             echo "  * Backported from trusty-security to precise"
318             echo
319             echo " -- Joshua Randall <jcrandall@alum.mit.edu>  Thu, 4 Feb 2016 11:31:00 -0000"
320             echo
321             cat debian/changelog
322         ) > debian/changelog.new
323         mv debian/changelog.new debian/changelog
324
325         # install build-deps and build
326         apt-get install -y --no-install-recommends debhelper dh-autoreconf libselinux-dev
327         dpkg-buildpackage -rfakeroot -b
328     )
329     fpm_build "$LIBFUSE_DIR/fuse_2.9.2-5_amd64.deb" fuse "Ubuntu Developers" deb "2.9.2" --iteration 5
330     fpm_build "$LIBFUSE_DIR/libfuse2_2.9.2-5_amd64.deb" libfuse2 "Ubuntu Developers" deb "2.9.2" --iteration 5
331     fpm_build "$LIBFUSE_DIR/libfuse-dev_2.9.2-5_amd64.deb" libfuse-dev "Ubuntu Developers" deb "2.9.2" --iteration 5
332     dpkg -i \
333         "$WORKSPACE/packages/$TARGET/fuse_2.9.2-5_amd64.deb" \
334         "$WORKSPACE/packages/$TARGET/libfuse2_2.9.2-5_amd64.deb" \
335         "$WORKSPACE/packages/$TARGET/libfuse-dev_2.9.2-5_amd64.deb"
336     apt-get -y --no-install-recommends -f install
337     rm -rf $LIBFUSE_DIR
338 fi
339
340 # Go binaries
341 cd $WORKSPACE/packages/$TARGET
342 export GOPATH=$(mktemp -d)
343 go get -v github.com/kardianos/govendor
344 package_go_binary sdk/go/crunchrunner crunchrunner \
345     "Crunchrunner executes a command inside a container and uploads the output"
346 package_go_binary services/arv-git-httpd arvados-git-httpd \
347     "Provide authenticated http access to Arvados-hosted git repositories"
348 package_go_binary services/crunch-dispatch-local crunch-dispatch-local \
349     "Dispatch Crunch containers on the local system"
350 package_go_binary services/crunch-dispatch-slurm crunch-dispatch-slurm \
351     "Dispatch Crunch containers to a SLURM cluster"
352 package_go_binary services/crunch-run crunch-run \
353     "Supervise a single Crunch container"
354 package_go_binary services/crunchstat crunchstat \
355     "Gather cpu/memory/network statistics of running Crunch jobs"
356 package_go_binary services/health arvados-health \
357     "Check health of all Arvados cluster services"
358 package_go_binary services/keep-balance keep-balance \
359     "Rebalance and garbage-collect data blocks stored in Arvados Keep"
360 package_go_binary services/keepproxy keepproxy \
361     "Make a Keep cluster accessible to clients that are not on the LAN"
362 package_go_binary services/keepstore keepstore \
363     "Keep storage daemon, accessible to clients on the LAN"
364 package_go_binary services/keep-web keep-web \
365     "Static web hosting service for user data stored in Arvados Keep"
366 package_go_binary services/ws arvados-ws \
367     "Arvados Websocket server"
368 package_go_binary tools/arv-sync-groups arv-sync-groups \
369     "Synchronize remote groups into Arvados from an external source"
370 package_go_binary tools/keep-block-check keep-block-check \
371     "Verify that all data from one set of Keep servers to another was copied"
372 package_go_binary tools/keep-rsync keep-rsync \
373     "Copy all data from one set of Keep servers to another"
374 package_go_binary tools/keep-exercise keep-exercise \
375     "Performance testing tool for Arvados Keep"
376
377 # The Python SDK
378 # Please resist the temptation to add --no-python-fix-name to the fpm call here
379 # (which would remove the python- prefix from the package name), because this
380 # package is a dependency of arvados-fuse, and fpm can not omit the python-
381 # prefix from only one of the dependencies of a package...  Maybe I could
382 # whip up a patch and send it upstream, but that will be for another day. Ward,
383 # 2014-05-15
384 cd $WORKSPACE/packages/$TARGET
385 rm -rf "$WORKSPACE/sdk/python/build"
386 arvados_python_client_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/python/arvados_python_client.egg-info/PKG-INFO)
387 test_package_presence ${PYTHON2_PKG_PREFIX}-arvados-python-client "$arvados_python_client_version" python
388 if [[ "$?" == "0" ]]; then
389   fpm_build $WORKSPACE/sdk/python "${PYTHON2_PKG_PREFIX}-arvados-python-client" 'Curoverse, Inc.' 'python' "$arvados_python_client_version" "--url=https://arvados.org" "--description=The Arvados Python SDK" --depends "${PYTHON2_PKG_PREFIX}-setuptools" --deb-recommends=git
390 fi
391
392 # cwl-runner
393 cd $WORKSPACE/packages/$TARGET
394 rm -rf "$WORKSPACE/sdk/cwl/build"
395 arvados_cwl_runner_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/cwl/arvados_cwl_runner.egg-info/PKG-INFO)
396 arvados_cwl_runner_iteration=3
397 test_package_presence ${PYTHON2_PKG_PREFIX}-arvados-cwl-runner "$arvados_cwl_runner_version" python "$arvados_cwl_runner_iteration"
398 if [[ "$?" == "0" ]]; then
399   fpm_build $WORKSPACE/sdk/cwl "${PYTHON2_PKG_PREFIX}-arvados-cwl-runner" 'Curoverse, Inc.' 'python' "$arvados_cwl_runner_version" "--url=https://arvados.org" "--description=The Arvados CWL runner" --depends "${PYTHON2_PKG_PREFIX}-setuptools" --iteration $arvados_cwl_runner_iteration
400 fi
401
402 # schema_salad. This is a python dependency of arvados-cwl-runner,
403 # but we can't use the usual PYTHONPACKAGES way to build this package due to the
404 # intricacies of how version numbers get generated in setup.py: we need a specific version,
405 # e.g. 1.7.20160316203940. If we don't explicitly list that version with the -v
406 # argument to fpm, and instead specify it as schema_salad==1.7.20160316203940, we get
407 # a package with version 1.7. That's because our gittagger hack is not being
408 # picked up by self.distribution.get_version(), which is called from
409 # https://github.com/jordansissel/fpm/blob/master/lib/fpm/package/pyfpm/get_metadata.py
410 # by means of this command:
411 #
412 # python2.7 setup.py --command-packages=pyfpm get_metadata --output=metadata.json
413 #
414 # So we build this thing separately.
415 #
416 # Ward, 2016-03-17
417 saladversion=$(cat "$WORKSPACE/sdk/cwl/setup.py" | grep schema-salad== | sed "s/.*==\(.*\)'.*/\1/")
418 test_package_presence python-schema-salad "$saladversion" python
419 if [[ "$?" == "0" ]]; then
420   fpm_build schema_salad "" "" python $saladversion --depends "${PYTHON2_PKG_PREFIX}-lockfile >= 1:0.12.2-2" --depends "${PYTHON2_PKG_PREFIX}-avro = 1.8.1-2"
421 fi
422
423 # And for cwltool we have the same problem as for schema_salad. Ward, 2016-03-17
424 cwltoolversion=$(cat "$WORKSPACE/sdk/cwl/setup.py" | grep cwltool== | sed "s/.*==\(.*\)'.*/\1/")
425 test_package_presence python-cwltool "$cwltoolversion" python
426 if [[ "$?" == "0" ]]; then
427   fpm_build cwltool "" "" python $cwltoolversion
428 fi
429
430 # The PAM module
431 if [[ $TARGET =~ debian|ubuntu ]]; then
432     cd $WORKSPACE/packages/$TARGET
433     rm -rf "$WORKSPACE/sdk/pam/build"
434     libpam_arvados_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/pam/arvados_pam.egg-info/PKG-INFO)
435     test_package_presence libpam-arvados "$libpam_arvados_version" python
436     if [[ "$?" == "0" ]]; then
437       fpm_build $WORKSPACE/sdk/pam libpam-arvados 'Curoverse, Inc.' 'python' "$libpam_arvados_version" "--url=https://arvados.org" "--description=PAM module for authenticating shell logins using Arvados API tokens" --depends libpam-python
438     fi
439 fi
440
441 # The FUSE driver
442 # Please see comment about --no-python-fix-name above; we stay consistent and do
443 # not omit the python- prefix first.
444 cd $WORKSPACE/packages/$TARGET
445 rm -rf "$WORKSPACE/services/fuse/build"
446 arvados_fuse_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/fuse/arvados_fuse.egg-info/PKG-INFO)
447 test_package_presence "${PYTHON2_PKG_PREFIX}-arvados-fuse" "$arvados_fuse_version" python
448 if [[ "$?" == "0" ]]; then
449   fpm_build $WORKSPACE/services/fuse "${PYTHON2_PKG_PREFIX}-arvados-fuse" 'Curoverse, Inc.' 'python' "$arvados_fuse_version" "--url=https://arvados.org" "--description=The Keep FUSE driver" --depends "${PYTHON2_PKG_PREFIX}-setuptools"
450 fi
451
452 # The node manager
453 cd $WORKSPACE/packages/$TARGET
454 rm -rf "$WORKSPACE/services/nodemanager/build"
455 nodemanager_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/nodemanager/arvados_node_manager.egg-info/PKG-INFO)
456 test_package_presence arvados-node-manager "$nodemanager_version" python
457 if [[ "$?" == "0" ]]; then
458   fpm_build $WORKSPACE/services/nodemanager arvados-node-manager 'Curoverse, Inc.' 'python' "$nodemanager_version" "--url=https://arvados.org" "--description=The Arvados node manager" --depends "${PYTHON2_PKG_PREFIX}-setuptools"
459 fi
460
461 # The Docker image cleaner
462 cd $WORKSPACE/packages/$TARGET
463 rm -rf "$WORKSPACE/services/dockercleaner/build"
464 dockercleaner_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/dockercleaner/arvados_docker_cleaner.egg-info/PKG-INFO)
465 dockercleaner_iteration=3
466 test_package_presence arvados-docker-cleaner "$dockercleaner_version" python "$dockercleaner_iteration"
467 if [[ "$?" == "0" ]]; then
468   fpm_build $WORKSPACE/services/dockercleaner arvados-docker-cleaner 'Curoverse, Inc.' 'python3' "$dockercleaner_version" "--url=https://arvados.org" "--description=The Arvados Docker image cleaner" --depends "${PYTHON3_PKG_PREFIX}-websocket-client = 0.37.0" --iteration "$dockercleaner_iteration"
469 fi
470
471 # The Arvados crunchstat-summary tool
472 cd $WORKSPACE/packages/$TARGET
473 crunchstat_summary_version=$(awk '($1 == "Version:"){print $2}' $WORKSPACE/tools/crunchstat-summary/crunchstat_summary.egg-info/PKG-INFO)
474 test_package_presence "$PYTHON2_PKG_PREFIX"-crunchstat-summary "$crunchstat_summary_version" python
475 if [[ "$?" == "0" ]]; then
476   rm -rf "$WORKSPACE/tools/crunchstat-summary/build"
477   fpm_build $WORKSPACE/tools/crunchstat-summary ${PYTHON2_PKG_PREFIX}-crunchstat-summary 'Curoverse, Inc.' 'python' "$crunchstat_summary_version" "--url=https://arvados.org" "--description=Crunchstat-summary reads Arvados Crunch log files and summarize resource usage"
478 fi
479
480 if [[ -z "$ONLY_BUILD" ]] || [[ "${PYTHON2_PKG_PREFIX}-apache-libcloud" == "$ONLY_BUILD" ]] ; then
481   # Forked libcloud
482   LIBCLOUD_DIR=$(mktemp -d)
483   (
484       cd $LIBCLOUD_DIR
485       git clone $DASHQ_UNLESS_DEBUG https://github.com/curoverse/libcloud.git .
486       git checkout $DASHQ_UNLESS_DEBUG apache-libcloud-$LIBCLOUD_PIN
487       # libcloud is absurdly noisy without -q, so force -q here
488       OLD_DASHQ_UNLESS_DEBUG=$DASHQ_UNLESS_DEBUG
489       DASHQ_UNLESS_DEBUG=-q
490       handle_python_package
491       DASHQ_UNLESS_DEBUG=$OLD_DASHQ_UNLESS_DEBUG
492   )
493   fpm_build $LIBCLOUD_DIR "$PYTHON2_PKG_PREFIX"-apache-libcloud
494   rm -rf $LIBCLOUD_DIR
495 fi
496
497 # Python 2 dependencies
498 declare -a PIP_DOWNLOAD_SWITCHES=(--no-deps)
499 # Add --no-use-wheel if this pip knows it.
500 pip wheel --help >/dev/null 2>&1
501 case "$?" in
502     0) PIP_DOWNLOAD_SWITCHES+=(--no-use-wheel) ;;
503     2) ;;
504     *) echo "WARNING: `pip wheel` test returned unknown exit code $?" ;;
505 esac
506
507 while read -r line || [[ -n "$line" ]]; do
508 #  echo "Text read from file: $line"
509   if [[ "$line" =~ ^# ]]; then
510     continue
511   fi
512   IFS='|'; arr=($line); unset IFS
513
514   dist=${arr[0]}
515
516   IFS=',';dists=($dist); unset IFS
517
518   MATCH=0
519   for d in "${dists[@]}"; do
520     if [[ "$d" == "$TARGET" ]] || [[ "$d" == "all" ]]; then
521       MATCH=1
522     fi
523   done
524
525   if [[ "$MATCH" != "1" ]]; then
526     continue
527   fi
528   name=${arr[1]}
529   version=${arr[2]}
530   iteration=${arr[3]}
531   pkgtype=${arr[4]}
532   arch=${arr[5]}
533   extra=${arr[6]}
534   declare -a 'extra_arr=('"$extra"')'
535
536   if [[ "$FORMAT" == "rpm" ]]; then
537     if [[ "$arch" == "all" ]]; then
538       arch="noarch"
539     fi
540     if [[ "$arch" == "amd64" ]]; then
541       arch="x86_64"
542     fi
543   fi
544
545   if [[ "$pkgtype" == "python" ]]; then
546     outname=$(echo "$name" | sed -e 's/^python-//' -e 's/_/-/g' -e "s/^/${PYTHON2_PKG_PREFIX}-/")
547   else
548     outname=$(echo "$name" | sed -e 's/^python-//' -e 's/_/-/g' -e "s/^/${PYTHON3_PKG_PREFIX}-/")
549   fi
550
551   if [[ -n "$ONLY_BUILD" ]] && [[ "$outname" != "$ONLY_BUILD" ]] ; then
552       continue
553   fi
554
555   case "$name" in
556       httplib2|google-api-python-client)
557           test_package_presence $outname $version $pkgtype $iteration $arch
558           if [[ "$?" == "0" ]]; then
559             # Work around 0640 permissions on some package files.
560             # See #7591 and #7991.
561             pyfpm_workdir=$(mktemp --tmpdir -d pyfpm-XXXXXX) && (
562                 set -e
563                 cd "$pyfpm_workdir"
564                 pip install "${PIP_DOWNLOAD_SWITCHES[@]}" --download . "$name==$version"
565                 # Sometimes pip gives us a tarball, sometimes a zip file...
566                 DOWNLOADED=`ls $name-*`
567                 [[ "$DOWNLOADED" =~ ".tar" ]] && tar -xf $DOWNLOADED
568                 [[ "$DOWNLOADED" =~ ".zip" ]] && unzip $DOWNLOADED
569                 cd "$name"-*/
570                 "python$PYTHON2_VERSION" setup.py $DASHQ_UNLESS_DEBUG egg_info build
571                 chmod -R go+rX .
572                 set +e
573                 fpm_build . "$outname" "" "$pkgtype" "$version" --iteration "$iteration" "${extra_arr[@]}"
574                 # The upload step uses the package timestamp to determine
575                 # if it is new.  --no-clobber plays nice with that.
576                 mv --no-clobber "$outname"*.$FORMAT "$WORKSPACE/packages/$TARGET"
577             )
578             if [ 0 != "$?" ]; then
579                 echo "ERROR: $name build process failed"
580                 EXITCODE=1
581             fi
582             if [ -n "$pyfpm_workdir" ]; then
583                 rm -rf "$pyfpm_workdir"
584             fi
585           fi
586           ;;
587       *)
588           test_package_presence $outname $version $pkgtype $iteration $arch
589           if [[ "$?" == "0" ]]; then
590             fpm_build "$name" "$outname" "" "$pkgtype" "$version" --iteration "$iteration" "${extra_arr[@]}"
591           fi
592           ;;
593   esac
594
595 done <`dirname "$(readlink -f "$0")"`"/build.list"
596
597 # Build the API server package
598 test_rails_package_presence arvados-api-server "$WORKSPACE/services/api"
599 if [[ "$?" == "0" ]]; then
600   handle_rails_package arvados-api-server "$WORKSPACE/services/api" \
601       "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
602       --description="Arvados API server - Arvados is a free and open source platform for big data science." \
603       --license="GNU Affero General Public License, version 3.0"
604 fi
605
606 # Build the workbench server package
607 test_rails_package_presence arvados-workbench "$WORKSPACE/apps/workbench"
608 if [[ "$?" == "0" ]] ; then
609   (
610       set -e
611       cd "$WORKSPACE/apps/workbench"
612
613       # We need to bundle to be ready even when we build a package without vendor directory
614       # because asset compilation requires it.
615       bundle install --path vendor/bundle >"$STDOUT_IF_DEBUG"
616
617       # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
618       # and we want that in the package, so it's easier to not exclude the tmp directory
619       # from the package - empty it instead.
620       rm -rf tmp
621       mkdir tmp
622
623       # Set up application.yml and production.rb so that asset precompilation works
624       \cp config/application.yml.example config/application.yml -f
625       \cp config/environments/production.rb.example config/environments/production.rb -f
626       sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
627       sed -i 's/keep_web_url: false/keep_web_url: exampledotcom/' config/application.yml
628
629       RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake npm:install >/dev/null
630       RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
631
632       # Remove generated configuration files so they don't go in the package.
633       rm config/application.yml config/environments/production.rb
634   )
635
636   if [[ "$?" != "0" ]]; then
637     echo "ERROR: Asset precompilation failed"
638     EXITCODE=1
639   else
640     handle_rails_package arvados-workbench "$WORKSPACE/apps/workbench" \
641         "$WORKSPACE/agpl-3.0.txt" --url="https://arvados.org" \
642         --description="Arvados Workbench - Arvados is a free and open source platform for big data science." \
643         --license="GNU Affero General Public License, version 3.0"
644   fi
645 fi
646
647 # clean up temporary GOPATH
648 rm -rf "$GOPATH"
649
650 exit $EXITCODE