Make run-build-packages.sh much more quiet by default. Also make
[arvados-dev.git] / jenkins / run-build-packages.sh
1 #!/bin/bash
2
3
4 read -rd "\000" helpmessage <<EOF
5 $(basename $0): Build Arvados packages and (optionally) upload them.
6
7 Syntax:
8         $(basename $0) WORKSPACE=/path/to/arvados [options]
9
10 Options:
11
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)
16
17 WORKSPACE=path         Path to the Arvados source tree to build packages from
18
19 EOF
20
21 EXITCODE=0
22 CALL_FREIGHT=0
23
24 DEBUG=0
25 UPLOAD=0
26
27 while [[ -n "$1" ]]
28 do
29     arg="$1"; shift
30     case "$arg" in
31         --help)
32             echo >&2 "$helpmessage"
33             echo >&2
34             exit 1
35             ;;
36         --scp-user)
37             APTUSER="$1"; shift
38             ;;
39         --apt-server)
40             APTSERVER="$1"; shift
41             ;;
42         --debug)
43             DEBUG=1
44             ;;
45         --upload)
46             UPLOAD=1
47             ;;
48         *)
49             echo >&2 "$0: Unrecognized option: '$arg'. Try: $0 --help"
50             exit 1
51             ;;
52     esac
53 done
54
55 # Sanity checks
56 if [[ "$UPLOAD" != '0' && ("$APTUSER" == '' || "$APTSERVER" == '') ]]; then
57   echo >&2 "$helpmessage"
58   echo >&2
59   echo >&2 "Error: please specify --scp-user and --apt-server if --upload is set"
60   echo >&2
61   exit 1
62 fi
63
64 # Sanity check
65 if ! [[ -n "$WORKSPACE" ]]; then
66   echo >&2 "$helpmessage"
67   echo >&2
68   echo >&2 "Error: WORKSPACE environment variable not set"
69   echo >&2
70   exit 1
71 fi
72
73 source /etc/profile.d/rvm.sh
74
75 if [[ "$DEBUG" != 0 ]]; then
76   echo "Workspace is $WORKSPACE"
77 fi
78
79 # Make all files world-readable -- jenkins runs with umask 027, and has checked
80 # out our git tree here
81 chmod o+r "$WORKSPACE" -R
82
83 # Now fix our umask to something better suited to building and publishing
84 # gems and packages
85 umask 0022
86
87 if [[ "$DEBUG" != 0 ]]; then
88   echo "umask is" `umask`
89 fi
90
91 # Build arvados GEM
92 if [[ "$DEBUG" != 0 ]]; then
93   echo "Build and publish ruby gems"
94 fi
95
96 cd "$WORKSPACE"
97 cd sdk/ruby
98 # clean up old gems
99 rm -f arvados-*gem
100
101 if [[ "$DEBUG" != 0 ]]; then
102   gem build arvados.gemspec
103 else
104   # -q appears to be broken in gem version 2.2.2
105   gem build arvados.gemspec -q >/dev/null
106 fi
107
108 if [[ "$UPLOAD" != 0 ]]; then
109   # publish new gem
110   gem push arvados-*gem
111 fi
112
113 # Build arvados-cli GEM
114 cd "$WORKSPACE"
115 cd sdk/cli
116 # clean up old gems
117 rm -f arvados-cli*gem
118
119 if [[ "$DEBUG" != 0 ]]; then
120   gem build arvados-cli.gemspec
121 else
122   # -q appears to be broken in gem version 2.2.2
123   gem build arvados-cli.gemspec -q >/dev/null
124 fi
125
126 if [[ "$UPLOAD" != 0 ]]; then
127   # publish new gem
128   gem push arvados-cli*gem
129 fi
130
131 # Build arvados-python-client Python package
132 if [[ "$DEBUG" != 0 ]]; then
133   echo "Build and publish arvados-python-client package"
134 fi
135
136 cd "$WORKSPACE"
137
138 GIT_HASH=`git log --format=format:%ct.%h -n1 .`
139
140 cd sdk/python
141
142 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
143
144 if [[ "$UPLOAD" != 0 ]]; then
145   # Make sure only to use sdist - that's the only format pip can deal with (sigh)
146   if [[ "$DEBUG" != 0 ]]; then
147     python setup.py sdist upload
148   else
149     python setup.py -q sdist upload
150   fi
151 else
152   # Make sure only to use sdist - that's the only format pip can deal with (sigh)
153   if [[ "$DEBUG" != 0 ]]; then
154     python setup.py sdist
155   else
156     python setup.py -q sdist
157   fi
158 fi
159
160 cd ../../services/fuse
161
162 if [[ "$UPLOAD" != 0 ]]; then
163   # Make sure only to use sdist - that's the only format pip can deal with (sigh)
164   if [[ "$DEBUG" != 0 ]]; then
165     python setup.py sdist upload
166   else
167     python setup.py -q sdist upload
168   fi
169 else
170   # Make sure only to use sdist - that's the only format pip can deal with (sigh)
171   if [[ "$DEBUG" != 0 ]]; then
172     python setup.py sdist
173   else
174     python setup.py -q sdist
175   fi
176 fi
177
178 # Build debs for everything
179 build_and_scp_deb () {
180   PACKAGE=$1
181   shift
182   PACKAGE_NAME=$1
183   shift
184   VENDOR=$1
185   shift
186   PACKAGE_TYPE=$1
187   shift
188   VERSION=$1
189   shift
190
191   if [[ "$PACKAGE_NAME" == "" ]]; then
192     PACKAGE_NAME=$PACKAGE
193   fi
194
195   if [[ "$PACKAGE_TYPE" == "" ]]; then
196     PACKAGE_TYPE='python'
197   fi
198
199   declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "-s" "$PACKAGE_TYPE" "-t" "deb")
200
201   if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then
202     COMMAND_ARR+=('-n' "$PACKAGE_NAME")
203   fi
204
205   if [[ "$VENDOR" != "" ]]; then
206     COMMAND_ARR+=('--vendor' "$VENDOR")
207   fi
208
209   if [[ "$VERSION" != "" ]]; then
210     COMMAND_ARR+=('-v' "$VERSION")
211   fi
212
213   for i; do
214     COMMAND_ARR+=("$i")
215   done
216
217   COMMAND_ARR+=("$PACKAGE")
218
219   if [[ "$DEBUG" != 0 ]]; then
220     echo
221     echo "Fpm command:"
222     echo "${COMMAND_ARR[@]}"
223     echo
224   fi
225
226   FPM_RESULTS=$("${COMMAND_ARR[@]}")
227   FPM_EXIT_CODE=$?
228
229   FPM_PACKAGE_NAME=''
230   if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\-.]*\.deb) ]]; then
231     FPM_PACKAGE_NAME=${BASH_REMATCH[1]}
232   fi
233
234   if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
235     EXITCODE=1
236     echo "Error: Unable to figure out package name from fpm results:\n $FPM_RESULTS"
237   else
238     if [[ ! $FPM_RESULTS =~ "File already exists" ]]; then
239       if [[ "$FPM_EXIT_CODE" != "0" ]]; then
240         echo "Error building debian package for $1:\n $FPM_RESULTS"
241       else
242         if [[ "$UPLOAD" != 0 ]]; then
243           scp -P2222 $FPM_PACKAGE_NAME $APTUSER@$APTSERVER:tmp/
244           CALL_FREIGHT=1
245         fi
246       fi
247     else
248       echo "Debian package $FPM_PACKAGE_NAME exists, not rebuilding"
249     fi
250   fi
251 }
252
253 if [[ ! -d "$WORKSPACE/debs" ]]; then
254   mkdir -p $WORKSPACE/debs
255 fi
256
257 # Arvados-src
258 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
259 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
260   mkdir "$WORKSPACE/src-build-dir"
261   cd "$WORKSPACE"
262   if [[ "$DEBUG" != 0 ]]; then
263     git clone https://github.com/curoverse/arvados.git src-build-dir
264   else
265     git clone -q https://github.com/curoverse/arvados.git src-build-dir
266   fi
267 fi
268
269 cd "$WORKSPACE/src-build-dir"
270 # just in case, check out master
271 if [[ "$DEBUG" != 0 ]]; then
272   git checkout master
273   git pull
274   # go into detached-head state
275   git checkout `git log --format=format:%h -n1 .`
276 else
277   git checkout -q master
278   git pull -q
279   # go into detached-head state
280   git checkout -q `git log --format=format:%h -n1 .`
281 fi
282
283 # Build arvados src deb package
284 cd $WORKSPACE/debs
285 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"
286
287 # clean up, check out master and step away from detached-head state
288 cd "$WORKSPACE/src-build-dir"
289 if [[ "$DEBUG" != 0 ]]; then
290   git checkout master
291 else
292   git checkout -q master
293 fi
294
295 # Keep
296 export GOPATH=$(mktemp -d)
297 mkdir -p "$GOPATH/src/git.curoverse.com"
298 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
299
300 # keepstore
301 go get "git.curoverse.com/arvados.git/services/keepstore"
302 cd $WORKSPACE/debs
303 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"
304
305 # keepproxy
306 go get "git.curoverse.com/arvados.git/services/keepproxy"
307 cd $WORKSPACE/debs
308 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"
309
310 # crunchstat
311 go get "git.curoverse.com/arvados.git/services/crunchstat"
312 cd $WORKSPACE/debs
313 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"
314
315 # The Python SDK
316 # Please resist the temptation to add --no-python-fix-name to the fpm call here
317 # (which would remove the python- prefix from the package name), because this
318 # package is a dependency of arvados-fuse, and fpm can not omit the python-
319 # prefix from only one of the dependencies of a package...  Maybe I could
320 # whip up a patch and send it upstream, but that will be for another day. Ward,
321 # 2014-05-15
322 cd $WORKSPACE/debs
323 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"
324
325 # The FUSE driver
326 # Please seem comment about --no-python-fix-name above; we stay consistent and do
327 # not omit the python- prefix first.
328 cd $WORKSPACE/debs
329 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"
330
331 # A few dependencies
332 build_and_scp_deb python-gflags
333 build_and_scp_deb pyvcf
334 build_and_scp_deb google-api-python-client
335 build_and_scp_deb httplib2
336 build_and_scp_deb ws4py
337 build_and_scp_deb virtualenv
338
339 # Finally, publish the packages, if necessary
340 if [[ "$UPLOAD" != 0 && "$CALL_FREIGHT" != 0 ]]; then
341   ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
342 else
343   if [[ "$UPLOAD" != 0 ]]; then
344     echo "No new packages generated. No freight run necessary."
345   fi
346 fi
347
348 # clean up temporary GOPATH
349 rm -rf "$GOPATH"
350
351 exit $EXITCODE