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