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