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 [[ "$DEBUG" != 0 ]]; then
85 echo "Workspace is $WORKSPACE"
89 # Generates a version number from the git log for the current working
90 # directory, and writes it to stdout.
92 declare $(TZ=UTC git log -n1 --first-parent --max-count=1 \
93 --format=format:"git_ts=%ct git_hash=%h" .)
94 echo "0.1.$(date -ud "@$git_ts" +%Y%m%d%H%M%S).$git_hash"
97 timestamp_from_git() {
98 # Generates a version number from the git log for the current working
99 # directory, and writes it to stdout.
100 local git_ts git_hash
101 declare $(TZ=UTC git log -n1 --first-parent --max-count=1 \
102 --format=format:"git_ts=%ct git_hash=%h" .)
106 handle_python_package () {
107 # This function assumes the current working directory is the python package directory
108 if [[ "$UPLOAD" != 0 ]]; then
109 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
110 if [[ "$DEBUG" != 0 ]]; then
111 python setup.py sdist upload
113 python setup.py -q sdist upload
116 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
117 if [[ "$DEBUG" != 0 ]]; then
118 python setup.py sdist
120 python setup.py -q sdist
125 # Build debs for everything
126 build_and_scp_deb () {
127 # The package source. Depending on the source type, this can be a
128 # path, or the name of the package in an upstream repository (e.g.,
132 # The name of the package to build. Defaults to $PACKAGE.
135 # Optional: the vendor of the package. Should be "Curoverse, Inc." for
136 # packages of our own software. Passed to fpm --vendor.
139 # The type of source package. Passed to fpm -s. Default "python".
142 # Optional: the package version number. Passed to fpm -v.
146 if [[ "$PACKAGE_NAME" == "" ]]; then
147 PACKAGE_NAME=$PACKAGE
150 if [[ "$PACKAGE_TYPE" == "" ]]; then
151 PACKAGE_TYPE='python'
154 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")
156 if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then
157 COMMAND_ARR+=('-n' "$PACKAGE_NAME")
160 if [[ "$VENDOR" != "" ]]; then
161 COMMAND_ARR+=('--vendor' "$VENDOR")
164 if [[ "$VERSION" != "" ]]; then
165 COMMAND_ARR+=('-v' "$VERSION")
168 # Append remaining function arguments directly to fpm's command line.
173 COMMAND_ARR+=("$PACKAGE")
175 if [[ "$DEBUG" != 0 ]]; then
177 echo "${COMMAND_ARR[@]}"
181 FPM_RESULTS=$("${COMMAND_ARR[@]}")
185 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\-.]*\.deb) ]]; then
186 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}
189 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
191 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
196 if [[ ! $FPM_RESULTS =~ "File already exists" ]]; then
197 if [[ "$FPM_EXIT_CODE" != "0" ]]; then
198 echo "Error building debian package for $1:\n $FPM_RESULTS"
200 if [[ "$UPLOAD" != 0 ]]; then
201 scp -P2222 $FPM_PACKAGE_NAME $APTUSER@$APTSERVER:tmp/
206 echo "Debian package $FPM_PACKAGE_NAME exists, not rebuilding"
211 if [[ -f /etc/profile.d/rvm.sh ]]; then
212 source /etc/profile.d/rvm.sh
215 # Make all files world-readable -- jenkins runs with umask 027, and has checked
216 # out our git tree here
217 chmod o+r "$WORKSPACE" -R
219 # More cleanup - make sure all executables that we'll package are 755
220 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
222 # Now fix our umask to something better suited to building and publishing
226 if [[ "$DEBUG" != 0 ]]; then
227 echo "umask is" `umask`
231 if [[ "$DEBUG" != 0 ]]; then
232 echo -e "\nPerl packages\n"
235 if [[ "$DEBUG" != 0 ]]; then
241 cd "$WORKSPACE/sdk/perl"
243 if [[ -e Makefile ]]; then
244 make realclean >"$PERL_OUT"
246 find -maxdepth 1 \( -name 'MANIFEST*' -or -name 'libarvados-perl_*.deb' \) \
250 perl Makefile.PL >"$PERL_OUT" && \
251 make install PREFIX=install INSTALLDIRS=perl >"$PERL_OUT" && \
252 build_and_scp_deb install/=/usr libarvados-perl "Curoverse, Inc." dir \
253 "$(version_from_git)"
256 if [[ "$DEBUG" != 0 ]]; then
262 if type rvm-exec 2>/dev/null; then
263 FPM_GEM_PREFIX=$(rvm-exec system gem environment gemdir)
265 FPM_GEM_PREFIX=$(gem environment gemdir)
270 # clean up old packages
271 find -maxdepth 1 \( -name 'arvados-*.gem' -or -name 'rubygem-arvados_*.deb' \) \
274 if [[ "$DEBUG" != 0 ]]; then
275 gem build arvados.gemspec
277 # -q appears to be broken in gem version 2.2.2
278 gem build arvados.gemspec -q >/dev/null
281 if [[ "$UPLOAD" != 0 ]]; then
283 gem push arvados-*gem
286 build_and_scp_deb arvados-*.gem "" "Curoverse, Inc." gem "" \
287 --prefix "$FPM_GEM_PREFIX"
289 # Build arvados-cli GEM
293 rm -f arvados-cli*gem
295 if [[ "$DEBUG" != 0 ]]; then
296 gem build arvados-cli.gemspec
298 # -q appears to be broken in gem version 2.2.2
299 gem build arvados-cli.gemspec -q >/dev/null
302 if [[ "$UPLOAD" != 0 ]]; then
304 gem push arvados-cli*gem
308 if [[ "$DEBUG" != 0 ]]; then
310 echo "Python packages"
317 handle_python_package
319 cd ../../services/fuse
320 handle_python_package
322 cd ../../services/nodemanager
323 handle_python_package
325 if [[ ! -d "$WORKSPACE/debs" ]]; then
326 mkdir -p $WORKSPACE/debs
330 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
331 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
332 mkdir "$WORKSPACE/src-build-dir"
334 if [[ "$DEBUG" != 0 ]]; then
335 git clone https://github.com/curoverse/arvados.git src-build-dir
337 git clone -q https://github.com/curoverse/arvados.git src-build-dir
341 cd "$WORKSPACE/src-build-dir"
342 # just in case, check out master
343 if [[ "$DEBUG" != 0 ]]; then
346 # go into detached-head state
347 git checkout `git log --format=format:%h -n1 .`
349 git checkout -q master
351 # go into detached-head state
352 git checkout -q `git log --format=format:%h -n1 .`
355 # Build arvados src deb package
357 PKG_VERSION=$(version_from_git)
359 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"
361 # clean up, check out master and step away from detached-head state
362 cd "$WORKSPACE/src-build-dir"
363 if [[ "$DEBUG" != 0 ]]; then
366 git checkout -q master
370 export GOPATH=$(mktemp -d)
371 mkdir -p "$GOPATH/src/git.curoverse.com"
372 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
375 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepstore"
376 PKG_VERSION=$(version_from_git)
377 go get "git.curoverse.com/arvados.git/services/keepstore"
379 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"
382 cd "$GOPATH/src/git.curoverse.com/arvados.git/sdk/go"
383 GO_SDK_VERSION=$(version_from_git)
384 GO_SDK_TIMESTAMP=$(timestamp_from_git)
387 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepproxy"
388 KEEPPROXY_VERSION=$(version_from_git)
389 KEEPPROXY_TIMESTAMP=$(timestamp_from_git)
391 if [[ "$GO_SDK_TIMESTAMP" -gt "$KEEPPROXY_TIMESTAMP" ]]; then
392 PKG_VERSION=$GO_SDK_VERSION
394 PKG_VERSION=$KEEPPROXY_VERSION
397 go get "git.curoverse.com/arvados.git/services/keepproxy"
399 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"
402 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/datamanager"
403 DATAMANAGER_VERSION=$(version_from_git)
404 DATAMANAGER_TIMESTAMP=$(timestamp_from_git)
406 if [[ "$GO_SDK_TIMESTAMP" -gt "$DATAMANAGER_TIMESTAMP" ]]; then
407 PKG_VERSION=$GO_SDK_VERSION
409 PKG_VERSION=$DATAMANAGER_VERSION
412 go get "git.curoverse.com/arvados.git/services/datamanager"
414 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."
417 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/crunchstat"
418 PKG_VERSION=$(version_from_git)
419 go get "git.curoverse.com/arvados.git/services/crunchstat"
421 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"
424 # Please resist the temptation to add --no-python-fix-name to the fpm call here
425 # (which would remove the python- prefix from the package name), because this
426 # package is a dependency of arvados-fuse, and fpm can not omit the python-
427 # prefix from only one of the dependencies of a package... Maybe I could
428 # whip up a patch and send it upstream, but that will be for another day. Ward,
431 # Python version numbering is obscure. Strip dashes and replace them with dots
432 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
433 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"
436 # Please seem comment about --no-python-fix-name above; we stay consistent and do
437 # not omit the python- prefix first.
439 # Python version numbering is obscure. Strip dashes and replace them with dots
440 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
441 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"
445 # Python version numbering is obscure. Strip dashes and replace them with dots
446 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
447 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"
450 for deppkg in python-gflags pyvcf google-api-python-client oauth2client \
451 pyasn1 pyasn1-modules rsa uritemplate httplib2 ws4py virtualenv \
452 pykka apache-libcloud requests six pyexecjs jsonschema ciso8601 \
454 build_and_scp_deb "$deppkg"
457 # cwltool from common-workflow-language. We use this in arv-run-pipeline-instance.
458 # We use $WORKSPACE/common-workflow-language as the clean directory from which to build the cwltool package
459 if [[ ! -d "$WORKSPACE/common-workflow-language" ]]; then
460 mkdir "$WORKSPACE/common-workflow-language"
462 if [[ "$DEBUG" != 0 ]]; then
463 git clone https://github.com/common-workflow-language/common-workflow-language.git common-workflow-language
465 git clone -q https://github.com/common-workflow-language/common-workflow-language.git common-workflow-language
469 cd "$WORKSPACE/common-workflow-language"
470 if [[ "$DEBUG" != 0 ]]; then
474 git checkout -q master
479 handle_python_package
480 CWLTOOL_VERSION=`git log --first-parent --max-count=1 --format='format:0.1.%ct.%h'`
482 # Build cwltool package
484 # Python version numbering is obscure. Strip dashes and replace them with dots
485 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
486 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)"
488 # Finally, publish the packages, if necessary
489 if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
490 ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
492 if [[ "$UPLOAD" != 0 ]]; then
493 echo "No new packages generated. No freight run necessary."
497 # clean up temporary GOPATH