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