Add very rudimentary support for pushing the rpm packages into a yum
[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 package for $1:\n $FPM_RESULTS"
244       else
245         if [[ "$UPLOAD" != 0 ]]; then
246           if [[ "$FORMAT" == 'deb' ]]; then
247             scp -P2222 $FPM_PACKAGE_NAME $APTUSER@$APTSERVER:tmp/
248           else
249             scp -P2222 $FPM_PACKAGE_NAME $APTUSER@$APTSERVER:rpm/
250           fi
251           CALL_FREIGHT=1
252         fi
253       fi
254     else
255       echo "Package $FPM_PACKAGE_NAME exists, not rebuilding"
256     fi
257   fi
258 }
259
260 if [[ -f /etc/profile.d/rvm.sh ]]; then
261   source /etc/profile.d/rvm.sh
262 fi
263
264 # Make all files world-readable -- jenkins runs with umask 027, and has checked
265 # out our git tree here
266 chmod o+r "$WORKSPACE" -R
267
268 # More cleanup - make sure all executables that we'll package are 755
269 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
270
271 # Now fix our umask to something better suited to building and publishing
272 # gems and packages
273 umask 0022
274
275 if [[ "$DEBUG" != 0 ]]; then
276   echo "umask is" `umask`
277 fi
278
279 # Perl packages
280 if [[ "$DEBUG" != 0 ]]; then
281   echo -e "\nPerl packages\n"
282 fi
283
284 if [[ "$DEBUG" != 0 ]]; then
285   PERL_OUT=/dev/stdout
286 else
287   PERL_OUT=/dev/null
288 fi
289
290 cd "$WORKSPACE/sdk/perl"
291
292 if [[ -e Makefile ]]; then
293   make realclean >"$PERL_OUT"
294 fi
295 find -maxdepth 1 \( -name 'MANIFEST*' -or -name 'libarvados-perl_*.deb' \) \
296     -delete
297 rm -rf install
298
299 perl Makefile.PL >"$PERL_OUT" && \
300     make install PREFIX=install INSTALLDIRS=perl >"$PERL_OUT" && \
301     build_and_scp_deb install/=/usr libarvados-perl "Curoverse, Inc." dir \
302       "$(version_from_git)"
303
304 # Ruby gems
305 if [[ "$DEBUG" != 0 ]]; then
306   echo
307   echo "Ruby gems"
308   echo
309 fi
310
311 if type rvm-exec >/dev/null 2>&1; then
312   FPM_GEM_PREFIX=$(rvm-exec system gem environment gemdir)
313 else
314   FPM_GEM_PREFIX=$(gem environment gemdir)
315 fi
316
317 cd "$WORKSPACE"
318 cd sdk/ruby
319 # clean up old packages
320 find -maxdepth 1 \( -name 'arvados-*.gem' -or -name 'rubygem-arvados_*.deb' \) \
321     -delete
322
323 if [[ "$DEBUG" != 0 ]]; then
324   gem build arvados.gemspec
325 else
326   # -q appears to be broken in gem version 2.2.2
327   gem build arvados.gemspec -q >/dev/null 2>&1
328 fi
329
330 if [[ "$UPLOAD" != 0 ]]; then
331   # publish new gem
332   gem push arvados-*gem
333 fi
334
335 build_and_scp_deb arvados-*.gem "" "Curoverse, Inc." gem "" \
336     --prefix "$FPM_GEM_PREFIX"
337
338 # Build arvados-cli GEM
339 cd "$WORKSPACE"
340 cd sdk/cli
341 # clean up old gems
342 rm -f arvados-cli*gem
343
344 if [[ "$DEBUG" != 0 ]]; then
345   gem build arvados-cli.gemspec
346 else
347   # -q appears to be broken in gem version 2.2.2
348   gem build arvados-cli.gemspec -q >/dev/null
349 fi
350
351 if [[ "$UPLOAD" != 0 ]]; then
352   # publish new gem
353   gem push arvados-cli*gem
354 fi
355
356 # Python packages
357 if [[ "$DEBUG" != 0 ]]; then
358   echo
359   echo "Python packages"
360   echo
361 fi
362
363 cd "$WORKSPACE"
364
365 cd sdk/python
366 handle_python_package
367
368 cd ../../services/fuse
369 handle_python_package
370
371 cd ../../services/nodemanager
372 handle_python_package
373
374 if [[ ! -d "$WORKSPACE/debs" ]]; then
375   mkdir -p $WORKSPACE/debs
376 fi
377
378 # Arvados-src
379 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
380 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
381   mkdir "$WORKSPACE/src-build-dir"
382   cd "$WORKSPACE"
383   if [[ "$DEBUG" != 0 ]]; then
384     git clone https://github.com/curoverse/arvados.git src-build-dir
385   else
386     git clone -q https://github.com/curoverse/arvados.git src-build-dir
387   fi
388 fi
389
390 cd "$WORKSPACE/src-build-dir"
391 # just in case, check out master
392 if [[ "$DEBUG" != 0 ]]; then
393   git checkout master
394   git pull
395   # go into detached-head state
396   git checkout `git log --format=format:%h -n1 .`
397 else
398   git checkout -q master
399   git pull -q
400   # go into detached-head state
401   git checkout -q `git log --format=format:%h -n1 .`
402 fi
403
404 git log --format=format:%H -n1 . > git-commit.version
405
406 # Build arvados src deb package
407 cd "$WORKSPACE"
408 PKG_VERSION=$(version_from_git)
409 cd $WORKSPACE/debs
410 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"
411
412 # clean up, check out master and step away from detached-head state
413 cd "$WORKSPACE/src-build-dir"
414 if [[ "$DEBUG" != 0 ]]; then
415   git checkout master
416 else
417   git checkout -q master
418 fi
419
420 # Keep
421 export GOPATH=$(mktemp -d)
422 mkdir -p "$GOPATH/src/git.curoverse.com"
423 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
424
425 # keepstore
426 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepstore"
427 PKG_VERSION=$(version_from_git)
428 go get "git.curoverse.com/arvados.git/services/keepstore"
429 cd $WORKSPACE/debs
430 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"
431
432 # Get GO SDK version
433 cd "$GOPATH/src/git.curoverse.com/arvados.git/sdk/go"
434 GO_SDK_VERSION=$(version_from_git)
435 GO_SDK_TIMESTAMP=$(timestamp_from_git)
436
437 # keepproxy
438 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepproxy"
439 KEEPPROXY_VERSION=$(version_from_git)
440 KEEPPROXY_TIMESTAMP=$(timestamp_from_git)
441
442 if [[ "$GO_SDK_TIMESTAMP" -gt "$KEEPPROXY_TIMESTAMP" ]]; then
443   PKG_VERSION=$GO_SDK_VERSION
444 else
445   PKG_VERSION=$KEEPPROXY_VERSION
446 fi
447
448 go get "git.curoverse.com/arvados.git/services/keepproxy"
449 cd $WORKSPACE/debs
450 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"
451
452 # datamanager
453 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/datamanager"
454 DATAMANAGER_VERSION=$(version_from_git)
455 DATAMANAGER_TIMESTAMP=$(timestamp_from_git)
456
457 if [[ "$GO_SDK_TIMESTAMP" -gt "$DATAMANAGER_TIMESTAMP" ]]; then
458   PKG_VERSION=$GO_SDK_VERSION
459 else
460   PKG_VERSION=$DATAMANAGER_VERSION
461 fi
462
463 go get "git.curoverse.com/arvados.git/services/datamanager"
464 cd $WORKSPACE/debs
465 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."
466
467 # arv-git-httpd
468 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/arv-git-httpd"
469 ARVGITHTTPD_VERSION=$(version_from_git)
470 ARVGITHTTPD_TIMESTAMP=$(timestamp_from_git)
471
472 if [[ "$GO_SDK_TIMESTAMP" -gt "$ARVGITHTTPD_TIMESTAMP" ]]; then
473   PKG_VERSION=$GO_SDK_VERSION
474 else
475   PKG_VERSION=$ARVGITHTTPD_VERSION
476 fi
477
478 go get "git.curoverse.com/arvados.git/services/arv-git-httpd"
479 cd $WORKSPACE/debs
480 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."
481
482 # crunchstat
483 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/crunchstat"
484 PKG_VERSION=$(version_from_git)
485 go get "git.curoverse.com/arvados.git/services/crunchstat"
486 cd $WORKSPACE/debs
487 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"
488
489 # The Python SDK
490 # Please resist the temptation to add --no-python-fix-name to the fpm call here
491 # (which would remove the python- prefix from the package name), because this
492 # package is a dependency of arvados-fuse, and fpm can not omit the python-
493 # prefix from only one of the dependencies of a package...  Maybe I could
494 # whip up a patch and send it upstream, but that will be for another day. Ward,
495 # 2014-05-15
496 cd $WORKSPACE/debs
497 # Python version numbering is obscure. Strip dashes and replace them with dots
498 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
499 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"
500
501 # The FUSE driver
502 # Please see comment about --no-python-fix-name above; we stay consistent and do
503 # not omit the python- prefix first.
504 cd $WORKSPACE/debs
505 # Python version numbering is obscure. Strip dashes and replace them with dots
506 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
507 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"
508
509 # The node manager
510 cd $WORKSPACE/debs
511 # Python version numbering is obscure. Strip dashes and replace them with dots
512 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
513 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"
514
515 # The Docker image cleaner
516 cd $WORKSPACE/debs
517 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"
518
519 # A few dependencies
520 for deppkg in python-gflags pyvcf google-api-python-client oauth2client \
521       pyasn1 pyasn1-modules rsa uritemplate httplib2 ws4py virtualenv \
522       pykka apache-libcloud requests six pyexecjs jsonschema ciso8601 \
523       pycrypto backports.ssl_match_hostname; do
524     build_and_scp_deb "$deppkg"
525 done
526
527 # Python 3 dependencies
528 for deppkg in docker-py six requests; do
529     # The empty string is the vendor argument: these aren't Curoverse software.
530     build_and_scp_deb "$deppkg" "python3-$deppkg" "" python3
531 done
532
533 # Build the API server package
534
535 cd "$WORKSPACE/services/api"
536
537 API_VERSION=$(version_from_git)
538 PACKAGE_NAME=arvados-api-server
539
540 if [[ ! -d "$WORKSPACE/services/api/tmp" ]]; then
541   mkdir $WORKSPACE/services/api/tmp
542 fi
543
544 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
545
546 if [[ "$DEBUG" != 0 ]]; then
547   echo $BUNDLE_OUTPUT
548 fi
549
550 /usr/bin/git rev-parse HEAD > git-commit.version
551
552 cd $WORKSPACE/debs
553
554 # Annoyingly, we require a database.yml file for rake assets:precompile to work. So for now,
555 # we do that in the upgrade script.
556 # TODO: add bogus database.yml file so we can precompile the assets and put them in the
557 # package. Then remove that database.yml file again. It has to be a valid file though.
558 #RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
559
560 # This is the complete package with vendor/bundle included.
561 # It's big, so we do not build it by default.
562 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
563   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")
564
565   if [[ "$DEBUG" != 0 ]]; then
566     echo
567     echo "${COMMAND_ARR[@]}"
568     echo
569   fi
570
571   FPM_RESULTS=$("${COMMAND_ARR[@]}")
572   FPM_EXIT_CODE=$?
573   verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
574 fi
575
576 # Build the 'bare' package without vendor/bundle.
577 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")
578
579 if [[ "$DEBUG" != 0 ]]; then
580   echo
581   echo "${COMMAND_ARR[@]}"
582   echo
583 fi
584
585 FPM_RESULTS=$("${COMMAND_ARR[@]}")
586 FPM_EXIT_CODE=$?
587 verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
588
589 # API server package build done
590
591 # Build the workbench server package
592
593 cd "$WORKSPACE/apps/workbench"
594
595 WORKBENCH_VERSION=$(version_from_git)
596 PACKAGE_NAME=arvados-workbench
597
598 if [[ ! -d "$WORKSPACE/apps/workbench/tmp" ]]; then
599   mkdir $WORKSPACE/apps/workbench/tmp
600 fi
601
602 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
603
604 if [[ "$DEBUG" != 0 ]]; then
605   echo $BUNDLE_OUTPUT
606 fi
607
608 /usr/bin/git rev-parse HEAD > git-commit.version
609
610 # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
611 # and we want that in the package, so it's easier to not exclude the tmp directory
612 # from the package - empty it instead.
613 rm -rf $WORKSPACE/apps/workbench/tmp/*
614
615 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
616
617 cd $WORKSPACE/debs
618
619 # This is the complete package with vendor/bundle included.
620 # It's big, so we do not build it by default.
621 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
622
623   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")
624
625   if [[ "$DEBUG" != 0 ]]; then
626     echo
627     echo "${COMMAND_ARR[@]}"
628     echo
629   fi
630
631   FPM_RESULTS=$("${COMMAND_ARR[@]}")
632   FPM_EXIT_CODE=$?
633   verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
634 fi
635
636 # Build the 'bare' package without vendor/bundle.
637
638 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")
639
640 if [[ "$DEBUG" != 0 ]]; then
641   echo
642   echo "${COMMAND_ARR[@]}"
643   echo
644 fi
645
646 FPM_RESULTS=$("${COMMAND_ARR[@]}")
647 FPM_EXIT_CODE=$?
648 verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
649
650 # Workbench package build done
651
652 # Finally, publish the packages, if necessary
653 if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
654   if [[ "$FORMAT" == 'deb' ]]; then
655     ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
656   else
657     ssh -p2222 $APTUSER@$APTSERVER -t "cd rpm && ls -laF *rpm && mv *rpm /var/www/rpm.arvados.org/CentOS/6/os/x86_64/ && createrepo /var/www/rpm.arvados.org/CentOS/6/os/x86_64/"
658   fi
659 else
660   if [[ "$UPLOAD" != 0 ]]; then
661     echo "No new packages generated. No freight run necessary."
662   fi
663 fi
664
665 # clean up temporary GOPATH
666 rm -rf "$GOPATH"
667
668 exit $EXITCODE