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