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 handle_python_package () {
98 # This function assumes the current working directory is the python package directory
99 if [[ "$UPLOAD" != 0 ]]; then
100 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
101 if [[ "$DEBUG" != 0 ]]; then
102 python setup.py sdist upload
104 python setup.py -q sdist upload
107 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
108 if [[ "$DEBUG" != 0 ]]; then
109 python setup.py sdist
111 python setup.py -q sdist
116 # Build debs for everything
117 build_and_scp_deb () {
118 # The package source. Depending on the source type, this can be a
119 # path, or the name of the package in an upstream repository (e.g.,
123 # The name of the package to build. Defaults to $PACKAGE.
126 # Optional: the vendor of the package. Should be "Curoverse, Inc." for
127 # packages of our own software. Passed to fpm --vendor.
130 # The type of source package. Passed to fpm -s. Default "python".
133 # Optional: the package version number. Passed to fpm -v.
137 if [[ "$PACKAGE_NAME" == "" ]]; then
138 PACKAGE_NAME=$PACKAGE
141 if [[ "$PACKAGE_TYPE" == "" ]]; then
142 PACKAGE_TYPE='python'
145 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")
147 if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then
148 COMMAND_ARR+=('-n' "$PACKAGE_NAME")
151 if [[ "$VENDOR" != "" ]]; then
152 COMMAND_ARR+=('--vendor' "$VENDOR")
155 if [[ "$VERSION" != "" ]]; then
156 COMMAND_ARR+=('-v' "$VERSION")
159 # Append remaining function arguments directly to fpm's command line.
164 COMMAND_ARR+=("$PACKAGE")
166 if [[ "$DEBUG" != 0 ]]; then
168 echo "${COMMAND_ARR[@]}"
172 FPM_RESULTS=$("${COMMAND_ARR[@]}")
176 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\-.]*\.deb) ]]; then
177 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}
180 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
182 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
187 if [[ ! $FPM_RESULTS =~ "File already exists" ]]; then
188 if [[ "$FPM_EXIT_CODE" != "0" ]]; then
189 echo "Error building debian package for $1:\n $FPM_RESULTS"
191 if [[ "$UPLOAD" != 0 ]]; then
192 scp -P2222 $FPM_PACKAGE_NAME $APTUSER@$APTSERVER:tmp/
197 echo "Debian package $FPM_PACKAGE_NAME exists, not rebuilding"
202 source /etc/profile.d/rvm.sh
204 # Make all files world-readable -- jenkins runs with umask 027, and has checked
205 # out our git tree here
206 chmod o+r "$WORKSPACE" -R
208 # More cleanup - make sure all executables that we'll package are 755
209 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
211 # Now fix our umask to something better suited to building and publishing
215 if [[ "$DEBUG" != 0 ]]; then
216 echo "umask is" `umask`
220 if [[ "$DEBUG" != 0 ]]; then
221 echo -e "\nPerl packages\n"
224 if [[ "$DEBUG" != 0 ]]; then
230 cd "$WORKSPACE/sdk/perl"
232 if [[ -e Makefile ]]; then
233 make realclean >"$PERL_OUT"
235 find -maxdepth 1 \( -name 'MANIFEST*' -or -name 'libarvados-perl_*.deb' \) \
239 perl Makefile.PL >"$PERL_OUT" && \
240 make install PREFIX=install INSTALLDIRS=perl >"$PERL_OUT" && \
241 build_and_scp_deb install/=/usr libarvados-perl "Curoverse, Inc." dir \
242 "$(version_from_git)"
245 if [[ "$DEBUG" != 0 ]]; then
251 if type rvm-exec 2>/dev/null; then
252 FPM_GEM_PREFIX=$(rvm-exec system gem environment gemdir)
254 FPM_GEM_PREFIX=$(gem environment gemdir)
259 # clean up old packages
260 find -maxdepth 1 \( -name 'arvados-*.gem' -or -name 'rubygem-arvados_*.deb' \) \
263 if [[ "$DEBUG" != 0 ]]; then
264 gem build arvados.gemspec
266 # -q appears to be broken in gem version 2.2.2
267 gem build arvados.gemspec -q >/dev/null
270 if [[ "$UPLOAD" != 0 ]]; then
272 gem push arvados-*gem
275 build_and_scp_deb arvados-*.gem "" "Curoverse, Inc." gem "" \
276 --prefix "$FPM_GEM_PREFIX"
278 # Build arvados-cli GEM
282 rm -f arvados-cli*gem
284 if [[ "$DEBUG" != 0 ]]; then
285 gem build arvados-cli.gemspec
287 # -q appears to be broken in gem version 2.2.2
288 gem build arvados-cli.gemspec -q >/dev/null
291 if [[ "$UPLOAD" != 0 ]]; then
293 gem push arvados-cli*gem
297 if [[ "$DEBUG" != 0 ]]; then
299 echo "Python packages"
304 PKG_VERSION=$(version_from_git)
307 handle_python_package
309 cd ../../services/fuse
310 handle_python_package
312 cd ../../services/nodemanager
313 handle_python_package
315 if [[ ! -d "$WORKSPACE/debs" ]]; then
316 mkdir -p $WORKSPACE/debs
320 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
321 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
322 mkdir "$WORKSPACE/src-build-dir"
324 if [[ "$DEBUG" != 0 ]]; then
325 git clone https://github.com/curoverse/arvados.git src-build-dir
327 git clone -q https://github.com/curoverse/arvados.git src-build-dir
331 cd "$WORKSPACE/src-build-dir"
332 # just in case, check out master
333 if [[ "$DEBUG" != 0 ]]; then
336 # go into detached-head state
337 git checkout `git log --format=format:%h -n1 .`
339 git checkout -q master
341 # go into detached-head state
342 git checkout -q `git log --format=format:%h -n1 .`
345 # Build arvados src deb package
347 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"
349 # clean up, check out master and step away from detached-head state
350 cd "$WORKSPACE/src-build-dir"
351 if [[ "$DEBUG" != 0 ]]; then
354 git checkout -q master
358 export GOPATH=$(mktemp -d)
359 mkdir -p "$GOPATH/src/git.curoverse.com"
360 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
363 go get "git.curoverse.com/arvados.git/services/keepstore"
365 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"
368 go get "git.curoverse.com/arvados.git/services/keepproxy"
370 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"
373 go get "git.curoverse.com/arvados.git/services/crunchstat"
375 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"
378 # Please resist the temptation to add --no-python-fix-name to the fpm call here
379 # (which would remove the python- prefix from the package name), because this
380 # package is a dependency of arvados-fuse, and fpm can not omit the python-
381 # prefix from only one of the dependencies of a package... Maybe I could
382 # whip up a patch and send it upstream, but that will be for another day. Ward,
385 build_and_scp_deb $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"
388 # Please seem comment about --no-python-fix-name above; we stay consistent and do
389 # not omit the python- prefix first.
391 build_and_scp_deb $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"
395 build_and_scp_deb $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"
398 for deppkg in python-gflags pyvcf google-api-python-client oauth2client \
399 pyasn1 pyasn1-modules rsa uritemplate httplib2 ws4py virtualenv \
400 pykka apache-libcloud requests six; do
401 build_and_scp_deb "$deppkg"
404 # cwltool from common-workflow-language. We use this in arv-run-pipeline-instance.
405 # We use $WORKSPACE/common-workflow-language as the clean directory from which to build the cwltool package
406 if [[ ! -d "$WORKSPACE/common-workflow-language" ]]; then
407 mkdir "$WORKSPACE/common-workflow-language"
409 if [[ "$DEBUG" != 0 ]]; then
410 git clone https://github.com/rabix/common-workflow-language.git common-workflow-language
412 git clone -q https://github.com/rabix/common-workflow-language.git common-workflow-language
416 cd "$WORKSPACE/common-workflow-language"
417 if [[ "$DEBUG" != 0 ]]; then
421 git checkout -q master
426 handle_python_package
427 CWLTOOL_VERSION=`git log --first-parent --max-count=1 --format='format:0.1.%ct.%h'`
429 # Build cwltool package
432 build_and_scp_deb $WORKSPACE/common-workflow-language/reference cwltool 'Common Workflow Language Working Group' 'python' "$(awk '($1 == "Version:"){print $2}' $WORKSPACE/common-workflow-language/reference/cwltool.egg-info/PKG-INFO)"
434 # Finally, publish the packages, if necessary
435 if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
436 ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
438 if [[ "$UPLOAD" != 0 ]]; then
439 echo "No new packages generated. No freight run necessary."
443 # clean up temporary GOPATH