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