9881ded9637b8ac8d558e05a6183653b25e55bc8
[arvados.git] / jenkins / run-build-packages.sh
1 #!/bin/bash
2
3 EXITCODE=0
4 CALL_FREIGHT=0
5
6 APTUSER=$1
7 APTSERVER=$2
8
9 if [[ "$APTUSER" == '' ]]; then
10   echo "Syntax: $0 <aptuser> <aptserver>"
11   exit 1
12 fi
13
14 if [[ "$APTSERVER" == '' ]]; then
15   echo "Syntax: $0 <aptuser> <aptserver>"
16   exit 1
17 fi
18
19 # Sanity check
20 if ! [[ -n "$WORKSPACE" ]]; then
21   echo "WORKSPACE environment variable not set"
22   exit 1
23 fi
24
25 source /etc/profile.d/rvm.sh
26 echo $WORKSPACE
27
28 # Make all files world-readable -- jenkins runs with umask 027, and has checked
29 # out our git tree here
30 chmod o+r "$WORKSPACE" -R
31
32 # Now fix our umask to something better suited to building and publishing
33 # gems and packages
34 umask 0022
35
36 echo "umask is"
37 umask
38
39 # Build arvados GEM
40 echo "Build and publish ruby gem"
41 cd "$WORKSPACE"
42 cd sdk/ruby
43 # clean up old gems
44 rm -f arvados-*gem
45 gem build arvados.gemspec
46 # publish new gem
47 gem push arvados-*gem
48
49 # Build arvados-cli GEM
50 echo "Build and publish ruby gem"
51 cd "$WORKSPACE"
52 cd sdk/cli
53 # clean up old gems
54 rm -f arvados-cli*gem
55 gem build arvados-cli.gemspec
56 # publish new gem
57 gem push arvados-cli*gem
58
59 # Build arvados-python-client Python package
60 echo "Build and publish arvados-python-client package"
61 cd "$WORKSPACE"
62
63 GIT_HASH=`git log --format=format:%ct.%h -n1 .`
64
65 cd sdk/python
66
67 # We mess with this file below, reset it here
68 git checkout setup.py
69
70 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
71 python setup.py egg_info -b ".$GIT_HASH" sdist upload
72
73 cd ../../services/fuse
74
75 # We mess with this file below, reset it here
76 git checkout setup.py
77
78 # Make sure only to use sdist - that's the only format pip can deal with (sigh)
79 python setup.py egg_info -b ".$GIT_HASH" sdist upload
80
81 # Build debs for everything
82
83 # Build arvados src deb package
84
85 build_and_scp_deb () {
86   PACKAGE=$1
87   shift
88   PACKAGE_NAME=$1
89   shift
90   VENDOR=$1
91   shift
92   PACKAGE_TYPE=$1
93   shift
94   VERSION=$1
95   shift
96
97   if [[ "$PACKAGE_NAME" == "" ]]; then
98     PACKAGE_NAME=$PACKAGE
99   fi
100
101   if [[ "$PACKAGE_TYPE" == "" ]]; then
102     PACKAGE_TYPE='python'
103   fi
104
105   declare -a COMMAND_ARR=("fpm" "--maintainer=Ward Vandewege <ward@curoverse.com>" "-s" "$PACKAGE_TYPE" "-t" "deb")
106
107   if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then
108     COMMAND_ARR+=('-n' "$PACKAGE_NAME")
109   fi
110
111   if [[ "$VENDOR" != "" ]]; then
112     COMMAND_ARR+=('--vendor' "$VENDOR")
113   fi
114
115   if [[ "$VERSION" != "" ]]; then
116     COMMAND_ARR+=('-v' "$VERSION")
117   fi
118
119   for i; do
120     COMMAND_ARR+=("$i")
121   done
122
123   COMMAND_ARR+=("$PACKAGE")
124
125   FPM_RESULTS=$("${COMMAND_ARR[@]}")
126   FPM_EXIT_CODE=$?
127
128   FPM_PACKAGE_NAME=''
129   if [[ $FPM_RESULTS =~ ([A-Za-z0-9_\-.]*\.deb) ]]; then
130     FPM_PACKAGE_NAME=${BASH_REMATCH[1]}
131   fi
132
133   if [[ "$FPM_PACKAGE_NAME" == "" ]]; then
134     EXITCODE=1
135     echo "Error: Unabled figure out package name from fpm results:\n $FPM_RESULTS"
136   else
137     if [[ ! $FPM_RESULTS =~ "File already exists" ]]; then
138       if [[ "$FPM_EXIT_CODE" != "0" ]]; then
139         echo "Error building debian package for $1:\n $FPM_RESULTS"
140       else
141         scp -P2222 $FPM_PACKAGE_NAME $APTUSER@$APTSERVER:tmp/
142         CALL_FREIGHT=1
143       fi
144     else
145       echo "Debian package $FPM_PACKAGE_NAME exists, not rebuilding"
146     fi
147   fi
148 }
149
150 if [[ ! -d "$WORKSPACE/debs" ]]; then
151   mkdir -p $WORKSPACE/debs
152 fi
153
154 # Arvados-src
155 # We use $WORKSPACE/src-build-dir as the clean directory from which to build the src package
156 if [[ ! -d "$WORKSPACE/src-build-dir" ]]; then
157   mkdir "$WORKSPACE/src-build-dir"
158   cd "$WORKSPACE"
159   git clone https://github.com/curoverse/arvados.git src-build-dir
160 fi
161
162 cd "$WORKSPACE/src-build-dir"
163 # just in case, check out master
164 git checkout master
165 git pull
166
167 # go into detached-head state
168 git checkout `git log --format=format:%h -n1 .`
169
170 cd $WORKSPACE/debs
171 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"
172
173 # clean up, check out master and step away from detached-head state
174 cd "$WORKSPACE/src-build-dir"
175 git checkout master
176
177 # Keep
178 export GOPATH=$(mktemp -d)
179 mkdir -p "$GOPATH/src/git.curoverse.com"
180 ln -sfn "$WORKSPACE" "$GOPATH/src/git.curoverse.com/arvados.git"
181
182 # keepstore
183 go get "git.curoverse.com/arvados.git/services/keepstore"
184 cd $WORKSPACE/debs
185 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"
186
187 # keepproxy
188 go get "git.curoverse.com/arvados.git/services/keepproxy"
189 cd $WORKSPACE/debs
190 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"
191
192 # crunchstat
193 go get "git.curoverse.com/arvados.git/services/crunchstat"
194 cd $WORKSPACE/debs
195 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"
196
197 # The Python SDK
198 cd $WORKSPACE/sdk/python
199 sed -i'' -e "s:version='0.1':version='0.1.$GIT_HASH':" setup.py
200
201 cd $WORKSPACE/debs
202
203 # Please resist the temptation to add --no-python-fix-name to the fpm call here
204 # (which would remove the python- prefix from the package name), because this
205 # package is a dependency of arvados-fuse, and fpm can not omit the python-
206 # prefix from only one of the dependencies of a package...  Maybe I could
207 # whip up a patch and send it upstream, but that will be for another day. Ward,
208 # 2014-05-15
209 build_and_scp_deb $WORKSPACE/sdk/python python-arvados-python-client 'Curoverse, Inc.' 'python' "0.1.${GIT_HASH}" "--url=https://arvados.org" "--description=The Arvados Python SDK"
210
211 # The FUSE driver
212 cd $WORKSPACE/services/fuse
213 sed -i'' -e "s:version='0.1':version='0.1.$GIT_HASH':" setup.py
214
215 cd $WORKSPACE/debs
216
217 # Please seem comment about --no-python-fix-name above; we stay consistent and do
218 # not omit the python- prefix first.
219 build_and_scp_deb $WORKSPACE/services/fuse python-arvados-fuse 'Curoverse, Inc.' 'python' "0.1.${GIT_HASH}" "--url=https://arvados.org" "--description=The Keep FUSE driver"
220
221 # A few dependencies
222 build_and_scp_deb python-gflags
223 build_and_scp_deb pyvcf
224 build_and_scp_deb google-api-python-client
225 build_and_scp_deb httplib2
226 build_and_scp_deb ws4py
227 build_and_scp_deb virtualenv
228
229 # Finally, publish the packages, if necessary
230 if [[ "$CALL_FREIGHT" != "0" ]]; then
231   ssh -p2222 $APTUSER@$APTSERVER -t "cd tmp && ls -laF *deb && freight add *deb apt/wheezy && freight cache && rm -f *deb"
232 else
233   echo "No new packages generated. No freight run necessary."
234 fi
235
236 # clean up temporary GOPATH
237 rm -rf "$GOPATH"
238
239 exit $EXITCODE