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"
88 handle_python_package () {
89 # This function assumes the current working directory is the python package directory
90 if [[ "$UPLOAD" != 0 ]]; then
91 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
92 if [[ "$DEBUG" != 0 ]]; then
93 python setup.py sdist upload
95 python setup.py -q sdist upload
98 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
99 if [[ "$DEBUG" != 0 ]]; then
100 python setup.py sdist
102 python setup.py -q sdist
107 # Build debs for everything
108 build_and_scp_deb () {
120 if [[ "$PACKAGE_NAME" == "" ]]; then
121 PACKAGE_NAME=$PACKAGE
124 if [[ "$PACKAGE_TYPE" == "" ]]; then
125 PACKAGE_TYPE='python'
128 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")
130 if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then
131 COMMAND_ARR+=('-n' "$PACKAGE_NAME")
134 if [[ "$VENDOR" != "" ]]; then
135 COMMAND_ARR+=('--vendor' "$VENDOR")
138 if [[ "$VERSION" != "" ]]; then
139 COMMAND_ARR+=('-v' "$VERSION")
146 COMMAND_ARR+=("$PACKAGE")
148 if [[ "$DEBUG" != 0 ]]; then
150 echo "${COMMAND_ARR[@]}"
154 FPM_RESULTS=$("${COMMAND_ARR[@]}")
158 if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\-.]*\.deb) ]]; then
159 FPM_PACKAGE_NAME=${BASH_REMATCH[1]}
162 if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
164 echo "Error: $PACKAGE: Unable to figure out package name from fpm results:"
169 if [[ ! $FPM_RESULTS =~ "File already exists" ]]; then
170 if [[ "$FPM_EXIT_CODE" != "0" ]]; then
171 echo "Error building debian package for $1:\n $FPM_RESULTS"
173 if [[ "$UPLOAD" != 0 ]]; then
174 scp -P2222 $FPM_PACKAGE_NAME $APTUSER@$APTSERVER:tmp/
179 echo "Debian package $FPM_PACKAGE_NAME exists, not rebuilding"
184 source /etc/profile.d/rvm.sh
186 # Make all files world-readable -- jenkins runs with umask 027, and has checked
187 # out our git tree here
188 chmod o+r "$WORKSPACE" -R
190 # More cleanup - make sure all executables that we'll package are 755
191 find -type d -name 'bin' |xargs -I {} find {} -type f |xargs -I {} chmod 755 {}
193 # Now fix our umask to something better suited to building and publishing
197 if [[ "$DEBUG" != 0 ]]; then
198 echo "umask is" `umask`
202 if [[ "$DEBUG" != 0 ]]; then
213 if [[ "$DEBUG" != 0 ]]; then
214 gem build arvados.gemspec
216 # -q appears to be broken in gem version 2.2.2
217 gem build arvados.gemspec -q >/dev/null
220 if [[ "$UPLOAD" != 0 ]]; then
222 gem push arvados-*gem
225 # Build arvados-cli GEM
229 rm -f arvados-cli*gem
231 if [[ "$DEBUG" != 0 ]]; then
232 gem build arvados-cli.gemspec
234 # -q appears to be broken in gem version 2.2.2
235 gem build arvados-cli.gemspec -q >/dev/null
238 if [[ "$UPLOAD" != 0 ]]; then
240 gem push arvados-cli*gem
244 if [[ "$DEBUG" != 0 ]]; then
246 echo "Python packages"
252 GIT_TIMESTAMP=`git log --first-parent --max-count=1 --format=format:%ct -n1 .`
253 HUMAN_READABLE_TIMESTAMP=`TZ=UTC date -d @$GIT_TIMESTAMP +%Y%m%d%H%M%S`
254 GIT_HASH=`git log --first-parent --max-count=1 --format=format:$HUMAN_READABLE_TIMESTAMP.%h -n1 .`
257 handle_python_package
259 cd ../../services/fuse
260 handle_python_package
262 cd ../../services/nodemanager
263 handle_python_package
265 if [[ ! -d "$WORKSPACE/debs" ]]; then
266 mkdir -p $WORKSPACE/debs
270 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
271 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
272 mkdir "$WORKSPACE/src-build-dir"
274 if [[ "$DEBUG" != 0 ]]; then
275 git clone https://github.com/curoverse/arvados.git src-build-dir
277 git clone -q https://github.com/curoverse/arvados.git src-build-dir
281 cd "$WORKSPACE/src-build-dir"
282 # just in case, check out master
283 if [[ "$DEBUG" != 0 ]]; then
286 # go into detached-head state
287 git checkout `git log --format=format:%h -n1 .`
289 git checkout -q master
291 # go into detached-head state
292 git checkout -q `git log --format=format:%h -n1 .`
295 # Build arvados src deb package
297 build_and_scp_deb $WORKSPACE/src-build-dir/=/usr/local/arvados/src arvados-src 'Curoverse, Inc.' 'dir' "0.1.$GIT_HASH" "--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"
299 # clean up, check out master and step away from detached-head state
300 cd "$WORKSPACE/src-build-dir"
301 if [[ "$DEBUG" != 0 ]]; then
304 git checkout -q master
308 export GOPATH=$(mktemp -d)
309 mkdir -p "$GOPATH/src/git.curoverse.com"
310 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
313 go get "git.curoverse.com/arvados.git/services/keepstore"
315 build_and_scp_deb $GOPATH/bin/keepstore=/usr/bin/keepstore keepstore 'Curoverse, Inc.' 'dir' "0.1.$GIT_HASH" "--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"
318 go get "git.curoverse.com/arvados.git/services/keepproxy"
320 build_and_scp_deb $GOPATH/bin/keepproxy=/usr/bin/keepproxy keepproxy 'Curoverse, Inc.' 'dir' "0.1.$GIT_HASH" "--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"
323 go get "git.curoverse.com/arvados.git/services/crunchstat"
325 build_and_scp_deb $GOPATH/bin/crunchstat=/usr/bin/crunchstat crunchstat 'Curoverse, Inc.' 'dir' "0.1.$GIT_HASH" "--url=https://arvados.org" "--license=GNU Affero General Public License, version 3.0" "--description=Crunchstat gathers cpu/memory/network statistics of running Crunch jobs"
328 # Please resist the temptation to add --no-python-fix-name to the fpm call here
329 # (which would remove the python- prefix from the package name), because this
330 # package is a dependency of arvados-fuse, and fpm can not omit the python-
331 # prefix from only one of the dependencies of a package... Maybe I could
332 # whip up a patch and send it upstream, but that will be for another day. Ward,
335 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"
338 # Please seem comment about --no-python-fix-name above; we stay consistent and do
339 # not omit the python- prefix first.
341 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"
345 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"
348 for deppkg in python-gflags pyvcf google-api-python-client oauth2client \
349 pyasn1 pyasn1-modules rsa uritemplate httplib2 ws4py virtualenv \
350 pykka apache-libcloud requests six; do
351 build_and_scp_deb "$deppkg"
354 # Finally, publish the packages, if necessary
355 if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
356 ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
358 if [[ "$UPLOAD" != 0 ]]; then
359 echo "No new packages generated. No freight run necessary."
363 # clean up temporary GOPATH