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