Build crunchstat package.
[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_and_scp_deb () {
67   PACKAGE=$1
68   PACKAGE_NAME=$2
69   # Put spaces in $3 and you will regret it. Despite the use of arrays below.
70   # Because, bash sucks.
71   VENDOR=${3// /_}
72   PACKAGE_TYPE=$4
73   EXTRA_ARGUMENTS=$5
74
75   if [[ "$PACKAGE_NAME" == "" ]]; then
76     PACKAGE_NAME=$PACKAGE
77   fi
78
79   if [[ "$PACKAGE_TYPE" == "" ]]; then
80     PACKAGE_TYPE='python'
81   fi
82
83   COMMAND_ARR=("fpm" "-s" "$PACKAGE_TYPE" "-t" "deb")
84
85   if [[ "$PACKAGE_NAME" != "$PACKAGE" ]]; then
86     COMMAND_ARR+=('-n' "$PACKAGE_NAME")
87   fi
88
89   if [[ "$VENDOR" != "" ]]; then
90     COMMAND_ARR+=('--vendor' "$VENDOR")
91   fi
92   for a in $EXTRA_ARGUMENTS; do
93     COMMAND_ARR+=("$a")
94   done
95
96   COMMAND_ARR+=("$PACKAGE")
97
98   FPM_RESULTS=$(${COMMAND_ARR[@]})
99   FPM_EXIT_CODE=$?
100   echo ${COMMAND_ARR[@]}
101   if [[ ! $FPM_RESULTS =~ "File already exists" ]]; then
102     if [[ "$FPM_EXIT_CODE" != "0" ]]; then
103       echo "Error building debian package for $1:\n $FPM_RESULTS"
104     else
105       scp -P2222 $PACKAGE_NAME*.deb $APTUSER@$APTSERVER:tmp/
106       CALL_PRM=1
107     fi
108   else
109     echo "Debian package for $1 exists, not rebuilding"
110   fi
111 }
112
113 if [[ ! -d "$WORKSPACE/debs" ]]; then
114   mkdir -p $WORKSPACE/debs
115 fi
116
117 # Make sure our destination directory on $APTSERVER exists - prm can delete it when invoked improperly
118 ssh -p2222 $APTUSER@$APTSERVER mkdir tmp
119
120 # Keep
121 cd $WORKSPACE/services/keep
122 ./go.sh install keep
123 cd $WORKSPACE/debs
124 build_and_scp_deb $WORKSPACE/services/keep/bin/keep=/usr/bin/keep keep 'Curoverse, Inc.' 'dir' "-v 0.1.$GIT_HASH"
125
126 # Keep proxy
127
128 # First build the keepclient library
129 cd $WORKSPACE/sdk/go
130 ./go.sh install arvados.org/keepclient
131
132 # Then keepproxy
133 cd $WORKSPACE/services/keep
134 ./go.sh install arvados.org/keepproxy
135 cd $WORKSPACE/debs
136 build_and_scp_deb $WORKSPACE/services/keep/bin/keepproxy=/usr/bin/keepproxy keepproxy 'Curoverse, Inc.' 'dir' "-v 0.1.$GIT_HASH"
137
138 # The crunchstat wrapper
139 cd $WORKSPACE/services/crunch/crunchstat
140 ./go.sh install arvados.org/crunchstat
141 cd $WORKSPACE/debs
142 build_and_scp_deb $WORKSPACE/services/crunch/crunchstat/bin/crunchstat=/usr/bin/crunchstat crunchstat 'Curoverse, Inc.' 'dir' "-v 0.1.$GIT_HASH"
143
144 # The Python SDK
145 cd $WORKSPACE/sdk/python
146 sed -i'' -e "s:version='0.1':version='0.1.$GIT_HASH':" setup.py
147
148 cd $WORKSPACE/debs
149
150 # Please resist the temptation to add --no-python-fix-name to the fpm call here
151 # (which would remove the python- prefix from the package name), because this
152 # package is a dependency of arvados-fuse, and fpm can not omit the python-
153 # prefix from only one of the dependencies of a package...  Maybe I could
154 # whip up a patch and send it upstream, but that will be for another day. Ward,
155 # 2014-05-15
156 build_and_scp_deb $WORKSPACE/sdk/python python-arvados-python-client 'Curoverse, Inc.' 'python' "-v 0.1.${GIT_HASH}"
157
158 # The FUSE driver
159 cd $WORKSPACE/services/fuse
160 sed -i'' -e "s:version='0.1':version='0.1.$GIT_HASH':" setup.py
161
162
163 cd $WORKSPACE/debs
164
165 # Please seem comment about --no-python-fix-name above; we stay consistent and do
166 # not omit the python- prefix first.
167 build_and_scp_deb $WORKSPACE/services/fuse python-arvados-fuse 'Curoverse, Inc.' 'python' "-v 0.1.${GIT_HASH}"
168
169 # A few dependencies
170 build_and_scp_deb python-gflags
171 build_and_scp_deb pyvcf
172 build_and_scp_deb google-api-python-client
173 build_and_scp_deb httplib2
174 build_and_scp_deb ws4py
175 build_and_scp_deb virtualenv
176
177 # Finally, publish the packages, if necessary
178 if [[ "$CALL_PRM" != "0" ]]; then
179   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"
180 else
181   echo "No new packages generated. No PRM run necessary."
182 fi
183