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