6388: Backport pycurl package everywhere.
[arvados.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 # Perl packages
323 if [[ "$DEBUG" != 0 ]]; then
324   echo -e "\nPerl packages\n"
325 fi
326
327 if [[ "$DEBUG" != 0 ]]; then
328   PERL_OUT=/dev/stdout
329 else
330   PERL_OUT=/dev/null
331 fi
332
333 cd "$WORKSPACE/sdk/perl"
334
335 if [[ -e Makefile ]]; then
336   make realclean >"$PERL_OUT"
337 fi
338 find -maxdepth 1 \( -name 'MANIFEST*' -or -name 'libarvados-perl_*.deb' \) \
339     -delete
340 rm -rf install
341
342 perl Makefile.PL >"$PERL_OUT" && \
343     make install PREFIX=install INSTALLDIRS=perl >"$PERL_OUT" && \
344     fpm_build_and_scp install/=/usr libarvados-perl "Curoverse, Inc." dir \
345       "$(version_from_git)"
346
347 # Ruby gems
348 if [[ "$DEBUG" != 0 ]]; then
349   echo
350   echo "Ruby gems"
351   echo
352 fi
353
354 if type rvm-exec >/dev/null 2>&1; then
355   FPM_GEM_PREFIX=$(rvm-exec system gem environment gemdir)
356 else
357   FPM_GEM_PREFIX=$(gem environment gemdir)
358 fi
359
360 cd "$WORKSPACE"
361 cd sdk/ruby
362
363 ARVADOS_GEM_EPOCH=`git log -n1 --first-parent --format=%ct`
364 ARVADOS_GEM_DATE=`date --utc --date="@${ARVADOS_GEM_EPOCH}" +%Y%m%d%H%M%S`
365 ARVADOS_GEM_VERSION="0.1.${ARVADOS_GEM_DATE}"
366
367 # see if this gem needs building/uploading
368 gem search arvados -r -a |grep -q $ARVADOS_GEM_VERSION
369
370 if [[ "$?" != "0" ]]; then
371   # clean up old packages
372   find -maxdepth 1 \( -name 'arvados-*.gem' -or -name 'rubygem-arvados_*.deb' -or -name 'rubygem-arvados_*.rpm' \) \
373       -delete
374
375   if [[ "$DEBUG" != 0 ]]; then
376     gem build arvados.gemspec
377   else
378     # -q appears to be broken in gem version 2.2.2
379     gem build arvados.gemspec -q >/dev/null 2>&1
380   fi
381
382   if [[ "$UPLOAD" != 0 ]]; then
383     # publish new gem
384     gem push arvados-*gem
385   fi
386
387   fpm_build_and_scp arvados-*.gem "" "Curoverse, Inc." gem "" \
388       --prefix "$FPM_GEM_PREFIX"
389 fi
390
391 # Build arvados-cli GEM
392 cd "$WORKSPACE"
393 cd sdk/cli
394
395 ARVADOS_CLI_GEM_EPOCH=`git log -n1 --first-parent --format=%ct`
396 ARVADOS_CLI_GEM_DATE=`date --utc --date="@${ARVADOS_CLI_GEM_EPOCH}" +%Y%m%d%H%M%S`
397 ARVADOS_CLI_GEM_VERSION="0.1.${ARVADOS_CLI_GEM_DATE}"
398
399 # see if this gem needs building/uploading
400 gem search arvados-cli -r -a |grep -q $ARVADOS_GEM_VERSION
401
402 if [[ "$?" != "0" ]]; then
403   # clean up old gems
404   rm -f arvados-cli*gem
405
406   if [[ "$DEBUG" != 0 ]]; then
407     gem build arvados-cli.gemspec
408   else
409     # -q appears to be broken in gem version 2.2.2
410     gem build arvados-cli.gemspec -q >/dev/null
411   fi
412
413   if [[ "$UPLOAD" != 0 ]]; then
414     # publish new gem
415     gem push arvados-cli*gem
416   fi
417 fi
418
419 # Python packages
420 if [[ "$DEBUG" != 0 ]]; then
421   echo
422   echo "Python packages"
423   echo
424 fi
425
426 cd "$WORKSPACE"
427
428 cd sdk/python
429 handle_python_package
430
431 cd ../../services/fuse
432 handle_python_package
433
434 cd ../../services/nodemanager
435 handle_python_package
436
437 if [[ ! -d "$WORKSPACE/debs" ]]; then
438   mkdir -p $WORKSPACE/debs
439 fi
440
441 # Arvados-src
442 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
443 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
444   mkdir "$WORKSPACE/src-build-dir"
445   cd "$WORKSPACE"
446   if [[ "$DEBUG" != 0 ]]; then
447     git clone https://github.com/curoverse/arvados.git src-build-dir
448   else
449     git clone -q https://github.com/curoverse/arvados.git src-build-dir
450   fi
451 fi
452
453 cd "$WORKSPACE/src-build-dir"
454 # just in case, check out master
455 if [[ "$DEBUG" != 0 ]]; then
456   git checkout master
457   git pull
458   # go into detached-head state
459   git checkout `git log --format=format:%h -n1 .`
460 else
461   git checkout -q master
462   git pull -q
463   # go into detached-head state
464   git checkout -q `git log --format=format:%h -n1 .`
465 fi
466
467 git log --format=format:%H -n1 . > git-commit.version
468
469 # Build arvados src deb package
470 cd "$WORKSPACE"
471 PKG_VERSION=$(version_from_git)
472 cd $WORKSPACE/debs
473 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"
474
475 # clean up, check out master and step away from detached-head state
476 cd "$WORKSPACE/src-build-dir"
477 if [[ "$DEBUG" != 0 ]]; then
478   git checkout master
479 else
480   git checkout -q master
481 fi
482
483 # Keep
484 export GOPATH=$(mktemp -d)
485 mkdir -p "$GOPATH/src/git.curoverse.com"
486 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
487
488 # keepstore
489 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepstore"
490 PKG_VERSION=$(version_from_git)
491 go get "git.curoverse.com/arvados.git/services/keepstore"
492 cd $WORKSPACE/debs
493 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"
494
495 # Get GO SDK version
496 cd "$GOPATH/src/git.curoverse.com/arvados.git/sdk/go"
497 GO_SDK_VERSION=$(version_from_git)
498 GO_SDK_TIMESTAMP=$(timestamp_from_git)
499
500 # keepproxy
501 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepproxy"
502 KEEPPROXY_VERSION=$(version_from_git)
503 KEEPPROXY_TIMESTAMP=$(timestamp_from_git)
504
505 if [[ "$GO_SDK_TIMESTAMP" -gt "$KEEPPROXY_TIMESTAMP" ]]; then
506   PKG_VERSION=$GO_SDK_VERSION
507 else
508   PKG_VERSION=$KEEPPROXY_VERSION
509 fi
510
511 go get "git.curoverse.com/arvados.git/services/keepproxy"
512 cd $WORKSPACE/debs
513 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"
514
515 # datamanager
516 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/datamanager"
517 DATAMANAGER_VERSION=$(version_from_git)
518 DATAMANAGER_TIMESTAMP=$(timestamp_from_git)
519
520 if [[ "$GO_SDK_TIMESTAMP" -gt "$DATAMANAGER_TIMESTAMP" ]]; then
521   PKG_VERSION=$GO_SDK_VERSION
522 else
523   PKG_VERSION=$DATAMANAGER_VERSION
524 fi
525
526 go get "git.curoverse.com/arvados.git/services/datamanager"
527 cd $WORKSPACE/debs
528 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."
529
530 # arv-git-httpd
531 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/arv-git-httpd"
532 ARVGITHTTPD_VERSION=$(version_from_git)
533 ARVGITHTTPD_TIMESTAMP=$(timestamp_from_git)
534
535 if [[ "$GO_SDK_TIMESTAMP" -gt "$ARVGITHTTPD_TIMESTAMP" ]]; then
536   PKG_VERSION=$GO_SDK_VERSION
537 else
538   PKG_VERSION=$ARVGITHTTPD_VERSION
539 fi
540
541 go get "git.curoverse.com/arvados.git/services/arv-git-httpd"
542 cd $WORKSPACE/debs
543 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."
544
545 # crunchstat
546 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/crunchstat"
547 PKG_VERSION=$(version_from_git)
548 go get "git.curoverse.com/arvados.git/services/crunchstat"
549 cd $WORKSPACE/debs
550 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"
551
552 # The Python SDK
553 # Please resist the temptation to add --no-python-fix-name to the fpm call here
554 # (which would remove the python- prefix from the package name), because this
555 # package is a dependency of arvados-fuse, and fpm can not omit the python-
556 # prefix from only one of the dependencies of a package...  Maybe I could
557 # whip up a patch and send it upstream, but that will be for another day. Ward,
558 # 2014-05-15
559 cd $WORKSPACE/debs
560 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
561
562 # The FUSE driver
563 # Please see comment about --no-python-fix-name above; we stay consistent and do
564 # not omit the python- prefix first.
565 cd $WORKSPACE/debs
566 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
567
568 # The node manager
569 cd $WORKSPACE/debs
570 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
571
572 # The Docker image cleaner
573 cd $WORKSPACE/debs
574 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"
575
576 # A few dependencies
577 for deppkg in "${PYTHON_BACKPORTS[@]}"; do
578     fpm_build_and_scp "$deppkg"
579 done
580
581 # Python 3 dependencies
582 for deppkg in "${PYTHON3_BACKPORTS[@]}"; do
583     # The empty string is the vendor argument: these aren't Curoverse software.
584     fpm_build_and_scp "$deppkg" "python3-$deppkg" "" python3
585 done
586
587 # Build the API server package
588
589 cd "$WORKSPACE/services/api"
590
591 API_VERSION=$(version_from_git)
592 PACKAGE_NAME=arvados-api-server
593
594 if [[ ! -d "$WORKSPACE/services/api/tmp" ]]; then
595   mkdir $WORKSPACE/services/api/tmp
596 fi
597
598 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
599
600 if [[ "$DEBUG" != 0 ]]; then
601   echo $BUNDLE_OUTPUT
602 fi
603
604 /usr/bin/git rev-parse HEAD > git-commit.version
605
606 cd $WORKSPACE/debs
607
608 # Annoyingly, we require a database.yml file for rake assets:precompile to work. So for now,
609 # we do that in the upgrade script.
610 # TODO: add bogus database.yml file so we can precompile the assets and put them in the
611 # package. Then remove that database.yml file again. It has to be a valid file though.
612 #RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
613
614 # This is the complete package with vendor/bundle included.
615 # It's big, so we do not build it by default.
616 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
617   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")
618
619   if [[ "$DEBUG" != 0 ]]; then
620     echo
621     echo "${COMMAND_ARR[@]}"
622     echo
623   fi
624
625   FPM_RESULTS=$("${COMMAND_ARR[@]}")
626   FPM_EXIT_CODE=$?
627   fpm_verify_and_scp $FPM_EXIT_CODE $FPM_RESULTS
628 fi
629
630 # Build the 'bare' package without vendor/bundle.
631 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")
632
633 if [[ "$DEBUG" != 0 ]]; then
634   echo
635   echo "${COMMAND_ARR[@]}"
636   echo
637 fi
638
639 FPM_RESULTS=$("${COMMAND_ARR[@]}")
640 FPM_EXIT_CODE=$?
641 fpm_verify_and_scp $FPM_EXIT_CODE $FPM_RESULTS
642
643 # API server package build done
644
645 # Build the workbench server package
646
647 cd "$WORKSPACE/apps/workbench"
648
649 WORKBENCH_VERSION=$(version_from_git)
650 PACKAGE_NAME=arvados-workbench
651
652 if [[ ! -d "$WORKSPACE/apps/workbench/tmp" ]]; then
653   mkdir $WORKSPACE/apps/workbench/tmp
654 fi
655
656 BUNDLE_OUTPUT=`bundle install --path vendor/bundle`
657
658 if [[ "$DEBUG" != 0 ]]; then
659   echo $BUNDLE_OUTPUT
660 fi
661
662 /usr/bin/git rev-parse HEAD > git-commit.version
663
664 # clear the tmp directory; the asset generation step will recreate tmp/cache/assets,
665 # and we want that in the package, so it's easier to not exclude the tmp directory
666 # from the package - empty it instead.
667 rm -rf $WORKSPACE/apps/workbench/tmp/*
668
669 # Set up application.yml so that asset precompilation works
670 \cp config/application.yml.example config/application.yml -f
671 sed -i 's/secret_token: ~/secret_token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/' config/application.yml
672
673 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile >/dev/null
674
675 if [[ "$?" != "0" ]]; then
676   echo "ERROR: Asset precompilation failed"
677   EXITCODE=1
678 fi
679
680 cd $WORKSPACE/debs
681
682 # This is the complete package with vendor/bundle included.
683 # It's big, so we do not build it by default.
684 if [[ "$BUILD_BUNDLE_PACKAGES" != 0 ]]; then
685
686   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")
687
688   if [[ "$DEBUG" != 0 ]]; then
689     echo
690     echo "${COMMAND_ARR[@]}"
691     echo
692   fi
693
694   FPM_RESULTS=$("${COMMAND_ARR[@]}")
695   FPM_EXIT_CODE=$?
696   fpm_verify_and_scp $FPM_EXIT_CODE $FPM_RESULTS
697 fi
698
699 # Build the 'bare' package without vendor/bundle.
700
701 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")
702
703 if [[ "$DEBUG" != 0 ]]; then
704   echo
705   echo "${COMMAND_ARR[@]}"
706   echo
707 fi
708
709 FPM_RESULTS=$("${COMMAND_ARR[@]}")
710 FPM_EXIT_CODE=$?
711 fpm_verify_and_scp $FPM_EXIT_CODE $FPM_RESULTS
712
713 # Workbench package build done
714
715 # Finally, publish the packages, if necessary
716 if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
717   ssh -p2222 $SCPUSER@$SCPHOST -t bash - <<EOF
718 if [ -n "\$(find -name "$FPM_OUTDIR/*.$FORMAT" -print -quit)" ]; then
719     cd "$FPM_OUTDIR" && $REPO_UPDATE_CMD
720 fi
721 EOF
722 else
723   if [[ "$UPLOAD" != 0 ]]; then
724     echo "No new packages generated. No freight run necessary."
725   fi
726 fi
727
728 # clean up temporary GOPATH
729 rm -rf "$GOPATH"
730
731 exit $EXITCODE