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