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 source /etc/profile.d/rvm.sh
213 # Make all files world-readable -- jenkins runs with umask 027, and has checked
214 # out our git tree here
215 chmod o+r "$WORKSPACE" -R
217 # More cleanup - make sure all executables that we'll package are 755
218 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
220 # Now fix our umask to something better suited to building and publishing
224 if [[ "$DEBUG" != 0 ]]; then
225 echo "umask is" `umask`
229 if [[ "$DEBUG" != 0 ]]; then
230 echo -e "\nPerl packages\n"
233 if [[ "$DEBUG" != 0 ]]; then
239 cd "$WORKSPACE/sdk/perl"
241 if [[ -e Makefile ]]; then
242 make realclean >"$PERL_OUT"
244 find -maxdepth 1 \( -name 'MANIFEST*' -or -name 'libarvados-perl_*.deb' \) \
248 perl Makefile.PL >"$PERL_OUT" && \
249 make install PREFIX=install INSTALLDIRS=perl >"$PERL_OUT" && \
250 build_and_scp_deb install/=/usr libarvados-perl "Curoverse, Inc." dir \
251 "$(version_from_git)"
254 if [[ "$DEBUG" != 0 ]]; then
260 if type rvm-exec 2>/dev/null; then
261 FPM_GEM_PREFIX=$(rvm-exec system gem environment gemdir)
263 FPM_GEM_PREFIX=$(gem environment gemdir)
268 # clean up old packages
269 find -maxdepth 1 \( -name 'arvados-*.gem' -or -name 'rubygem-arvados_*.deb' \) \
272 if [[ "$DEBUG" != 0 ]]; then
273 gem build arvados.gemspec
275 # -q appears to be broken in gem version 2.2.2
276 gem build arvados.gemspec -q >/dev/null
279 if [[ "$UPLOAD" != 0 ]]; then
281 gem push arvados-*gem
284 build_and_scp_deb arvados-*.gem "" "Curoverse, Inc." gem "" \
285 --prefix "$FPM_GEM_PREFIX"
287 # Build arvados-cli GEM
291 rm -f arvados-cli*gem
293 if [[ "$DEBUG" != 0 ]]; then
294 gem build arvados-cli.gemspec
296 # -q appears to be broken in gem version 2.2.2
297 gem build arvados-cli.gemspec -q >/dev/null
300 if [[ "$UPLOAD" != 0 ]]; then
302 gem push arvados-cli*gem
306 if [[ "$DEBUG" != 0 ]]; then
308 echo "Python packages"
315 handle_python_package
317 cd ../../services/fuse
318 handle_python_package
320 cd ../../services/nodemanager
321 handle_python_package
323 if [[ ! -d "$WORKSPACE/debs" ]]; then
324 mkdir -p $WORKSPACE/debs
328 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
329 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
330 mkdir "$WORKSPACE/src-build-dir"
332 if [[ "$DEBUG" != 0 ]]; then
333 git clone https://github.com/curoverse/arvados.git src-build-dir
335 git clone -q https://github.com/curoverse/arvados.git src-build-dir
339 cd "$WORKSPACE/src-build-dir"
340 # just in case, check out master
341 if [[ "$DEBUG" != 0 ]]; then
344 # go into detached-head state
345 git checkout `git log --format=format:%h -n1 .`
347 git checkout -q master
349 # go into detached-head state
350 git checkout -q `git log --format=format:%h -n1 .`
353 # Build arvados src deb package
355 PKG_VERSION=$(version_from_git)
357 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"
359 # clean up, check out master and step away from detached-head state
360 cd "$WORKSPACE/src-build-dir"
361 if [[ "$DEBUG" != 0 ]]; then
364 git checkout -q master
368 export GOPATH=$(mktemp -d)
369 mkdir -p "$GOPATH/src/git.curoverse.com"
370 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
373 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepstore"
374 PKG_VERSION=$(version_from_git)
375 go get "git.curoverse.com/arvados.git/services/keepstore"
377 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"
380 cd "$GOPATH/src/git.curoverse.com/arvados.git/sdk/go"
381 GO_SDK_VERSION=$(version_from_git)
382 GO_SDK_TIMESTAMP=$(timestamp_from_git)
384 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/keepproxy"
385 KEEPPROXY_VERSION=$(version_from_git)
386 KEEPPROXY_TIMESTAMP=$(timestamp_from_git)
388 if [[ "$GO_SDK_TIMESTAMP" -gt "$KEEPPROXY_TIMESTAMP" ]]; then
389 PKG_VERSION=$GO_SDK_VERSION
391 PKG_VERSION=$KEEPPROXY_VERSION
394 go get "git.curoverse.com/arvados.git/services/keepproxy"
396 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"
399 cd "$GOPATH/src/git.curoverse.com/arvados.git/services/crunchstat"
400 PKG_VERSION=$(version_from_git)
401 go get "git.curoverse.com/arvados.git/services/crunchstat"
403 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"
406 # Please resist the temptation to add --no-python-fix-name to the fpm call here
407 # (which would remove the python- prefix from the package name), because this
408 # package is a dependency of arvados-fuse, and fpm can not omit the python-
409 # prefix from only one of the dependencies of a package... Maybe I could
410 # whip up a patch and send it upstream, but that will be for another day. Ward,
413 # Python version numbering is obscure. Strip dashes and replace them with dots
414 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
415 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"
418 # Please seem comment about --no-python-fix-name above; we stay consistent and do
419 # not omit the python- prefix first.
421 # Python version numbering is obscure. Strip dashes and replace them with dots
422 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
423 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"
427 # Python version numbering is obscure. Strip dashes and replace them with dots
428 # to match our other version numbers. Cf. commit 4afcb8c, compliance with PEP-440.
429 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"
432 for deppkg in python-gflags pyvcf google-api-python-client oauth2client \
433 pyasn1 pyasn1-modules rsa uritemplate httplib2 ws4py virtualenv \
434 pykka apache-libcloud requests six pyexecjs jsonschema; do
435 build_and_scp_deb "$deppkg"
438 # cwltool from common-workflow-language. We use this in arv-run-pipeline-instance.
439 # We use $WORKSPACE/common-workflow-language as the clean directory from which to build the cwltool package
440 if [[ ! -d "$WORKSPACE/common-workflow-language" ]]; then
441 mkdir "$WORKSPACE/common-workflow-language"
443 if [[ "$DEBUG" != 0 ]]; then
444 git clone https://github.com/common-workflow-language/common-workflow-language.git common-workflow-language
446 git clone -q https://github.com/common-workflow-language/common-workflow-language.git common-workflow-language
450 cd "$WORKSPACE/common-workflow-language"
451 if [[ "$DEBUG" != 0 ]]; then
455 git checkout -q master
460 handle_python_package
461 CWLTOOL_VERSION=`git log --first-parent --max-count=1 --format='format:0.1.%ct.%h'`
463 # Build cwltool package
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/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)"
469 # Finally, publish the packages, if necessary
470 if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
471 ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
473 if [[ "$UPLOAD" != 0 ]]; then
474 echo "No new packages generated. No freight run necessary."
478 # clean up temporary GOPATH