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