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