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