-
Notifications
You must be signed in to change notification settings - Fork 2
/
buildfarm.sh
executable file
·286 lines (225 loc) · 7.54 KB
/
buildfarm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/bash
TIMEOUT=7000
# Do docker build?
DOCKER_BUILD=1
#NO_CACHE="--no-cache"
NO_CACHE=""
# day of the week to build docker images for git pull (0 means Sunday)
BUILD_DAY=0
# Build RPMs and test RPMs
BUILD_RPM=0
# Send mail?
SEND_MAIL=1
# test_error
ERROR=0
# mail address
REPLYTO=$MAILTO
SUBJECT="Pgpool-II buildfarm results $1"
# directories
SRCDIR=/var/buildfarm
VOLUM=$SRCDIR/volum-$1
GITROOT=$SRCDIR/docker-pgpool-II-regression
LOGDIR=$SRCDIR/log-$1
WORKDIR=$GITROOT/work
# backup regression test log to other host
REGRESSIONLOGDIR=regression-log-$1
REGRESSIONLOG=$SRCDIR/$REGRESSIONLOGDIR
REGRESSIONLOGFILE=`date +%Y%m%d`-buildfarm-$1.tar.gz
LOG_BACKUP=log_backup_host
LOG_BACKUP_DIR=log_backup_dir
TMPLOG=$LOGDIR/tmp.log
RESULT=$LOGDIR/result
SUMMARY=$LOGDIR/summary
# sed command
COLOR='\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]'
NOCOLOR='\x1B\(B'
SEDPTN="s/($COLOR|$NOCOLOR)//g"
SED="sed -r $SEDPTN"
# targets
OS=$1
PGSQL_LIST=(14 13 12 11 10)
BRANCH_LIST=(master V4_3_STABLE V4_2_STABLE V4_1_STABLE V4_0_STABLE V3_7_STABLE)
# functions
## get tag for docker image of specified branch
function getTag()
{
local os=`echo $1 | tr [A-Z] [a-z]`
echo buildfarm_$os
}
function getName()
{
OS=$1
BRANCH=$2
PGSQL_VERSION=$3
local os=`echo $OS | tr [A-Z] [a-z]`
local POOLVER=`getPoolVer $BRANCH`
local PGVER=`echo $PGSQL_VERSION | tr -d . | cut -c 1-2`
echo "${os}_${POOLVER}_pg${PGVER}"
}
## get path to dockerfile directory of specified branch
function getDockerfileDir()
{
local OS=$1
echo "${GITROOT}/${OS}"
}
## get pgpool version number (e.g. 34) for tag and dockerfile
function getPoolVer()
{
local BRANCH=$1
case $BRANCH in
"master" )
echo master ;;
*)
echo $BRANCH | tr -d V_STABLE ;;
esac
}
## print environment info
function printEnvInfo()
{
local TAG=$1
local PGSQL=$2
local PGVER_OF_IMAGE=`docker run --rm $TAG /usr/pgsql-${PGSQL}/bin/postmaster --version 2>/dev/null | sed "s/[^0-9.]//g"`
local OS_OF_IMAGE=`docker run --rm $TAG cat /etc/redhat-release 2>/dev/null`
local KERNEL_OF_IMAGE=`docker run --rm $TAG uname -r 2>/dev/null`
echo "PostgreSQL: $PGVER_OF_IMAGE"
echo "OS: $OS_OF_IMAGE ($KERNEL_OF_IMAGE)"
}
rm -rf $VOLUM/*
if [ -e $LOGDIR ]; then
rm -rf $LOGDIR;
fi
mkdir $LOGDIR
rm -rf ${REGRESSIONLOG}/*
if [ $BUILD_RPM -eq 1 ]; then
echo "pgpool-II buildfarm (Test RPMs)" >> $RESULT
else
echo "pgpool-II buildfarm (Test source code)" >> $RESULT
fi
echo "=========================================================================" >> $SUMMARY
echo "start: " `LANG=en date`>> $RESULT
echo >> $RESULT
TAG=`getTag $OS`
# building docker image
if [ $DOCKER_BUILD -eq 1 -o `date '+%w'` = $BUILD_DAY ]; then
echo -n "** building docker image ..." >> $RESULT
BUILD_LOG=$LOGDIR/$OS-build.log
cd $GITROOT
DOCKERFILE_DIR=`getDockerfileDir $OS`
DOCKERFILE_NAME=Dockerfile.$OS
docker build -t $TAG -f $DOCKERFILE_NAME $NO_CACHE . >> $TMPLOG 2>&1
RST=$?
cat $TMPLOG | col -xb | $SED > $BUILD_LOG
if [ $RST -ne 0 ]; then
echo failure. >> $RESULT
echo >> $RESULT
fi
echo success. >> $RESULT
echo >> $RESULT
fi
for BRANCH in ${BRANCH_LIST[@]}
do
for PGSQL in ${PGSQL_LIST[@]}
do
NAME=`getName $OS $BRANCH $PGSQL`
LOG=$LOGDIR/${OS}_${BRANCH}_${PGSQL}.log
echo "* Target branch: $BRANCH" >> $RESULT
echo >> $RESULT
# print environment information
printEnvInfo $TAG $PGSQL >> $RESULT
echo >> $RESULT
# Regression test
echo "** Regression test" >> $RESULT
echo >> $RESULT
docker run \
-e OS=$OS \
-e PGPOOL_BRANCH=$BRANCH \
-e PGSQL_VERSION=$PGSQL \
-e BUILD_RPM=$BUILD_RPM \
--privileged -v $VOLUM:/var/volum --name $NAME -d $TAG > $TMPLOG 2>&1
timeout $TIMEOUT docker exec $NAME /tmp/start.sh >> $TMPLOG 2>&1
if [ ! $? -eq 0 ]; then
echo "buildfarm timed out" >> $TMPLOG
else
docker kill $NAME
docker rm $NAME
fi
cat $TMPLOG | col -xb | $SED > $LOG
CONFIGURE_ERROR=`awk '/^configure: error/' $LOG`
if [ ! -z "$CONFIGURE_ERROR" ]; then
echo "Error" >> $RESULT
echo "$CONFIGURE_ERROR" >> $RESULT
echo >> $RESULT
fi
MAKE_ERROR=`awk '/^(make: \*\*\*|make install failed)/' $LOG`
if [ ! -z "$MAKE_ERROR" ]; then
echo "Error" >> $RESULT
echo "$MAKE_ERROR" >> $RESULT
echo >> $RESULT
else
echo "make...ok" >> $RESULT
fi
TEST_ERROR=`awk '/\.failed\.$/' $LOG`
TEST_TIMEOUT=`awk '/(\.timeout\.|buildfarm timed out)$/' $LOG`
if [ ! -z "$TEST_ERROR" -o ! -z "$TEST_TIMEOUT" -o ! -z "$MAKE_ERROR" -o ! -z "$CONFIGURE_ERROR" ]; then
echo "* $BRANCH PostgreSQL $PGSQL $OS" >> $SUMMARY
mkdir -p ${REGRESSIONLOG}/$OS/$PGSQL/$BRANCH/
if [ ! -z "$TEST_ERROR" ]; then
echo "$TEST_ERROR" >> $SUMMARY
elif [ ! -z "$TEST_TIMEOUT" ]; then
echo "$TEST_TIMEOUT" >> $SUMMARY
elif [ ! -z "$MAKE_ERROR" ]; then
echo "$MAKE_ERROR" >> $SUMMARY
elif [ ! -z "$CONFIGURE_ERROR" ]; then
echo "$CONFIGURE_ERROR" >> $SUMMARY
fi
echo >> $SUMMARY
ERROR=1
# move failed regression logs
echo "copy failed test logs to regression-log" >> $TMPLOG
cp -r $VOLUM/$OS/$PGSQL/$BRANCH/src/test/regression/log ${REGRESSIONLOG}/$OS/$PGSQL/$BRANCH/ >> $TMPLOG 2>&1
cp $LOG ${REGRESSIONLOG}/$OS/$PGSQL/$BRANCH/ >> $TMPLOG 2>&1
grep testing $TMPLOG | while read s; do
if echo $s | grep -qEv '\.\.\.ok\.$'; then
test_dir=`echo $s | cut -d ' ' -f 2 | cut -d . -f 1`
#echo "copy $VOLUM/$OS/$PGSQL/$BRANCH/src/test/regression/tests/${test_dir}.* to regression-log" >> $LOG
if [ $BRANCH = V3_3_STABLE ]; then
cp -r $VOLUM/$OS/$PGSQL/$BRANCH/test/regression/tests/${test_dir}.* ${REGRESSIONLOG}/$OS/$PGSQL/$BRANCH/ >> $LOG 2>&1
else
cp -r $VOLUM/$OS/$PGSQL/$BRANCH/src/test/regression/tests/${test_dir}.* ${REGRESSIONLOG}/$OS/$PGSQL/$BRANCH/ >> $LOG 2>&1
fi
fi
done
fi
# delete volume
rm -rf $VOLUM/$OS/$PGSQL/$BRANCH
awk '/^testing/,EOF' $LOG >> $RESULT
echo >> $RESULT
done
done
if [ $ERROR -eq 0 ]; then
echo "All tests succeeded." >> $SUMMARY
fi
echo "=========================================================================" >> $SUMMARY
echo >> $SUMMARY
echo "end: " `LANG=en date`>> $RESULT
echo >> $RESULT
# move regression test logs to log_backup_host
cd $SRCDIR
tar zcvf ${REGRESSIONLOGFILE} ${REGRESSIONLOGDIR} >> $LOG 2>&1
if [ -e ${REGRESSIONLOGFILE} ]; then
if [ `stat -c %s ${REGRESSIONLOGFILE}` -lt 600000000 ]; then
scp ${REGRESSIONLOGFILE} ${LOG_BACKUP}:${LOG_BACKUP_DIR}
fi
fi
if [ ! $? -eq 0 ]; then
echo "moving regression result to log_backup_host ... failed" >> $RESULT
else
echo "moving regression result to log_backup_host ... OK" >> $RESULT
fi
rm -f ${REGRESSIONLOGFILE}
rm -rf ${REGRESSIONLOG}/*
if [ -n "$SEND_MAIL" ] && [ "$SEND_MAIL" -eq 1 ]; then
cat $SUMMARY $RESULT | mail -s "$SUBJECT" -r $FROM $MAILTO
fi