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