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