1ceecee278412a9adce691f7142a75771a9ea2d6
[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"
428
429 cd sdk/python
430 handle_python_package
431
432 cd ../../services/fuse
433 handle_python_package
434
435 cd ../../services/nodemanager
436 handle_python_package
437
438 # Arvados-src
439 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
440 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
441   mkdir "$WORKSPACE/src-build-dir"
442   cd "$WORKSPACE"
443   if [[ "$DEBUG" != 0 ]]; then
444     git clone https://github.com/curoverse/arvados.git src-build-dir
445   else
446     git clone -q https://github.com/curoverse/arvados.git src-build-dir
447   fi
448 fi
449
450 cd "$WORKSPACE/src-build-dir"
451 # just in case, check out master
452 if [[ "$DEBUG" != 0 ]]; then
453   git checkout master
454   git pull
455   # go into detached-head state
456   MASTER_COMMIT_HASH=$(format_last_commit_here "%H")
457   git checkout "$MASTER_COMMIT_HASH"
458 else
459   git checkout -q master
460   git pull -q
461   # go into detached-head state
462   MASTER_COMMIT_HASH=$(format_last_commit_here "%H")
463   git checkout -q "$MASTER_COMMIT_HASH"
464 fi
465 echo "$MASTER_COMMIT_HASH" >git-commit.version
466
467 # Build arvados src deb package
468 cd "$WORKSPACE"
469 PKG_VERSION=$(version_from_git)
470 cd $WORKSPACE/packages/$TARGET
471 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"
472
473 # clean up, check out master and step away from detached-head state
474 cd "$WORKSPACE/src-build-dir"
475 if [[ "$DEBUG" != 0 ]]; then
476   git checkout master
477 else
478   git checkout -q master
479 fi
480
481 # Keep
482 export GOPATH=$(mktemp -d)
483 mkdir -p "$GOPATH/src/git.curoverse.com"
484 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
485
486 # keepstore
487 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepstore"
488 PKG_VERSION=$(version_from_git)
489 go get "git.curoverse.com/arvados.git/services/keepstore"
490 cd $WORKSPACE/packages/$TARGET
491 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"
492
493 # Get GO SDK version
494 cd "$GOPATH/src/git.curoverse.com/arvados.git/sdk/go"
495 GO_SDK_VERSION=$(version_from_git)
496 GO_SDK_TIMESTAMP=$(timestamp_from_git)
497
498 # keepproxy
499 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepproxy"
500 KEEPPROXY_VERSION=$(version_from_git)
501 KEEPPROXY_TIMESTAMP=$(timestamp_from_git)
502
503 if [[ "$GO_SDK_TIMESTAMP" -gt "$KEEPPROXY_TIMESTAMP" ]]; then
504   PKG_VERSION=$GO_SDK_VERSION
505 else
506   PKG_VERSION=$KEEPPROXY_VERSION
507 fi
508
509 go get "git.curoverse.com/arvados.git/services/keepproxy"
510 cd $WORKSPACE/packages/$TARGET
511 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"
512
513 # datamanager
514 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/datamanager"
515 DATAMANAGER_VERSION=$(version_from_git)
516 DATAMANAGER_TIMESTAMP=$(timestamp_from_git)
517
518 if [[ "$GO_SDK_TIMESTAMP" -gt "$DATAMANAGER_TIMESTAMP" ]]; then
519   PKG_VERSION=$GO_SDK_VERSION
520 else
521   PKG_VERSION=$DATAMANAGER_VERSION
522 fi
523
524 go get "git.curoverse.com/arvados.git/services/datamanager"
525 cd $WORKSPACE/packages/$TARGET
526 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."
527
528 # arv-git-httpd
529 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/arv-git-httpd"
530 ARVGITHTTPD_VERSION=$(version_from_git)
531 ARVGITHTTPD_TIMESTAMP=$(timestamp_from_git)
532
533 if [[ "$GO_SDK_TIMESTAMP" -gt "$ARVGITHTTPD_TIMESTAMP" ]]; then
534   PKG_VERSION=$GO_SDK_VERSION
535 else
536   PKG_VERSION=$ARVGITHTTPD_VERSION
537 fi
538
539 go get "git.curoverse.com/arvados.git/services/arv-git-httpd"
540 cd $WORKSPACE/packages/$TARGET
541 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."
542
543 # crunchstat
544 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/crunchstat"
545 PKG_VERSION=$(version_from_git)
546 go get "git.curoverse.com/arvados.git/services/crunchstat"
547 cd $WORKSPACE/packages/$TARGET
548 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"
549
550 # The Python SDK
551 # Please resist the temptation to add --no-python-fix-name to the fpm call here
552 # (which would remove the python- prefix from the package name), because this
553 # package is a dependency of arvados-fuse, and fpm can not omit the python-
554 # prefix from only one of the dependencies of a package...  Maybe I could
555 # whip up a patch and send it upstream, but that will be for another day. Ward,
556 # 2014-05-15
557 cd $WORKSPACE/packages/$TARGET
558 rm -rf "$WORKSPACE/sdk/python/build"
559 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
560
561 # The FUSE driver
562 # Please see comment about --no-python-fix-name above; we stay consistent and do
563 # not omit the python- prefix first.
564 cd $WORKSPACE/packages/$TARGET
565 rm -rf "$WORKSPACE/services/fuse/build"
566 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"
567
568 # The node manager
569 cd $WORKSPACE/packages/$TARGET
570 rm -rf "$WORKSPACE/services/nodemanager/build"
571 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"
572
573 # The Docker image cleaner
574 cd $WORKSPACE/packages/$TARGET
575 rm -rf "$WORKSPACE/services/dockercleaner/build"
576 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"
577
578 # A few dependencies
579 for deppkg in "${PYTHON_BACKPORTS[@]}"; do
580     outname=$(echo "$deppkg" | sed -e 's/^python-//' -e 's/[<=>].*//' -e 's/_/-/g' -e "s/^/${PYTHON2_PKG_PREFIX}-/")
581     fpm_build "$deppkg" "$outname"
582 done
583
584 # Python 3 dependencies
585 for deppkg in "${PYTHON3_BACKPORTS[@]}"; do
586     outname=$(echo "$deppkg" | sed -e 's/^python-//' -e 's/[<=>].*//' -e 's/_/-/g' -e "s/^/${PYTHON3_PKG_PREFIX}-/")
587     # The empty string is the vendor argument: these aren't Curoverse software.
588     fpm_build "$deppkg" "$outname" "" python3
589 done
590
591 # libpam-arvados
592 cd $WORKSPACE/sdk/pam
593 PKG_VERSION=$(version_from_git)
594 cd $WORKSPACE/packages/$TARGET
595
596 if [[ "$FORMAT" == "deb" ]]; then
597   fpm_build $WORKSPACE/sdk/pam/debian/shellinabox=/etc/pam.d/shellinabox libpam-arvados 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=Apache License, Version 2.0" "--description=PAM module for Arvados" "--config-files=/etc/default" "-d libpam-python" $WORKSPACE/sdk/pam/arvados_pam.py=/usr/bin/arvados_pam.py $WORKSPACE/sdk/pam/debian/arvados_pam=/etc/default/arvados_pam
598 #else
599   # FIXME enable and test once we have the centos pam.d file
600   #fpm_build $WORKSPACE/sdk/pam/centos/shellinabox=/etc/pam.d/shellinabox libpam-arvados 'Curoverse, Inc.' 'dir' "$PKG_VERSION" "--url=https://arvados.org" "--license=Apache License, Version 2.0" "--description=PAM module for Arvados" "--config-files=/etc/default" "-d libpam-python" $WORKSPACE/sdk/pam/arvados_pam.py=/usr/bin/arvados_pam.py $WORKSPACE/sdk/pam/centos/arvados_pam=/etc/default/arvados_pam
601 fi
602
603 # Build the API server package
604
605 cd "$WORKSPACE/services/api"
606
607 API_VERSION=$(version_from_git)
608 PACKAGE_NAME=arvados-api-server
609
610 if [[ ! -d "$WORKSPACE/services/api/tmp" ]]; then
611   mkdir $WORKSPACE/services/api/tmp
612 fi
613
614 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
615
616 if [[ "$DEBUG" != 0 ]]; then
617   echo $BUNDLE_OUTPUT
618 fi
619
620 /usr/bin/git rev-parse HEAD > git-commit.version
621
622 cd $WORKSPACE/packages/$TARGET
623
624 # Annoyingly, we require a database.yml file for rake assets:precompile to work. So for now,
625 # we do that in the upgrade script.
626 # TODO: add bogus database.yml file so we can precompile the assets and put them in the
627 # package. Then remove that database.yml file again. It has to be a valid file though.
628 #RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
629
630 # This is the complete package with vendor/bundle included.
631 # It's big, so we do not build it by default.
632 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
633   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")
634
635   if [[ "$DEBUG" != 0 ]]; then
636     echo
637     echo "${COMMAND_ARR[@]}"
638     echo
639   fi
640
641   FPM_RESULTS=$("${COMMAND_ARR[@]}")
642   FPM_EXIT_CODE=$?
643   fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
644 fi
645
646 # Build the 'bare' package without vendor/bundle.
647 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")
648
649 if [[ "$DEBUG" != 0 ]]; then
650   echo
651   echo "${COMMAND_ARR[@]}"
652   echo
653 fi
654
655 FPM_RESULTS=$("${COMMAND_ARR[@]}")
656 FPM_EXIT_CODE=$?
657 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
658
659 # API server package build done
660
661 # Build the workbench server package
662
663 cd "$WORKSPACE/apps/workbench"
664
665 WORKBENCH_VERSION=$(version_from_git)
666 PACKAGE_NAME=arvados-workbench
667
668 if [[ ! -d "$WORKSPACE/apps/workbench/tmp" ]]; then
669   mkdir $WORKSPACE/apps/workbench/tmp
670 fi
671
672 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
673
674 if [[ "$DEBUG" != 0 ]]; then
675   echo $BUNDLE_OUTPUT
676 fi
677
678 /usr/bin/git rev-parse HEAD > git-commit.version
679
680 # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
681 # and we want that in the package, so it's easier to not exclude the tmp directory
682 # from the package - empty it instead.
683 rm -rf $WORKSPACE/apps/workbench/tmp/*
684
685 # Set up application.yml and production.rb so that asset precompilation works
686 \cp config/application.yml.example config/application.yml -f
687 \cp config/environments/production.rb.example config/environments/production.rb -f
688 sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
689
690 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
691
692 if [[ "$?" != "0" ]]; then
693   echo "ERROR: Asset precompilation failed"
694   EXITCODE=1
695 fi
696
697 cd $WORKSPACE/packages/$TARGET
698
699 # This is the complete package with vendor/bundle included.
700 # It's big, so we do not build it by default.
701 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
702
703   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")
704
705   if [[ "$DEBUG" != 0 ]]; then
706     echo
707     echo "${COMMAND_ARR[@]}"
708     echo
709   fi
710
711   FPM_RESULTS=$("${COMMAND_ARR[@]}")
712   FPM_EXIT_CODE=$?
713   fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
714 fi
715
716 # Build the 'bare' package without vendor/bundle.
717
718 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")
719
720 if [[ "$DEBUG" != 0 ]]; then
721   echo
722   echo "${COMMAND_ARR[@]}"
723   echo
724 fi
725
726 FPM_RESULTS=$("${COMMAND_ARR[@]}")
727 FPM_EXIT_CODE=$?
728 fpm_verify $FPM_EXIT_CODE $FPM_RESULTS
729
730 # Workbench package build done
731 # clean up temporary GOPATH
732 rm -rf "$GOPATH"
733
734 exit $EXITCODE