Do not build and upload gems that already exist on rubygems.
[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
320 ARVADOS_GEM_EPOCH=`git log -n1 --first-parent --format=%ct`
321 ARVADOS_GEM_DATE=`date --utc --date="@${ARVADOS_GEM_EPOCH}" +%Y%m%d%H%M%S`
322 ARVADOS_GEM_VERSION="0.1.${ARVADOS_GEM_DATE}"
323
324 # see if this gem needs building/uploading
325 gem search arvados -r -a |grep -q $ARVADOS_GEM_VERSION
326
327 if [[ "$?" != "0" ]]; then
328   # clean up old packages
329   find -maxdepth 1 \( -name 'arvados-*.gem' -or -name 'rubygem-arvados_*.deb' -or -name 'rubygem-arvados_*.rpm' \) \
330       -delete
331
332   if [[ "$DEBUG" != 0 ]]; then
333     gem build arvados.gemspec
334   else
335     # -q appears to be broken in gem version 2.2.2
336     gem build arvados.gemspec -q >/dev/null 2>&1
337   fi
338   
339   if [[ "$UPLOAD" != 0 ]]; then
340     # publish new gem
341     gem push arvados-*gem
342   fi
343   
344   build_and_scp_deb arvados-*.gem "" "Curoverse, Inc." gem "" \
345       --prefix "$FPM_GEM_PREFIX"
346 fi
347   
348 # Build arvados-cli GEM
349 cd "$WORKSPACE"
350 cd sdk/cli
351
352 ARVADOS_CLI_GEM_EPOCH=`git log -n1 --first-parent --format=%ct`
353 ARVADOS_CLI_GEM_DATE=`date --utc --date="@${ARVADOS_CLI_GEM_EPOCH}" +%Y%m%d%H%M%S`
354 ARVADOS_CLI_GEM_VERSION="0.1.${ARVADOS_CLI_GEM_DATE}"
355
356 # see if this gem needs building/uploading
357 gem search arvados-cli -r -a |grep -q $ARVADOS_GEM_VERSION
358
359 if [[ "$?" != "0" ]]; then
360   # clean up old gems
361   rm -f arvados-cli*gem
362   
363   if [[ "$DEBUG" != 0 ]]; then
364     gem build arvados-cli.gemspec
365   else
366     # -q appears to be broken in gem version 2.2.2
367     gem build arvados-cli.gemspec -q >/dev/null
368   fi
369   
370   if [[ "$UPLOAD" != 0 ]]; then
371     # publish new gem
372     gem push arvados-cli*gem
373   fi
374 fi
375
376 # Python packages
377 if [[ "$DEBUG" != 0 ]]; then
378   echo
379   echo "Python packages"
380   echo
381 fi
382
383 cd "$WORKSPACE"
384
385 cd sdk/python
386 handle_python_package
387
388 cd ../../services/fuse
389 handle_python_package
390
391 cd ../../services/nodemanager
392 handle_python_package
393
394 if [[ ! -d "$WORKSPACE/debs" ]]; then
395   mkdir -p $WORKSPACE/debs
396 fi
397
398 # Arvados-src
399 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
400 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
401   mkdir "$WORKSPACE/src-build-dir"
402   cd "$WORKSPACE"
403   if [[ "$DEBUG" != 0 ]]; then
404     git clone https://github.com/curoverse/arvados.git src-build-dir
405   else
406     git clone -q https://github.com/curoverse/arvados.git src-build-dir
407   fi
408 fi
409
410 cd "$WORKSPACE/src-build-dir"
411 # just in case, check out master
412 if [[ "$DEBUG" != 0 ]]; then
413   git checkout master
414   git pull
415   # go into detached-head state
416   git checkout `git log --format=format:%h -n1 .`
417 else
418   git checkout -q master
419   git pull -q
420   # go into detached-head state
421   git checkout -q `git log --format=format:%h -n1 .`
422 fi
423
424 git log --format=format:%H -n1 . > git-commit.version
425
426 # Build arvados src deb package
427 cd "$WORKSPACE"
428 PKG_VERSION=$(version_from_git)
429 cd $WORKSPACE/debs
430 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"
431
432 # clean up, check out master and step away from detached-head state
433 cd "$WORKSPACE/src-build-dir"
434 if [[ "$DEBUG" != 0 ]]; then
435   git checkout master
436 else
437   git checkout -q master
438 fi
439
440 # Keep
441 export GOPATH=$(mktemp -d)
442 mkdir -p "$GOPATH/src/git.curoverse.com"
443 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
444
445 # keepstore
446 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepstore"
447 PKG_VERSION=$(version_from_git)
448 go get "git.curoverse.com/arvados.git/services/keepstore"
449 cd $WORKSPACE/debs
450 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"
451
452 # Get GO SDK version
453 cd "$GOPATH/src/git.curoverse.com/arvados.git/sdk/go"
454 GO_SDK_VERSION=$(version_from_git)
455 GO_SDK_TIMESTAMP=$(timestamp_from_git)
456
457 # keepproxy
458 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepproxy"
459 KEEPPROXY_VERSION=$(version_from_git)
460 KEEPPROXY_TIMESTAMP=$(timestamp_from_git)
461
462 if [[ "$GO_SDK_TIMESTAMP" -gt "$KEEPPROXY_TIMESTAMP" ]]; then
463   PKG_VERSION=$GO_SDK_VERSION
464 else
465   PKG_VERSION=$KEEPPROXY_VERSION
466 fi
467
468 go get "git.curoverse.com/arvados.git/services/keepproxy"
469 cd $WORKSPACE/debs
470 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"
471
472 # datamanager
473 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/datamanager"
474 DATAMANAGER_VERSION=$(version_from_git)
475 DATAMANAGER_TIMESTAMP=$(timestamp_from_git)
476
477 if [[ "$GO_SDK_TIMESTAMP" -gt "$DATAMANAGER_TIMESTAMP" ]]; then
478   PKG_VERSION=$GO_SDK_VERSION
479 else
480   PKG_VERSION=$DATAMANAGER_VERSION
481 fi
482
483 go get "git.curoverse.com/arvados.git/services/datamanager"
484 cd $WORKSPACE/debs
485 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."
486
487 # arv-git-httpd
488 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/arv-git-httpd"
489 ARVGITHTTPD_VERSION=$(version_from_git)
490 ARVGITHTTPD_TIMESTAMP=$(timestamp_from_git)
491
492 if [[ "$GO_SDK_TIMESTAMP" -gt "$ARVGITHTTPD_TIMESTAMP" ]]; then
493   PKG_VERSION=$GO_SDK_VERSION
494 else
495   PKG_VERSION=$ARVGITHTTPD_VERSION
496 fi
497
498 go get "git.curoverse.com/arvados.git/services/arv-git-httpd"
499 cd $WORKSPACE/debs
500 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."
501
502 # crunchstat
503 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/crunchstat"
504 PKG_VERSION=$(version_from_git)
505 go get "git.curoverse.com/arvados.git/services/crunchstat"
506 cd $WORKSPACE/debs
507 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"
508
509 # The Python SDK
510 # Please resist the temptation to add --no-python-fix-name to the fpm call here
511 # (which would remove the python- prefix from the package name), because this
512 # package is a dependency of arvados-fuse, and fpm can not omit the python-
513 # prefix from only one of the dependencies of a package...  Maybe I could
514 # whip up a patch and send it upstream, but that will be for another day. Ward,
515 # 2014-05-15
516 cd $WORKSPACE/debs
517 # Python version numbering is obscure. Strip dashes and replace them with dots
518 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
519 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"
520
521 # The FUSE driver
522 # Please see comment about --no-python-fix-name above; we stay consistent and do
523 # not omit the python- prefix first.
524 cd $WORKSPACE/debs
525 # Python version numbering is obscure. Strip dashes and replace them with dots
526 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
527 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"
528
529 # The node manager
530 cd $WORKSPACE/debs
531 # Python version numbering is obscure. Strip dashes and replace them with dots
532 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
533 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"
534
535 # The Docker image cleaner
536 cd $WORKSPACE/debs
537 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"
538
539 # A few dependencies
540 for deppkg in python-gflags pyvcf google-api-python-client oauth2client \
541       pyasn1 pyasn1-modules rsa uritemplate httplib2 ws4py virtualenv \
542       pykka apache-libcloud requests six pyexecjs jsonschema ciso8601 \
543       pycrypto backports.ssl_match_hostname; do
544     build_and_scp_deb "$deppkg"
545 done
546
547 # Python 3 dependencies
548 for deppkg in docker-py six requests; do
549     # The empty string is the vendor argument: these aren't Curoverse software.
550     build_and_scp_deb "$deppkg" "python3-$deppkg" "" python3
551 done
552
553 # Build the API server package
554
555 cd "$WORKSPACE/services/api"
556
557 API_VERSION=$(version_from_git)
558 PACKAGE_NAME=arvados-api-server
559
560 if [[ ! -d "$WORKSPACE/services/api/tmp" ]]; then
561   mkdir $WORKSPACE/services/api/tmp
562 fi
563
564 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
565
566 if [[ "$DEBUG" != 0 ]]; then
567   echo $BUNDLE_OUTPUT
568 fi
569
570 /usr/bin/git rev-parse HEAD > git-commit.version
571
572 cd $WORKSPACE/debs
573
574 # Annoyingly, we require a database.yml file for rake assets:precompile to work. So for now,
575 # we do that in the upgrade script.
576 # TODO: add bogus database.yml file so we can precompile the assets and put them in the
577 # package. Then remove that database.yml file again. It has to be a valid file though.
578 #RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
579
580 # This is the complete package with vendor/bundle included.
581 # It's big, so we do not build it by default.
582 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
583   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")
584
585   if [[ "$DEBUG" != 0 ]]; then
586     echo
587     echo "${COMMAND_ARR[@]}"
588     echo
589   fi
590
591   FPM_RESULTS=$("${COMMAND_ARR[@]}")
592   FPM_EXIT_CODE=$?
593   verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
594 fi
595
596 # Build the 'bare' package without vendor/bundle.
597 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")
598
599 if [[ "$DEBUG" != 0 ]]; then
600   echo
601   echo "${COMMAND_ARR[@]}"
602   echo
603 fi
604
605 FPM_RESULTS=$("${COMMAND_ARR[@]}")
606 FPM_EXIT_CODE=$?
607 verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
608
609 # API server package build done
610
611 # Build the workbench server package
612
613 cd "$WORKSPACE/apps/workbench"
614
615 WORKBENCH_VERSION=$(version_from_git)
616 PACKAGE_NAME=arvados-workbench
617
618 if [[ ! -d "$WORKSPACE/apps/workbench/tmp" ]]; then
619   mkdir $WORKSPACE/apps/workbench/tmp
620 fi
621
622 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
623
624 if [[ "$DEBUG" != 0 ]]; then
625   echo $BUNDLE_OUTPUT
626 fi
627
628 /usr/bin/git rev-parse HEAD > git-commit.version
629
630 # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
631 # and we want that in the package, so it's easier to not exclude the tmp directory
632 # from the package - empty it instead.
633 rm -rf $WORKSPACE/apps/workbench/tmp/*
634
635 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
636
637 cd $WORKSPACE/debs
638
639 # This is the complete package with vendor/bundle included.
640 # It's big, so we do not build it by default.
641 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
642
643   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")
644
645   if [[ "$DEBUG" != 0 ]]; then
646     echo
647     echo "${COMMAND_ARR[@]}"
648     echo
649   fi
650
651   FPM_RESULTS=$("${COMMAND_ARR[@]}")
652   FPM_EXIT_CODE=$?
653   verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
654 fi
655
656 # Build the 'bare' package without vendor/bundle.
657
658 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")
659
660 if [[ "$DEBUG" != 0 ]]; then
661   echo
662   echo "${COMMAND_ARR[@]}"
663   echo
664 fi
665
666 FPM_RESULTS=$("${COMMAND_ARR[@]}")
667 FPM_EXIT_CODE=$?
668 verify_and_scp_deb $FPM_EXIT_CODE $FPM_RESULTS
669
670 # Workbench package build done
671
672 # Finally, publish the packages, if necessary
673 if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
674   if [[ "$FORMAT" == 'deb' ]]; then
675     ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
676   else
677     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/"
678   fi
679 else
680   if [[ "$UPLOAD" != 0 ]]; then
681     echo "No new packages generated. No freight run necessary."
682   fi
683 fi
684
685 # clean up temporary GOPATH
686 rm -rf "$GOPATH"
687
688 exit $EXITCODE