4 read -rd "\000" helpmessage <<EOF
5 $(basename $0): Build Arvados packages and (optionally) upload them.
8 WORKSPACE=/path/to/arvados $(basename $0) [options]
12 --upload Upload packages (default: false)
13 --scp-user USERNAME Scp user for apt server (only required when --upload is specified)
14 --apt-server HOSTNAME Apt server hostname (only required when --upload is specified)
15 --debug Output debug information (default: false)
17 WORKSPACE=path Path to the Arvados source tree to build packages from
32 echo >&2 "$helpmessage"
49 echo >&2 "$0: Unrecognized option: '$arg'. Try: $0 --help"
56 if [[ "$UPLOAD" != '0' && ("$APTUSER" == '' || "$APTSERVER" == '') ]]; then
57 echo >&2 "$helpmessage"
59 echo >&2 "Error: please specify --scp-user and --apt-server if --upload is set"
65 if ! [[ -n "$WORKSPACE" ]]; then
66 echo >&2 "$helpmessage"
68 echo >&2 "Error: WORKSPACE environment variable not set"
74 fpm --version >/dev/null 2>&1
76 if [[ "$?" != 0 ]]; then
77 echo >&2 "$helpmessage"
79 echo >&2 "Error: fpm not found"
84 if ! easy_install3 --version >/dev/null; then
88 Error: easy_install3 (from python3-setuptools) not found
94 if [[ "$DEBUG" != 0 ]]; then
95 echo "Workspace is $WORKSPACE"
99 # Generates a version number from the git log for the current working
100 # directory, and writes it to stdout.
101 local git_ts git_hash
102 declare $(TZ=UTC git log -n1 --first-parent --max-count=1 \
103 --format=format:"git_ts=%ct git_hash=%h" .)
104 echo "0.1.$(date -ud "@$git_ts" +%Y%m%d%H%M%S).$git_hash"
107 timestamp_from_git() {
108 # Generates a version number from the git log for the current working
109 # directory, and writes it to stdout.
110 local git_ts git_hash
111 declare $(TZ=UTC git log -n1 --first-parent --max-count=1 \
112 --format=format:"git_ts=%ct git_hash=%h" .)
116 handle_python_package () {
117 # This function assumes the current working directory is the python package directory
118 if [[ "$UPLOAD" != 0 ]]; then
119 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
120 if [[ "$DEBUG" != 0 ]]; then
121 python setup.py sdist upload
123 python setup.py -q sdist upload
126 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
127 if [[ "$DEBUG" != 0 ]]; then
128 python setup.py sdist
130 python setup.py -q sdist
135 # Build debs for everything
136 build_and_scp_deb () {
137 # The package source. Depending on the source type, this can be a
138 # path, or the name of the package in an upstream repository (e.g.,
142 # The name of the package to build. Defaults to $PACKAGE.
143 PACKAGE_NAME=${1:-$PACKAGE}
145 # Optional: the vendor of the package. Should be "Curoverse, Inc." for
146 # packages of our own software. Passed to fpm --vendor.
149 # The type of source package. Passed to fpm -s. Default "python".
150 PACKAGE_TYPE=${1:-python}
153 if [ "python3" = "$PACKAGE_TYPE" ]; then
154 # fpm does not actually support this package type. Instead we recognize
155 # it as a convenience shortcut to add several necessary arguments to
156 # fpm's command line later.
158 set -- "$@" --python-bin python3 --python-easyinstall easy_install3 \
159 --python-package-name-prefix python3 --depends python3
161 # Optional: the package version number. Passed to fpm -v.
165 declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "-s" "$PACKAGE_TYPE" "-t" "deb" "-x" "usr/local/lib/python2.7/dist-packages/tests")
167 if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then
168 COMMAND_ARR+=('-n' "$PACKAGE_NAME")
171 if [[ "$VENDOR" != "" ]]; then
172 COMMAND_ARR+=('--vendor' "$VENDOR")
175 if [[ "$VERSION" != "" ]]; then
176 COMMAND_ARR+=('-v' "$VERSION")
179 # Append remaining function arguments directly to fpm's command line.
184 COMMAND_ARR+=("$PACKAGE")
186 if [[ "$DEBUG" != 0 ]]; then
188 echo "${COMMAND_ARR[@]}"
192 FPM_RESULTS=$("${COMMAND_ARR[@]}")
196 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\-.]*\.deb) ]]; then
197 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}
200 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
202 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
207 if [[ ! $FPM_RESULTS =~ "File already exists" ]]; then
208 if [[ "$FPM_EXIT_CODE" != "0" ]]; then
209 echo "Error building debian package for $1:\n $FPM_RESULTS"
211 if [[ "$UPLOAD" != 0 ]]; then
212 scp -P2222 $FPM_PACKAGE_NAME $APTUSER@$APTSERVER:tmp/
217 echo "Debian package $FPM_PACKAGE_NAME exists, not rebuilding"
222 if [[ -f /etc/profile.d/rvm.sh ]]; then
223 source /etc/profile.d/rvm.sh
226 # Make all files world-readable -- jenkins runs with umask 027, and has checked
227 # out our git tree here
228 chmod o+r "$WORKSPACE" -R
230 # More cleanup - make sure all executables that we'll package are 755
231 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
233 # Now fix our umask to something better suited to building and publishing
237 if [[ "$DEBUG" != 0 ]]; then
238 echo "umask is" `umask`
242 if [[ "$DEBUG" != 0 ]]; then
243 echo -e "\nPerl packages\n"
246 if [[ "$DEBUG" != 0 ]]; then
252 cd "$WORKSPACE/sdk/perl"
254 if [[ -e Makefile ]]; then
255 make realclean >"$PERL_OUT"
257 find -maxdepth 1 \( -name 'MANIFEST*' -or -name 'libarvados-perl_*.deb' \) \
261 perl Makefile.PL >"$PERL_OUT" && \
262 make install PREFIX=install INSTALLDIRS=perl >"$PERL_OUT" && \
263 build_and_scp_deb install/=/usr libarvados-perl "Curoverse, Inc." dir \
264 "$(version_from_git)"
267 if [[ "$DEBUG" != 0 ]]; then
273 if type rvm-exec 2>/dev/null; then
274 FPM_GEM_PREFIX=$(rvm-exec system gem environment gemdir)
276 FPM_GEM_PREFIX=$(gem environment gemdir)
281 # clean up old packages
282 find -maxdepth 1 \( -name 'arvados-*.gem' -or -name 'rubygem-arvados_*.deb' \) \
285 if [[ "$DEBUG" != 0 ]]; then
286 gem build arvados.gemspec
288 # -q appears to be broken in gem version 2.2.2
289 gem build arvados.gemspec -q >/dev/null
292 if [[ "$UPLOAD" != 0 ]]; then
294 gem push arvados-*gem
297 build_and_scp_deb arvados-*.gem "" "Curoverse, Inc." gem "" \
298 --prefix "$FPM_GEM_PREFIX"
300 # Build arvados-cli GEM
304 rm -f arvados-cli*gem
306 if [[ "$DEBUG" != 0 ]]; then
307 gem build arvados-cli.gemspec
309 # -q appears to be broken in gem version 2.2.2
310 gem build arvados-cli.gemspec -q >/dev/null
313 if [[ "$UPLOAD" != 0 ]]; then
315 gem push arvados-cli*gem
319 if [[ "$DEBUG" != 0 ]]; then
321 echo "Python packages"
328 handle_python_package
330 cd ../../services/fuse
331 handle_python_package
333 cd ../../services/nodemanager
334 handle_python_package
336 if [[ ! -d "$WORKSPACE/debs" ]]; then
337 mkdir -p $WORKSPACE/debs
341 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
342 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
343 mkdir "$WORKSPACE/src-build-dir"
345 if [[ "$DEBUG" != 0 ]]; then
346 git clone https://github.com/curoverse/arvados.git src-build-dir
348 git clone -q https://github.com/curoverse/arvados.git src-build-dir
352 cd "$WORKSPACE/src-build-dir"
353 # just in case, check out master
354 if [[ "$DEBUG" != 0 ]]; then
357 # go into detached-head state
358 git checkout `git log --format=format:%h -n1 .`
360 git checkout -q master
362 # go into detached-head state
363 git checkout -q `git log --format=format:%h -n1 .`
366 # Build arvados src deb package
368 PKG_VERSION=$(version_from_git)
370 build_and_scp_deb $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"
372 # clean up, check out master and step away from detached-head state
373 cd "$WORKSPACE/src-build-dir"
374 if [[ "$DEBUG" != 0 ]]; then
377 git checkout -q master
381 export GOPATH=$(mktemp -d)
382 mkdir -p "$GOPATH/src/git.curoverse.com"
383 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
386 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepstore"
387 PKG_VERSION=$(version_from_git)
388 go get "git.curoverse.com/arvados.git/services/keepstore"
390 build_and_scp_deb $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"
393 cd "$GOPATH/src/git.curoverse.com/arvados.git/sdk/go"
394 GO_SDK_VERSION=$(version_from_git)
395 GO_SDK_TIMESTAMP=$(timestamp_from_git)
398 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepproxy"
399 KEEPPROXY_VERSION=$(version_from_git)
400 KEEPPROXY_TIMESTAMP=$(timestamp_from_git)
402 if [[ "$GO_SDK_TIMESTAMP" -gt "$KEEPPROXY_TIMESTAMP" ]]; then
403 PKG_VERSION=$GO_SDK_VERSION
405 PKG_VERSION=$KEEPPROXY_VERSION
408 go get "git.curoverse.com/arvados.git/services/keepproxy"
410 build_and_scp_deb $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"
413 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/datamanager"
414 DATAMANAGER_VERSION=$(version_from_git)
415 DATAMANAGER_TIMESTAMP=$(timestamp_from_git)
417 if [[ "$GO_SDK_TIMESTAMP" -gt "$DATAMANAGER_TIMESTAMP" ]]; then
418 PKG_VERSION=$GO_SDK_VERSION
420 PKG_VERSION=$DATAMANAGER_VERSION
423 go get "git.curoverse.com/arvados.git/services/datamanager"
425 build_and_scp_deb $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."
428 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/arv-git-httpd"
429 ARVGITHTTPD_VERSION=$(version_from_git)
430 ARVGITHTTPD_TIMESTAMP=$(timestamp_from_git)
432 if [[ "$GO_SDK_TIMESTAMP" -gt "$ARVGITHTTPD_TIMESTAMP" ]]; then
433 PKG_VERSION=$GO_SDK_VERSION
435 PKG_VERSION=$ARVGITHTTPD_VERSION
438 go get "git.curoverse.com/arvados.git/services/arv-git-httpd"
440 build_and_scp_deb $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."
443 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/crunchstat"
444 PKG_VERSION=$(version_from_git)
445 go get "git.curoverse.com/arvados.git/services/crunchstat"
447 build_and_scp_deb $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"
450 # Please resist the temptation to add --no-python-fix-name to the fpm call here
451 # (which would remove the python- prefix from the package name), because this
452 # package is a dependency of arvados-fuse, and fpm can not omit the python-
453 # prefix from only one of the dependencies of a package... Maybe I could
454 # whip up a patch and send it upstream, but that will be for another day. Ward,
457 # Python version numbering is obscure. Strip dashes and replace them with dots
458 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
459 build_and_scp_deb $WORKSPACE/sdk/python python-arvados-python-client 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){ gsub(/-/,".",$2); print $2 }' $WORKSPACE/sdk/python/arvados_python_client.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Arvados Python SDK"
462 # Please see comment about --no-python-fix-name above; we stay consistent and do
463 # not omit the python- prefix first.
465 # Python version numbering is obscure. Strip dashes and replace them with dots
466 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
467 build_and_scp_deb $WORKSPACE/services/fuse python-arvados-fuse 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){ gsub(/-/,".",$2); print $2 }' $WORKSPACE/services/fuse/arvados_fuse.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Keep FUSE driver"
471 # Python version numbering is obscure. Strip dashes and replace them with dots
472 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
473 build_and_scp_deb $WORKSPACE/services/nodemanager arvados-node-manager 'Curoverse, Inc.' 'python' "$(awk '($1 == "Version:"){ gsub(/-/,".",$2); print $2}' $WORKSPACE/services/nodemanager/arvados_node_manager.egg-info/PKG-INFO)" "--url=https://arvados.org" "--description=The Arvados node manager"
475 # The Docker image cleaner
477 build_and_scp_deb $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"
480 for deppkg in python-gflags pyvcf google-api-python-client oauth2client \
481 pyasn1 pyasn1-modules rsa uritemplate httplib2 ws4py virtualenv \
482 pykka apache-libcloud requests six pyexecjs jsonschema ciso8601 \
483 pycrypto backports.ssl_match_hostname; do
484 build_and_scp_deb "$deppkg"
486 # Python 3 dependencies
487 for deppkg in docker-py six requests; do
488 # The empty string is the vendor argument: these aren't Curoverse software.
489 build_and_scp_deb "$deppkg" "python3-$deppkg" "" python3
492 # cwltool from common-workflow-language. We use this in arv-run-pipeline-instance.
493 # We use $WORKSPACE/common-workflow-language as the clean directory from which to build the cwltool package
494 if [[ ! -d "$WORKSPACE/common-workflow-language" ]]; then
495 mkdir "$WORKSPACE/common-workflow-language"
497 if [[ "$DEBUG" != 0 ]]; then
498 git clone https://github.com/common-workflow-language/common-workflow-language.git common-workflow-language
500 git clone -q https://github.com/common-workflow-language/common-workflow-language.git common-workflow-language
504 cd "$WORKSPACE/common-workflow-language"
505 if [[ "$DEBUG" != 0 ]]; then
509 git checkout -q master
514 handle_python_package
515 CWLTOOL_VERSION=`git log --first-parent --max-count=1 --format='format:0.1.%ct.%h'`
517 # Build cwltool package
519 # Python version numbering is obscure. Strip dashes and replace them with dots
520 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
521 build_and_scp_deb $WORKSPACE/common-workflow-language/reference cwltool 'Common Workflow Language Working Group' 'python' "$(awk '($1 == "Version:"){ gsub(/-/,".",$2); print $2 }' $WORKSPACE/common-workflow-language/reference/cwltool.egg-info/PKG-INFO)"
523 # Finally, publish the packages, if necessary
524 if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
525 ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
527 if [[ "$UPLOAD" != 0 ]]; then
528 echo "No new packages generated. No freight run necessary."
532 # clean up temporary GOPATH