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