6934: Build libpam-arvados only for targets that have libpam-python.
[arvados-dev.git] / jenkins / run-build-packages.sh
1 #!/bin/bash
2
3
4 read -rd "\000" helpmessage <<EOF
5 $(basename $0): Build Arvados packages
6
7 Syntax:
8         WORKSPACE=/path/to/arvados $(basename $0) [options]
9
10 Options:
11
12 --build-bundle-packages  (default: false)
13     Build api server and workbench packages with vendor/bundle included
14 --debug
15     Output debug information (default: false)
16 --target
17     Distribution to build packages for (default: debian7)
18
19 WORKSPACE=path         Path to the Arvados source tree to build packages from
20
21 EOF
22
23 EXITCODE=0
24 DEBUG=${ARVADOS_DEBUG:-0}
25 BUILD_BUNDLE_PACKAGES=0
26 TARGET=debian7
27
28 PARSEDOPTS=$(getopt --name "$0" --longoptions \
29     help,build-bundle-packages,debug,target: \
30     -- "" "$@")
31 if [ $? -ne 0 ]; then
32     exit 1
33 fi
34
35 eval set -- "$PARSEDOPTS"
36 while [ $# -gt 0 ]; do
37     case "$1" in
38         --help)
39             echo >&2 "$helpmessage"
40             echo >&2
41             exit 1
42             ;;
43         --target)
44             TARGET="$2"; shift
45             ;;
46         --debug)
47             DEBUG=1
48             ;;
49         --build-bundle-packages)
50             BUILD_BUNDLE_PACKAGES=1
51             ;;
52         --)
53             if [ $# -gt 1 ]; then
54                 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
55                 exit 1
56             fi
57             ;;
58     esac
59     shift
60 done
61
62 declare -a PYTHON_BACKPORTS PYTHON3_BACKPORTS
63
64 PYTHON2_VERSION=2.7
65 PYTHON3_VERSION=$(python3 -c 'import sys; print("{v.major}.{v.minor}".format(v=sys.version_info))')
66
67 case "$TARGET" in
68     debian7)
69         FORMAT=deb
70         PYTHON2_PACKAGE=python$PYTHON2_VERSION
71         PYTHON2_PKG_PREFIX=python
72         PYTHON3_PACKAGE=python$PYTHON3_VERSION
73         PYTHON3_PKG_PREFIX=python3
74         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client \
75             oauth2client pyasn1==0.1.7 pyasn1-modules==0.0.5 \
76             rsa uritemplate httplib2 ws4py \
77             virtualenv pykka apache-libcloud requests six pyexecjs jsonschema \
78             ciso8601 pycrypto backports.ssl_match_hostname pycurl llfuse)
79         PYTHON3_BACKPORTS=(docker-py six requests websocket-client)
80         ;;
81     debian8)
82         FORMAT=deb
83         PYTHON2_PACKAGE=python$PYTHON2_VERSION
84         PYTHON2_PKG_PREFIX=python
85         PYTHON3_PACKAGE=python$PYTHON3_VERSION
86         PYTHON3_PKG_PREFIX=python3
87         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client \
88             oauth2client pyasn1==0.1.7 pyasn1-modules==0.0.5 \
89             rsa uritemplate httplib2 ws4py \
90             virtualenv pykka apache-libcloud requests six pyexecjs jsonschema \
91             ciso8601 pycrypto backports.ssl_match_hostname pycurl llfuse)
92         PYTHON3_BACKPORTS=(docker-py six requests websocket-client)
93         ;;
94     ubuntu1204)
95         FORMAT=deb
96         PYTHON2_PACKAGE=python$PYTHON2_VERSION
97         PYTHON2_PKG_PREFIX=python
98         PYTHON3_PACKAGE=python$PYTHON3_VERSION
99         PYTHON3_PKG_PREFIX=python3
100         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client \
101             oauth2client pyasn1==0.1.7 pyasn1-modules==0.0.5 \
102             rsa uritemplate httplib2 ws4py \
103             virtualenv pykka apache-libcloud requests six pyexecjs jsonschema \
104             ciso8601 pycrypto backports.ssl_match_hostname pycurl llfuse)
105         PYTHON3_BACKPORTS=(docker-py six requests websocket-client)
106         ;;
107     ubuntu1404)
108         FORMAT=deb
109         PYTHON2_PACKAGE=python$PYTHON2_VERSION
110         PYTHON2_PKG_PREFIX=python
111         PYTHON3_PACKAGE=python$PYTHON3_VERSION
112         PYTHON3_PKG_PREFIX=python3
113         PYTHON_BACKPORTS=(pyasn1==0.1.7 pyasn1-modules==0.0.5 llfuse ciso8601 \
114             google-api-python-client six uritemplate oauth2client httplib2 \
115             rsa apache-libcloud pycurl backports.ssl_match_hostname)
116         PYTHON3_BACKPORTS=(docker-py requests websocket-client)
117         ;;
118     centos6)
119         FORMAT=rpm
120         PYTHON2_PACKAGE=$(rpm -qf "$(which python$PYTHON2_VERSION)" --queryformat '%{NAME}\n')
121         PYTHON2_PKG_PREFIX=$PYTHON2_PACKAGE
122         PYTHON3_PACKAGE=$(rpm -qf "$(which python$PYTHON3_VERSION)" --queryformat '%{NAME}\n')
123         PYTHON3_PKG_PREFIX=$PYTHON3_PACKAGE
124         PYTHON_BACKPORTS=(python-gflags pyvcf google-api-python-client \
125             oauth2client pyasn1==0.1.7 pyasn1-modules==0.0.5 \
126             rsa uritemplate httplib2 ws4py \
127             pykka apache-libcloud requests six pyexecjs jsonschema \
128             ciso8601 pycrypto backports.ssl_match_hostname pycurl
129             python-daemon lockfile llfuse)
130         PYTHON3_BACKPORTS=(docker-py six requests)
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 find_easy_install() {
160     for version_suffix in "$@"; do
161         if "easy_install$version_suffix" --version >/dev/null 2>&1; then
162             echo "easy_install$version_suffix"
163             return 0
164         fi
165     done
166     cat >&2 <<EOF
167 $helpmessage
168
169 Error: easy_install$1 (from Python setuptools module) not found
170
171 EOF
172     exit 1
173 }
174
175 EASY_INSTALL2=$(find_easy_install -$PYTHON2_VERSION "")
176 EASY_INSTALL3=$(find_easy_install -$PYTHON3_VERSION 3)
177
178 RUN_BUILD_PACKAGES_PATH="`dirname \"$0\"`"
179 RUN_BUILD_PACKAGES_PATH="`( cd \"$RUN_BUILD_PACKAGES_PATH\" && pwd )`"  # absolutized and normalized
180 if [ -z "$RUN_BUILD_PACKAGES_PATH" ] ; then
181   # error; for some reason, the path is not accessible
182   # to the script (e.g. permissions re-evaled after suid)
183   exit 1  # fail
184 fi
185
186 if [[ "$DEBUG" != 0 ]]; then
187   echo "$0 is running from $RUN_BUILD_PACKAGES_PATH"
188   echo "Workspace is $WORKSPACE"
189 fi
190
191 format_last_commit_here() {
192     local format=$1; shift
193     TZ=UTC git log -n1 --first-parent "--format=format:$format" .
194 }
195
196 version_from_git() {
197   # Generates a version number from the git log for the current working
198   # directory, and writes it to stdout.
199   local git_ts git_hash
200   declare $(format_last_commit_here "git_ts=%ct git_hash=%h")
201   echo "0.1.$(date -ud "@$git_ts" +%Y%m%d%H%M%S).$git_hash"
202 }
203
204 nohash_version_from_git() {
205     version_from_git | cut -d. -f1-3
206 }
207
208 timestamp_from_git() {
209     format_last_commit_here "%ct"
210 }
211
212 handle_python_package () {
213   # This function assumes the current working directory is the python package directory
214   if [ -n "$(find dist -name "*-$(nohash_version_from_git).tar.gz" -print -quit)" ]; then
215     # This package doesn't need rebuilding.
216     return
217   fi
218   # Make sure only to use sdist - that's the only format pip can deal with (sigh)
219   if [[ "$DEBUG" != 0 ]]; then
220     python setup.py sdist
221   else
222     python setup.py -q sdist
223   fi
224 }
225
226 handle_ruby_gem() {
227     local gem_name=$1; shift
228     local gem_version=$(nohash_version_from_git)
229
230     if [ -e "${gem_name}-${gem_version}.gem" ]; then
231         # This gem doesn't need rebuilding.
232         return
233     fi
234
235     find -maxdepth 1 -name "${gem_name}-*.gem" -delete
236
237     if [[ "$DEBUG" != 0 ]]; then
238         gem build "$gem_name.gemspec"
239     else
240         # -q appears to be broken in gem version 2.2.2
241         gem build "$gem_name.gemspec" -q >/dev/null 2>&1
242     fi
243
244     fpm_build "$gem_name"-*.gem "" "Curoverse, Inc." gem "" \
245         --prefix "$FPM_GEM_PREFIX"
246     mv -t "$WORKSPACE/packages/$TARGET/" "$gem_name"*."$FORMAT"
247 }
248
249 # Build packages for everything
250 fpm_build () {
251   # The package source.  Depending on the source type, this can be a
252   # path, or the name of the package in an upstream repository (e.g.,
253   # pip).
254   PACKAGE=$1
255   shift
256   # The name of the package to build.  Defaults to $PACKAGE.
257   PACKAGE_NAME=${1:-$PACKAGE}
258   shift
259   # Optional: the vendor of the package.  Should be "Curoverse, Inc." for
260   # packages of our own software.  Passed to fpm --vendor.
261   VENDOR=$1
262   shift
263   # The type of source package.  Passed to fpm -s.  Default "python".
264   PACKAGE_TYPE=${1:-python}
265   shift
266   # Optional: the package version number.  Passed to fpm -v.
267   VERSION=$1
268   shift
269
270   case "$PACKAGE_TYPE" in
271       python)
272           # All Arvados Python2 packages depend on Python 2.7.
273           # Make sure we build with that for consistency.
274           set -- "$@" --python-bin python2.7 \
275               --python-easyinstall "$EASY_INSTALL2" \
276               --python-package-name-prefix "$PYTHON2_PKG_PREFIX" \
277               --depends "$PYTHON2_PACKAGE"
278           ;;
279       python3)
280           # fpm does not actually support a python3 package type.  Instead
281           # we recognize it as a convenience shortcut to add several
282           # necessary arguments to fpm's command line later, after we're
283           # done handling positional arguments.
284           PACKAGE_TYPE=python
285           set -- "$@" --python-bin python3 \
286               --python-easyinstall "$EASY_INSTALL3" \
287               --python-package-name-prefix "$PYTHON3_PKG_PREFIX" \
288               --depends "$PYTHON3_PACKAGE"
289           ;;
290   esac
291
292   declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "-s" "$PACKAGE_TYPE" "-t" "$FORMAT")
293   if [ python = "$PACKAGE_TYPE" ]; then
294     COMMAND_ARR+=(--exclude=\*/{dist,site}-packages/tests/\*)
295   fi
296
297   if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then
298     COMMAND_ARR+=('-n' "$PACKAGE_NAME")
299   fi
300
301   if [[ "$VENDOR" != "" ]]; then
302     COMMAND_ARR+=('--vendor' "$VENDOR")
303   fi
304
305   if [[ "$VERSION" != "" ]]; then
306     COMMAND_ARR+=('-v' "$VERSION")
307   fi
308
309   # Append remaining function arguments directly to fpm's command line.
310   for i; do
311     COMMAND_ARR+=("$i")
312   done
313
314   COMMAND_ARR+=("$PACKAGE")
315
316   if [[ "$DEBUG" != 0 ]]; then
317     echo
318     echo "${COMMAND_ARR[@]}"
319     echo
320   fi
321
322   FPM_RESULTS=$("${COMMAND_ARR[@]}")
323   FPM_EXIT_CODE=$?
324
325   fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
326 }
327
328 # verify build results
329 fpm_verify () {
330   FPM_EXIT_CODE=$1
331   shift
332   FPM_RESULTS=$@
333
334   FPM_PACKAGE_NAME=''
335   if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\.-]*\.)(deb|rpm) ]]; then
336     FPM_PACKAGE_NAME=${BASH_REMATCH[1]}${BASH_REMATCH[2]}
337   fi
338
339   if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
340     EXITCODE=1
341     echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
342     echo
343     echo $FPM_RESULTS
344     echo
345   elif [[ "$FPM_RESULTS" =~ "File already exists" ]]; then
346     echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
347   elif [[ 0 -ne "$FPM_EXIT_CODE" ]]; then
348     echo "Error building package for $1:\n $FPM_RESULTS"
349   fi
350 }
351
352 if [[ -f /etc/profile.d/rvm.sh ]]; then
353   source /etc/profile.d/rvm.sh
354 fi
355
356 # Make all files world-readable -- jenkins runs with umask 027, and has checked
357 # out our git tree here
358 chmod o+r "$WORKSPACE" -R
359
360 # More cleanup - make sure all executables that we'll package are 755
361 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
362
363 # Now fix our umask to something better suited to building and publishing
364 # gems and packages
365 umask 0022
366
367 if [[ "$DEBUG" != 0 ]]; then
368   echo "umask is" `umask`
369 fi
370
371 if [[ ! -d "$WORKSPACE/packages/$TARGET" ]]; then
372   mkdir -p $WORKSPACE/packages/$TARGET
373 fi
374
375 # Perl packages
376 if [[ "$DEBUG" != 0 ]]; then
377   echo -e "\nPerl packages\n"
378 fi
379
380 if [[ "$DEBUG" != 0 ]]; then
381   PERL_OUT=/dev/stdout
382 else
383   PERL_OUT=/dev/null
384 fi
385
386 cd "$WORKSPACE/sdk/perl"
387
388 if [[ -e Makefile ]]; then
389   make realclean >"$PERL_OUT"
390 fi
391 find -maxdepth 1 \( -name 'MANIFEST*' -or -name "libarvados-perl*.$FORMAT" \) \
392     -delete
393 rm -rf install
394
395 perl Makefile.PL INSTALL_BASE=install >"$PERL_OUT" && \
396     make install INSTALLDIRS=perl >"$PERL_OUT" && \
397     fpm_build install/lib/=/usr/share libarvados-perl \
398     "Curoverse, Inc." dir "$(version_from_git)" install/man/=/usr/share/man && \
399     mv libarvados-perl*.$FORMAT "$WORKSPACE/packages/$TARGET/"
400
401 # Ruby gems
402 if [[ "$DEBUG" != 0 ]]; then
403   echo
404   echo "Ruby gems"
405   echo
406 fi
407
408 if type rvm-exec >/dev/null 2>&1; then
409   FPM_GEM_PREFIX=$(rvm-exec system gem environment gemdir)
410 else
411   FPM_GEM_PREFIX=$(gem environment gemdir)
412 fi
413
414 cd "$WORKSPACE/sdk/ruby"
415 handle_ruby_gem arvados
416
417 cd "$WORKSPACE/sdk/cli"
418 handle_ruby_gem arvados-cli
419
420 # Python packages
421 if [[ "$DEBUG" != 0 ]]; then
422   echo
423   echo "Python packages"
424   echo
425 fi
426
427 cd "$WORKSPACE/sdk/pam"
428 handle_python_package
429
430 cd "$WORKSPACE/sdk/python"
431 handle_python_package
432
433 cd "$WORKSPACE/services/fuse"
434 handle_python_package
435
436 cd "$WORKSPACE/services/nodemanager"
437 handle_python_package
438
439 # Arvados-src
440 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
441 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
442   mkdir "$WORKSPACE/src-build-dir"
443   cd "$WORKSPACE"
444   if [[ "$DEBUG" != 0 ]]; then
445     git clone https://github.com/curoverse/arvados.git src-build-dir
446   else
447     git clone -q https://github.com/curoverse/arvados.git src-build-dir
448   fi
449 fi
450
451 # Get the commit hash we're building against, from the working directory
452 cd "$WORKSPACE"
453 MASTER_COMMIT_HASH=$(format_last_commit_here "%H")
454
455 # Make sure we check out that commit in the clean $WORKSPACE/src-build-dir directory
456 cd "$WORKSPACE/src-build-dir"
457 # just in case, check out master
458 if [[ "$DEBUG" != 0 ]]; then
459   git checkout master
460   git pull
461   # go into detached-head state
462   git checkout "$MASTER_COMMIT_HASH"
463 else
464   git checkout -q master
465   git pull -q
466   # go into detached-head state
467   git checkout -q "$MASTER_COMMIT_HASH"
468 fi
469 echo "$MASTER_COMMIT_HASH" >git-commit.version
470
471 # Build arvados src deb package
472 cd "$WORKSPACE"
473 PKG_VERSION=$(version_from_git)
474 cd $WORKSPACE/packages/$TARGET
475 fpm_build $WORKSPACE/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"
476
477 # clean up, check out master and step away from detached-head state
478 cd "$WORKSPACE/src-build-dir"
479 if [[ "$DEBUG" != 0 ]]; then
480   git checkout master
481 else
482   git checkout -q master
483 fi
484
485 # Keep
486 export GOPATH=$(mktemp -d)
487 mkdir -p "$GOPATH/src/git.curoverse.com"
488 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
489
490 # keepstore
491 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepstore"
492 PKG_VERSION=$(version_from_git)
493 go get "git.curoverse.com/arvados.git/services/keepstore"
494 cd $WORKSPACE/packages/$TARGET
495 fpm_build $GOPATH/bin/keepstore=/usr/bin/keepstore keepstore 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=Keepstore is the Keep storage daemon, accessible to clients on the LAN"
496
497 # Get GO SDK version
498 cd "$GOPATH/src/git.curoverse.com/arvados.git/sdk/go"
499 GO_SDK_VERSION=$(version_from_git)
500 GO_SDK_TIMESTAMP=$(timestamp_from_git)
501
502 # keepproxy
503 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepproxy"
504 KEEPPROXY_VERSION=$(version_from_git)
505 KEEPPROXY_TIMESTAMP=$(timestamp_from_git)
506
507 if [[ "$GO_SDK_TIMESTAMP" -gt "$KEEPPROXY_TIMESTAMP" ]]; then
508   PKG_VERSION=$GO_SDK_VERSION
509 else
510   PKG_VERSION=$KEEPPROXY_VERSION
511 fi
512
513 go get "git.curoverse.com/arvados.git/services/keepproxy"
514 cd $WORKSPACE/packages/$TARGET
515 fpm_build $GOPATH/bin/keepproxy=/usr/bin/keepproxy keepproxy 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=Keepproxy makes a Keep cluster accessible to clients that are not on the LAN"
516
517 # datamanager
518 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/datamanager"
519 DATAMANAGER_VERSION=$(version_from_git)
520 DATAMANAGER_TIMESTAMP=$(timestamp_from_git)
521
522 if [[ "$GO_SDK_TIMESTAMP" -gt "$DATAMANAGER_TIMESTAMP" ]]; then
523   PKG_VERSION=$GO_SDK_VERSION
524 else
525   PKG_VERSION=$DATAMANAGER_VERSION
526 fi
527
528 go get "git.curoverse.com/arvados.git/services/datamanager"
529 cd $WORKSPACE/packages/$TARGET
530 fpm_build $GOPATH/bin/datamanager=/usr/bin/arvados-data-manager arvados-data-manager 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=Datamanager ensures block replication levels, reports on disk usage and determines which blocks should be deleted when space is needed."
531
532 # arv-git-httpd
533 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/arv-git-httpd"
534 ARVGITHTTPD_VERSION=$(version_from_git)
535 ARVGITHTTPD_TIMESTAMP=$(timestamp_from_git)
536
537 if [[ "$GO_SDK_TIMESTAMP" -gt "$ARVGITHTTPD_TIMESTAMP" ]]; then
538   PKG_VERSION=$GO_SDK_VERSION
539 else
540   PKG_VERSION=$ARVGITHTTPD_VERSION
541 fi
542
543 go get "git.curoverse.com/arvados.git/services/arv-git-httpd"
544 cd $WORKSPACE/packages/$TARGET
545 fpm_build $GOPATH/bin/arv-git-httpd=/usr/bin/arvados-git-httpd arvados-git-httpd 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=Provides authenticated http access to Arvados-hosted git repositories."
546
547 # crunchstat
548 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/crunchstat"
549 PKG_VERSION=$(version_from_git)
550 go get "git.curoverse.com/arvados.git/services/crunchstat"
551 cd $WORKSPACE/packages/$TARGET
552 fpm_build $GOPATH/bin/crunchstat=/usr/bin/crunchstat crunchstat 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=Crunchstat gathers cpu/memory/network statistics of running Crunch jobs"
553
554 # The Python SDK
555 # Please resist the temptation to add --no-python-fix-name to the fpm call here
556 # (which would remove the python- prefix from the package name), because this
557 # package is a dependency of arvados-fuse, and fpm can not omit the python-
558 # prefix from only one of the dependencies of a package...  Maybe I could
559 # whip up a patch and send it upstream, but that will be for another day. Ward,
560 # 2014-05-15
561 cd $WORKSPACE/packages/$TARGET
562 rm -rf "$WORKSPACE/sdk/python/build"
563 fpm_build $WORKSPACE/sdk/python "${PYTHON2_PKG_PREFIX}-arvados-python-client" 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/python/arvados_python_client.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Arvados Python SDK" --deb-recommends=git
564
565 # The PAM module
566 if [[ $TARGET =~ debian|ubuntu ]]; then
567     cd $WORKSPACE/packages/$TARGET
568     rm -rf "$WORKSPACE/sdk/pam/build"
569     fpm_build $WORKSPACE/sdk/pam libpam-arvados 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/sdk/pam/arvados_pam.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=PAM module for authenticating shell logins using Arvados API tokens" --depends libpam-python
570 fi
571
572 # The FUSE driver
573 # Please see comment about --no-python-fix-name above; we stay consistent and do
574 # not omit the python- prefix first.
575 cd $WORKSPACE/packages/$TARGET
576 rm -rf "$WORKSPACE/services/fuse/build"
577 fpm_build $WORKSPACE/services/fuse "${PYTHON2_PKG_PREFIX}-arvados-fuse" 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/fuse/arvados_fuse.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Keep FUSE driver"
578
579 # The node manager
580 cd $WORKSPACE/packages/$TARGET
581 rm -rf "$WORKSPACE/services/nodemanager/build"
582 fpm_build $WORKSPACE/services/nodemanager arvados-node-manager 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/nodemanager/arvados_node_manager.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Arvados node manager"
583
584 # The Docker image cleaner
585 cd $WORKSPACE/packages/$TARGET
586 rm -rf "$WORKSPACE/services/dockercleaner/build"
587 fpm_build $WORKSPACE/services/dockercleaner arvados-docker-cleaner 'Curoverse, Inc.' 'python3' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/services/dockercleaner/arvados_docker_cleaner.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Arvados Docker image cleaner"
588
589 # A few dependencies
590 for deppkg in "${PYTHON_BACKPORTS[@]}"; do
591     outname=$(echo "$deppkg" | sed -e 's/^python-//' -e 's/[<=>].*//' -e 's/_/-/g' -e "s/^/${PYTHON2_PKG_PREFIX}-/")
592     fpm_build "$deppkg" "$outname"
593 done
594
595 # Python 3 dependencies
596 for deppkg in "${PYTHON3_BACKPORTS[@]}"; do
597     outname=$(echo "$deppkg" | sed -e 's/^python-//' -e 's/[<=>].*//' -e 's/_/-/g' -e "s/^/${PYTHON3_PKG_PREFIX}-/")
598     # The empty string is the vendor argument: these aren't Curoverse software.
599     fpm_build "$deppkg" "$outname" "" python3
600 done
601
602 # Build the API server package
603
604 cd "$WORKSPACE/services/api"
605
606 API_VERSION=$(version_from_git)
607 PACKAGE_NAME=arvados-api-server
608
609 if [[ ! -d "$WORKSPACE/services/api/tmp" ]]; then
610   mkdir $WORKSPACE/services/api/tmp
611 fi
612
613 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
614
615 if [[ "$DEBUG" != 0 ]]; then
616   echo $BUNDLE_OUTPUT
617 fi
618
619 /usr/bin/git rev-parse HEAD > git-commit.version
620
621 cd $WORKSPACE/packages/$TARGET
622
623 # Annoyingly, we require a database.yml file for rake assets:precompile to work. So for now,
624 # we do that in the upgrade script.
625 # TODO: add bogus database.yml file so we can precompile the assets and put them in the
626 # package. Then remove that database.yml file again. It has to be a valid file though.
627 #RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
628
629 # This is the complete package with vendor/bundle included.
630 # It's big, so we do not build it by default.
631 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
632   declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados API server - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}-with-bundle" "-v" "$API_VERSION" "-x" "var/www/arvados-api/current/tmp" "-x" "var/www/arvados-api/current/log" "-x" "var/www/arvados-api/current/vendor/cache/*" "-x" "var/www/arvados-api/current/coverage" "-x" "var/www/arvados-api/current/Capfile*" "-x" "var/www/arvados-api/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/postinst.sh" "$WORKSPACE/services/api/=/var/www/arvados-api/current" "$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/arvados-api-server-upgrade.sh=/usr/local/bin/arvados-api-server-upgrade.sh")
633
634   if [[ "$DEBUG" != 0 ]]; then
635     echo
636     echo "${COMMAND_ARR[@]}"
637     echo
638   fi
639
640   FPM_RESULTS=$("${COMMAND_ARR[@]}")
641   FPM_EXIT_CODE=$?
642   fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
643 fi
644
645 # Build the 'bare' package without vendor/bundle.
646 declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados API server - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}" "-v" "$API_VERSION" "-x" "var/www/arvados-api/current/tmp" "-x" "var/www/arvados-api/current/log" "-x" "var/www/arvados-api/current/vendor/bundle" "-x" "var/www/arvados-api/current/vendor/cache/*" "-x" "var/www/arvados-api/current/coverage" "-x" "var/www/arvados-api/current/Capfile*" "-x" "var/www/arvados-api/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/postinst.sh" "$WORKSPACE/services/api/=/var/www/arvados-api/current" "$RUN_BUILD_PACKAGES_PATH/arvados-api-server-extras/arvados-api-server-upgrade.sh=/usr/local/bin/arvados-api-server-upgrade.sh")
647
648 if [[ "$DEBUG" != 0 ]]; then
649   echo
650   echo "${COMMAND_ARR[@]}"
651   echo
652 fi
653
654 FPM_RESULTS=$("${COMMAND_ARR[@]}")
655 FPM_EXIT_CODE=$?
656 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
657
658 # API server package build done
659
660 # Build the workbench server package
661
662 cd "$WORKSPACE/apps/workbench"
663
664 WORKBENCH_VERSION=$(version_from_git)
665 PACKAGE_NAME=arvados-workbench
666
667 if [[ ! -d "$WORKSPACE/apps/workbench/tmp" ]]; then
668   mkdir $WORKSPACE/apps/workbench/tmp
669 fi
670
671 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
672
673 if [[ "$DEBUG" != 0 ]]; then
674   echo $BUNDLE_OUTPUT
675 fi
676
677 /usr/bin/git rev-parse HEAD > git-commit.version
678
679 # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
680 # and we want that in the package, so it's easier to not exclude the tmp directory
681 # from the package - empty it instead.
682 rm -rf $WORKSPACE/apps/workbench/tmp/*
683
684 # Set up application.yml and production.rb so that asset precompilation works
685 \cp config/application.yml.example config/application.yml -f
686 \cp config/environments/production.rb.example config/environments/production.rb -f
687 sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
688
689 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
690
691 if [[ "$?" != "0" ]]; then
692   echo "ERROR: Asset precompilation failed"
693   EXITCODE=1
694 fi
695
696 cd $WORKSPACE/packages/$TARGET
697
698 # This is the complete package with vendor/bundle included.
699 # It's big, so we do not build it by default.
700 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
701
702   declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados Workbench - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}-with-bundle" "-v" "$WORKBENCH_VERSION" "-x" "var/www/arvados-workbench/current/log" "-x" "var/www/arvados-workbench/current/vendor/cache/*" "-x" "var/www/arvados-workbench/current/coverage" "-x" "var/www/arvados-workbench/current/Capfile*" "-x" "var/www/arvados-workbench/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/postinst.sh" "$WORKSPACE/apps/workbench/=/var/www/arvados-workbench/current" "$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/arvados-workbench-upgrade.sh=/usr/local/bin/arvados-workbench-upgrade.sh")
703
704   if [[ "$DEBUG" != 0 ]]; then
705     echo
706     echo "${COMMAND_ARR[@]}"
707     echo
708   fi
709
710   FPM_RESULTS=$("${COMMAND_ARR[@]}")
711   FPM_EXIT_CODE=$?
712   fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
713 fi
714
715 # Build the 'bare' package without vendor/bundle.
716
717 declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "--vendor='Curoverse, Inc.'" "--url='https://arvados.org'" "--description='Arvados Workbench - Arvados is a free and open source platform for big data science.'" "--license='GNU Affero General Public License, version 3.0'" "-s" "dir" "-t" "$FORMAT" "-n" "${PACKAGE_NAME}" "-v" "$WORKBENCH_VERSION" "-x" "var/www/arvados-workbench/current/log" "-x" "var/www/arvados-workbench/current/vendor/bundle" "-x" "var/www/arvados-workbench/current/vendor/cache/*" "-x" "var/www/arvados-workbench/current/coverage" "-x" "var/www/arvados-workbench/current/Capfile*" "-x" "var/www/arvados-workbench/current/config/deploy*" "--after-install=$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/postinst.sh" "$WORKSPACE/apps/workbench/=/var/www/arvados-workbench/current" "$RUN_BUILD_PACKAGES_PATH/arvados-workbench-extras/arvados-workbench-upgrade.sh=/usr/local/bin/arvados-workbench-upgrade.sh")
718
719 if [[ "$DEBUG" != 0 ]]; then
720   echo
721   echo "${COMMAND_ARR[@]}"
722   echo
723 fi
724
725 FPM_RESULTS=$("${COMMAND_ARR[@]}")
726 FPM_EXIT_CODE=$?
727 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
728
729 # Workbench package build done
730 # clean up temporary GOPATH
731 rm -rf "$GOPATH"
732
733 exit $EXITCODE