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