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