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")
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 # Now fix our umask to something better suited to building and publishing
194 if [[ "$DEBUG" != 0 ]]; then
195 echo "umask is" `umask`
199 if [[ "$DEBUG" != 0 ]]; then
210 if [[ "$DEBUG" != 0 ]]; then
211 gem build arvados.gemspec
213 # -q appears to be broken in gem version 2.2.2
214 gem build arvados.gemspec -q >/dev/null
217 if [[ "$UPLOAD" != 0 ]]; then
219 gem push arvados-*gem
222 # Build arvados-cli GEM
226 rm -f arvados-cli*gem
228 if [[ "$DEBUG" != 0 ]]; then
229 gem build arvados-cli.gemspec
231 # -q appears to be broken in gem version 2.2.2
232 gem build arvados-cli.gemspec -q >/dev/null
235 if [[ "$UPLOAD" != 0 ]]; then
237 gem push arvados-cli*gem
241 if [[ "$DEBUG" != 0 ]]; then
243 echo "Python packages"
249 GIT_TIMESTAMP=`git log --first-parent --max-count=1 --format=format:%ct -n1 .`
250 HUMAN_READABLE_TIMESTAMP=`TZ=UTC date -d @$GIT_TIMESTAMP +%Y%m%d%H%M%S`
251 GIT_HASH=`git log --first-parent --max-count=1 --format=format:$HUMAN_READABLE_TIMESTAMP.%h -n1 .`
254 handle_python_package
256 cd ../../services/fuse
257 handle_python_package
259 cd ../../services/nodemanager
260 handle_python_package
262 if [[ ! -d "$WORKSPACE/debs" ]]; then
263 mkdir -p $WORKSPACE/debs
267 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
268 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
269 mkdir "$WORKSPACE/src-build-dir"
271 if [[ "$DEBUG" != 0 ]]; then
272 git clone https://github.com/curoverse/arvados.git src-build-dir
274 git clone -q https://github.com/curoverse/arvados.git src-build-dir
278 cd "$WORKSPACE/src-build-dir"
279 # just in case, check out master
280 if [[ "$DEBUG" != 0 ]]; then
283 # go into detached-head state
284 git checkout `git log --format=format:%h -n1 .`
286 git checkout -q master
288 # go into detached-head state
289 git checkout -q `git log --format=format:%h -n1 .`
292 # Build arvados src deb package
294 build_and_scp_deb $WORKSPACE/src-build-dir/=/usr/local/arvados/src arvados-src 'Curoverse, Inc.' 'dir' "0.1.$GIT_HASH" "-x '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"
296 # clean up, check out master and step away from detached-head state
297 cd "$WORKSPACE/src-build-dir"
298 if [[ "$DEBUG" != 0 ]]; then
301 git checkout -q master
305 export GOPATH=$(mktemp -d)
306 mkdir -p "$GOPATH/src/git.curoverse.com"
307 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
310 go get "git.curoverse.com/arvados.git/services/keepstore"
312 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"
315 go get "git.curoverse.com/arvados.git/services/keepproxy"
317 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"
320 go get "git.curoverse.com/arvados.git/services/crunchstat"
322 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"
325 # Please resist the temptation to add --no-python-fix-name to the fpm call here
326 # (which would remove the python- prefix from the package name), because this
327 # package is a dependency of arvados-fuse, and fpm can not omit the python-
328 # prefix from only one of the dependencies of a package... Maybe I could
329 # whip up a patch and send it upstream, but that will be for another day. Ward,
332 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"
335 # Please seem comment about --no-python-fix-name above; we stay consistent and do
336 # not omit the python- prefix first.
338 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"
342 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"
345 for deppkg in python-gflags pyvcf google-api-python-client oauth2client \
346 pyasn1 pyasn1-modules rsa uritemplate httplib2 ws4py virtualenv \
347 pykka apache-libcloud; do
348 build_and_scp_deb "$deppkg"
351 # Finally, publish the packages, if necessary
352 if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
353 ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
355 if [[ "$UPLOAD" != 0 ]]; then
356 echo "No new packages generated. No freight run necessary."
360 # clean up temporary GOPATH