Store the full git hash of the checkout in the arvados-src package, in a file called...
[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 git log --format=format:%H -n1 . > git-commit.version
395
396 # Build arvados src deb package
397 cd "$WORKSPACE"
398 PKG_VERSION=$(version_from_git)
399 cd $WORKSPACE/debs
400 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"
401
402 # clean up, check out master and step away from detached-head state
403 cd "$WORKSPACE/src-build-dir"
404 if [[ "$DEBUG" != 0 ]]; then
405   git checkout master
406 else
407   git checkout -q master
408 fi
409
410 # Keep
411 export GOPATH=$(mktemp -d)
412 mkdir -p "$GOPATH/src/git.curoverse.com"
413 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
414
415 # keepstore
416 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepstore"
417 PKG_VERSION=$(version_from_git)
418 go get "git.curoverse.com/arvados.git/services/keepstore"
419 cd $WORKSPACE/debs
420 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"
421
422 # Get GO SDK version
423 cd "$GOPATH/src/git.curoverse.com/arvados.git/sdk/go"
424 GO_SDK_VERSION=$(version_from_git)
425 GO_SDK_TIMESTAMP=$(timestamp_from_git)
426
427 # keepproxy
428 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepproxy"
429 KEEPPROXY_VERSION=$(version_from_git)
430 KEEPPROXY_TIMESTAMP=$(timestamp_from_git)
431
432 if [[ "$GO_SDK_TIMESTAMP" -gt "$KEEPPROXY_TIMESTAMP" ]]; then
433   PKG_VERSION=$GO_SDK_VERSION
434 else
435   PKG_VERSION=$KEEPPROXY_VERSION
436 fi
437
438 go get "git.curoverse.com/arvados.git/services/keepproxy"
439 cd $WORKSPACE/debs
440 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"
441
442 # datamanager
443 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/datamanager"
444 DATAMANAGER_VERSION=$(version_from_git)
445 DATAMANAGER_TIMESTAMP=$(timestamp_from_git)
446
447 if [[ "$GO_SDK_TIMESTAMP" -gt "$DATAMANAGER_TIMESTAMP" ]]; then
448   PKG_VERSION=$GO_SDK_VERSION
449 else
450   PKG_VERSION=$DATAMANAGER_VERSION
451 fi
452
453 go get "git.curoverse.com/arvados.git/services/datamanager"
454 cd $WORKSPACE/debs
455 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."
456
457 # arv-git-httpd
458 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/arv-git-httpd"
459 ARVGITHTTPD_VERSION=$(version_from_git)
460 ARVGITHTTPD_TIMESTAMP=$(timestamp_from_git)
461
462 if [[ "$GO_SDK_TIMESTAMP" -gt "$ARVGITHTTPD_TIMESTAMP" ]]; then
463   PKG_VERSION=$GO_SDK_VERSION
464 else
465   PKG_VERSION=$ARVGITHTTPD_VERSION
466 fi
467
468 go get "git.curoverse.com/arvados.git/services/arv-git-httpd"
469 cd $WORKSPACE/debs
470 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."
471
472 # crunchstat
473 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/crunchstat"
474 PKG_VERSION=$(version_from_git)
475 go get "git.curoverse.com/arvados.git/services/crunchstat"
476 cd $WORKSPACE/debs
477 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"
478
479 # The Python SDK
480 # Please resist the temptation to add --no-python-fix-name to the fpm call here
481 # (which would remove the python- prefix from the package name), because this
482 # package is a dependency of arvados-fuse, and fpm can not omit the python-
483 # prefix from only one of the dependencies of a package...  Maybe I could
484 # whip up a patch and send it upstream, but that will be for another day. Ward,
485 # 2014-05-15
486 cd $WORKSPACE/debs
487 # Python version numbering is obscure. Strip dashes and replace them with dots
488 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
489 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"
490
491 # The FUSE driver
492 # Please see comment about --no-python-fix-name above; we stay consistent and do
493 # not omit the python- prefix first.
494 cd $WORKSPACE/debs
495 # Python version numbering is obscure. Strip dashes and replace them with dots
496 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
497 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"
498
499 # The node manager
500 cd $WORKSPACE/debs
501 # Python version numbering is obscure. Strip dashes and replace them with dots
502 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
503 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"
504
505 # The Docker image cleaner
506 cd $WORKSPACE/debs
507 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"
508
509 # A few dependencies
510 for deppkg in python-gflags pyvcf google-api-python-client oauth2client \
511       pyasn1 pyasn1-modules rsa uritemplate httplib2 ws4py virtualenv \
512       pykka apache-libcloud requests six pyexecjs jsonschema ciso8601 \
513       pycrypto backports.ssl_match_hostname; do
514     build_and_scp_deb "$deppkg"
515 done
516
517 # Python 3 dependencies
518 for deppkg in docker-py six requests; do
519     # The empty string is the vendor argument: these aren't Curoverse software.
520     build_and_scp_deb "$deppkg" "python3-$deppkg" "" python3
521 done
522
523 # Build the API server package
524
525 cd "$WORKSPACE/services/api"
526
527 API_VERSION=$(version_from_git)
528 PACKAGE_NAME=arvados-api-server
529
530 if [[ ! -d "$WORKSPACE/services/api/tmp" ]]; then
531   mkdir $WORKSPACE/services/api/tmp
532 fi
533
534 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
535
536 if [[ "$DEBUG" != 0 ]]; then
537   echo $BUNDLE_OUTPUT
538 fi
539
540 /usr/bin/git rev-parse HEAD > git-commit.version
541
542 cd $WORKSPACE/debs
543
544 # Annoyingly, we require a database.yml file for rake assets:precompile to work. So for now,
545 # we do that in the upgrade script.
546 # TODO: add bogus database.yml file so we can precompile the assets and put them in the
547 # package. Then remove that database.yml file again. It has to be a valid file though.
548 #RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
549
550 # This is the complete package with vendor/bundle included.
551 # It's big, so we do not build it by default.
552 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
553   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")
554
555   if [[ "$DEBUG" != 0 ]]; then
556     echo
557     echo "${COMMAND_ARR[@]}"
558     echo
559   fi
560
561   FPM_RESULTS=$("${COMMAND_ARR[@]}")
562   FPM_EXIT_CODE=$?
563   verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
564 fi
565
566 # Build the 'bare' package without vendor/bundle.
567 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")
568
569 if [[ "$DEBUG" != 0 ]]; then
570   echo
571   echo "${COMMAND_ARR[@]}"
572   echo
573 fi
574
575 FPM_RESULTS=$("${COMMAND_ARR[@]}")
576 FPM_EXIT_CODE=$?
577 verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
578
579 # API server package build done
580
581 # Build the workbench server package
582
583 cd "$WORKSPACE/apps/workbench"
584
585 WORKBENCH_VERSION=$(version_from_git)
586 PACKAGE_NAME=arvados-workbench
587
588 if [[ ! -d "$WORKSPACE/apps/workbench/tmp" ]]; then
589   mkdir $WORKSPACE/apps/workbench/tmp
590 fi
591
592 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
593
594 if [[ "$DEBUG" != 0 ]]; then
595   echo $BUNDLE_OUTPUT
596 fi
597
598 /usr/bin/git rev-parse HEAD > git-commit.version
599
600 # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
601 # and we want that in the package, so it's easier to not exclude the tmp directory
602 # from the package - empty it instead.
603 rm -rf $WORKSPACE/apps/workbench/tmp/*
604
605 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
606
607 cd $WORKSPACE/debs
608
609 # This is the complete package with vendor/bundle included.
610 # It's big, so we do not build it by default.
611 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
612
613   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")
614
615   if [[ "$DEBUG" != 0 ]]; then
616     echo
617     echo "${COMMAND_ARR[@]}"
618     echo
619   fi
620
621   FPM_RESULTS=$("${COMMAND_ARR[@]}")
622   FPM_EXIT_CODE=$?
623   verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
624 fi
625
626 # Build the 'bare' package without vendor/bundle.
627
628 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")
629
630 if [[ "$DEBUG" != 0 ]]; then
631   echo
632   echo "${COMMAND_ARR[@]}"
633   echo
634 fi
635
636 FPM_RESULTS=$("${COMMAND_ARR[@]}")
637 FPM_EXIT_CODE=$?
638 verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
639
640 # Workbench package build done
641
642 # Finally, publish the packages, if necessary
643 if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
644   ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
645 else
646   if [[ "$UPLOAD" != 0 ]]; then
647     echo "No new packages generated. No freight run necessary."
648   fi
649 fi
650
651 # clean up temporary GOPATH
652 rm -rf "$GOPATH"
653
654 exit $EXITCODE