2 REVISION=$(echo '$Revision$' | sed -e 's,\$,,g' -e 's,^\w*:\s,,' )
7 # default values, tunable with command-line options
8 DEFAULT_FCDISTRO=centos5
9 DEFAULT_PLDISTRO=planetlab
10 DEFAULT_PERSONALITY=linux32
11 DEFAULT_BASE="@DATE@--@PLDISTRO@-@FCDISTRO@-@PERSONALITY@"
12 DEFAULT_build_SVNPATH="http://svn.planet-lab.org/svn/build/trunk"
13 DEFAULT_TESTCONFIG="default"
16 # web publishing results
17 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
19 # default gpg path used in signing yum repo
20 DEFAULT_GPGPATH="/etc/planetlab"
21 # default email to use in gpg secring
22 DEFAULT_GPGUID="root@$( /bin/hostname )"
25 DEFAULT_TESTBUILDURL="http://build.onelab.eu/"
26 TESTBOXSSH=root@testbox.onelab.eu
28 # assuming vserver runs in UTC
29 DATE=$(date +'%Y.%m.%d')
31 # temporary - wrap a quick summary of suspicious stuff
32 # this is to focus on installation that go wrong
33 # use with care, a *lot* of other things can go bad as well
36 echo "******************** BEG SUMMARY"
39 # read a full log and tries to extract the interesting stuff
42 m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*|.*PROPFIND.*|.*Starting.*:runtest.*")
43 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
44 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
45 m_installing_end=re.compile('Installed:.*')
46 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
47 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
49 def summary (filename):
58 for line in f.xreadlines():
59 # first off : discard warnings related to doc
60 if m_installing_doc1.match(line):
61 (begin,end)=m_installing_doc1.match(line).groups()
63 if m_installing_doc2.match(line):
64 (begin,end)=m_installing_doc2.match(line).groups()
66 # unconditionnally show these lines
67 if m_show_line.match(line):
69 # an 'installing' line with messages afterwards : needs to be echoed
70 elif m_installing_err.match(line):
71 (installing,error)=m_installing_err.match(line).groups()
72 print '>>>',installing
75 # closing an 'installing' section
76 elif m_installing_end.match(line):
78 # any 'installing' line
79 elif m_installing_any.match(line):
81 installing=m_installing_any.match(line).group(1)
82 print '>>>',installing
84 # print lines when echo is true
86 if echo: print '>>>',line,
89 print 'Failed to analyze',filename
91 for arg in sys.argv[1:]:
94 echo "******************** END SUMMARY"
98 # Notify recipient of failure or success, manage various stamps
101 # early stage ? - let's not create /build/@PLDISTRO@
102 if [ ! -d ${WEBPATH} ] ; then
104 WEBLOG=/tmp/vbuild-early.log.txt
107 summary $LOG >> ${WEBLOG}
108 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 30k $WEBLOG) > ${WEBLOG}.ko
109 if [ -n "$MAILTO" ] ; then
111 echo "See full build log at ${LOG_URL}" ; \
112 echo "and tail version at ${LOG_URL}.ko" ; \
113 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
114 tail -c 30k ${WEBLOG} ) | mail -s "Failures with ${MAIL_SUBJECT}" $MAILTO
119 function success () {
121 # early stage ? - let's not create /build/@PLDISTRO@
122 if [ ! -d ${WEBPATH} ] ; then
124 WEBLOG=/tmp/vbuild-early-$(date +%Y-%m-%d).log.txt
127 summary $LOG >> ${WEBLOG}
128 if [ -n "$DO_TEST" ] ; then
130 echo "Successfully built and tested" ; \
131 echo "See full build log at ${LOG_URL}" ; \
132 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
134 rm -f ${WEBLOG}.pkg-ok ${WEBLOG}.ko
137 echo "Successful package-only build, no test requested" ; \
138 echo "See full build log at ${LOG_URL}" ; \
142 if [ -n "$MAILTO" ] ; then
144 echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ; \
145 echo "See full build log at ${LOG_URL}" ; \
146 [ -n "$DO_TEST" ] && echo "See complete set of testlogs at ${TESTLOGS_URL}" ) \
147 | mail -s "Success with ${MAIL_SUBJECT}" $MAILTO
152 # run in the vserver - do not manage success/failure, will be done from the root ctx
157 echo -n "============================== Starting $COMMAND:build on "
163 echo "Running make IN $(pwd)"
165 # stuff our own variable settings
166 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
167 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
168 MAKEVARS=("build-SVNPATH=${build_SVNPATH}" "${MAKEVARS[@]}")
169 MAKEVARS=("PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
170 MAKEVARS=("MAILTO=${MAILTO}" "${MAKEVARS[@]}")
172 MAKEVARS=("BASE=${BASE}" "${MAKEVARS[@]}")
175 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
176 # store tests_svnpath
177 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true tests_svnpath
179 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
181 make -C /build $DRY_RUN "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
185 # this was formerly run in the myplc-devel chroot but now is run in the root context,
186 # this is so that the .ssh config gets done manually, and once and for all
187 function runtest () {
192 echo -n "============================== Starting $COMMAND:runtest on $(date)"
194 # where to find TESTS_SVNPATH
195 stamp=/vservers/$BASE/build/tests_svnpath
196 if [ ! -f $stamp ] ; then
197 echo "$COMMAND: Cannot figure TESTS_SVNPATH from missing $stamp"
201 TESTS_SVNPATH=$(cat $stamp)
202 # xxx - Thierry - need to rework the test framework in tests/system so it can work
203 # with the entire tests/ module checked out, rather than only tests/system/
204 # ugly workaround for now
205 TESTS_SYSTEM_SVNPATH=${TESTS_SVNPATH}/system
207 ### the URL to the RPMS/<arch> location
209 for a in i386 x86_64; do
210 archdir=/vservers/$BASE/build/RPMS/$a
211 if [ -d $archdir ] ; then
212 url=$(echo $archdir | sed -e "s,/vservers/$BASE/build,${TESTBUILDURL}${PLDISTRO}/${BASE},")
217 if [ -z "$url" ] ; then
218 echo "$COMMAND: Cannot locate arch URL for testing"
223 # test directory name on test box
226 ssh -n ${TESTBOXSSH} rm -rf ${testdir}
228 ssh -n ${TESTBOXSSH} svn co ${TESTS_SYSTEM_SVNPATH} ${testdir}
229 # check out the entire tests/ module (with system/ duplicated) as a subdir - see xxx above
230 ssh -n ${TESTBOXSSH} svn co ${TESTS_SVNPATH} ${testdir}/tests
231 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
233 for config in ${TESTCONFIG} ; do
234 configs="$configs --config $config"
236 test_env="-p $PERSONALITY -d $PLDISTRO -f $FCDISTRO"
238 # need to proceed despite of set -e
240 ssh 2>&1 -n ${TESTBOXSSH} ${testdir}/runtest --build ${build_SVNPATH} --url ${url} $configs $test_env --all || success=
242 # gather logs in the vserver
243 mkdir -p /vservers/$BASE/build/testlogs
244 ssh 2>&1 -n ${TESTBOXSSH} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
245 # push them to the build web
246 chmod -R a+r /vservers/$BASE/build/testlogs/
247 rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
249 if [ -z "$success" ] ; then
253 echo -n "============================== End $COMMAND:runtest on $(date)"
256 function in_root_context () {
257 rpm -q util-vserver > /dev/null
260 # this part won't work with a remote(rsync) WEBPATH
261 function sign_node_packages () {
263 echo "Signing node packages"
267 repository=$WEBPATH/$BASE/RPMS/
268 # the rpms that need signing
270 # and the corresponding stamps
273 for package in $(find $repository/ -name '*.rpm') ; do
274 stamp=$repository/signed-stamps/$(basename $package).signed
275 # If package is newer than signature stamp
276 if [ $package -nt $stamp ] ; then
277 new_rpms="$new_rpms $package"
278 new_stamps="$new_stamps $stamp"
280 # Or than createrepo database
281 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
284 if [ -n "$new_rpms" ] ; then
285 # Create a stamp once the package gets signed
286 mkdir $repository/signed-stamps 2> /dev/null
288 # Sign RPMS. setsid detaches rpm from the terminal,
289 # allowing the (hopefully blank) GPG password to be
290 # entered from stdin instead of /dev/tty.
292 --define "_signature gpg" \
293 --define "_gpg_path $GPGPATH" \
294 --define "_gpg_name $GPGUID" \
295 --resign $new_rpms && touch $new_stamps
298 # Update repository index / yum metadata.
299 if [ -n "$need_createrepo" ] ; then
300 echo "Indexing node packages after signing"
301 if [ -f $repository/yumgroups.xml ] ; then
302 createrepo --quiet -g yumgroups.xml $repository
304 createrepo --quiet $repository
309 function show_env () {
311 echo FCDISTRO=$FCDISTRO
312 echo PLDISTRO=$PLDISTRO
313 echo PERSONALITY=$PERSONALITY
315 echo build_SVNPATH=$build_SVNPATH
316 echo MAKEVARS="${MAKEVARS[@]}"
317 echo DRY_RUN="$DRY_RUN"
318 echo PLDISTROTAGS="$PLDISTROTAGS"
319 # this does not help, it's not yet set when we run show_env
320 #echo WEBPATH="$WEBPATH"
321 echo TESTBUILDURL="$TESTBUILDURL"
322 if in_root_context ; then
323 echo PLDISTROTAGS="$PLDISTROTAGS"
325 if [ -f /build/$PLDISTROTAGS ] ; then
326 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
327 cat /build/$PLDISTROTAGS
328 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
330 echo "XXXXXXXXXXXXXXXXXXXX Cannot find tags definition file /build/$PLDISTROTAGS, assuming remote pldistro"
337 echo "Usage: $COMMAND [option] [var=value...] make-targets"
338 echo "This is $REVISION"
339 echo "Supported options"
340 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
341 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
342 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
343 echo " -b base - defaults to $DEFAULT_BASE"
344 echo " @NAME@ replaced as appropriate"
345 echo " -o base: (overwrite) do not re-create vserver, re-use base instead"
346 echo " the -f/-d/-t/-s/-p/-m options are uneffective in this case"
347 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
348 echo " -s svnpath - where to fetch the build module - defaults to $DEFAULT_build_SVNPATH"
349 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
350 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
351 echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL"
352 echo " -y sign yum repo in webpath"
353 echo " -g path to gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
354 echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
355 echo " -m mailto - no default"
356 echo " -B : run build only"
357 echo " -T : run test only"
358 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
359 echo " -v : be verbose"
360 echo " -7 : uses weekday-@FCDISTRO@ as base"
361 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
376 while getopts "f:d:p:b:o:t:s:x:c:w:W:g:u:m:BTnyv7i:" opt ; do
378 f) FCDISTRO=$OPTARG ;;
379 d) PLDISTRO=$OPTARG ;;
380 p) PERSONALITY=$OPTARG ;;
382 o) OVERBASE=$OPTARG ;;
383 t) PLDISTROTAGS=$OPTARG ;;
384 s) build_SVNPATH=$OPTARG ;;
385 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
386 w) WEBPATH=$OPTARG ;;
387 W) TESTBUILDURL=$OPTARG ;;
388 y) SIGNYUMREPO=true ;;
389 g) GPGPATH=$OPTARG ;;
396 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
402 # preserve options for passing them again later, together with expanded base
404 toshift=$(($OPTIND - 1))
405 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
407 # allow var=value stuff;
408 for target in "$@" ; do
409 # check if contains '='
410 target1=$(echo $target | sed -e s,=,,)
411 if [ "$target" = "$target1" ] ; then
412 MAKETARGETS=(${MAKETARGETS[@]} "$target")
414 MAKEVARS=(${MAKEVARS[@]} "$target")
419 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
420 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
421 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
422 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
423 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
424 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
425 [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
426 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
427 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
428 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
429 [ -z "$build_SVNPATH" ] && build_SVNPATH="$DEFAULT_build_SVNPATH"
430 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
432 [ -n "$DRY_RUN" ] && MAILTO=""
434 if [ -n "$OVERBASE" ] ; then
435 sedargs="-e s,@DATE@,${DATE},g"
436 BASE=$(echo ${OVERBASE} | sed $sedargs)
438 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
439 BASE=$(echo ${BASE} | sed $sedargs)
442 ### elaborate mail subject
443 if [ -n "$DO_BUILD" -a -n "$DO_TEST" ] ; then
444 MAIL_SUBJECT="complete"
445 elif [ -n "$DO_BUILD" ] ; then
446 MAIL_SUBJECT="package-only"
447 elif [ -n "$DO_TEST" ] ; then
448 MAIL_SUBJECT="test-only"
450 if [ -n "$OVERBASE" ] ; then
451 MAIL_SUBJECT="$MAIL_SUBJECT incremental run on"
453 MAIL_SUBJECT="$MAIL_SUBJECT fresh build"
455 MAIL_SUBJECT="$MAIL_SUBJECT ${BASE}"
457 if ! in_root_context ; then
459 echo "==================== Within vserver BEG $(date)"
461 echo "==================== Within vserver END $(date)"
465 # we run in the root context :
466 # (*) create or check for the vserver to use
467 # (*) copy this command in the vserver
470 if [ -n "$OVERBASE" ] ; then
471 ### Re-use a vserver (finish an unfinished build..)
472 if [ ! -d /vservers/${BASE} ] ; then
473 echo $COMMAND : cannot find vserver $BASE
476 # manage LOG - beware it might be a symlink so nuke it first
477 LOG=/vservers/${BASE}.log.txt
481 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
482 # start in case e.g. we just rebooted
483 vserver ${BASE} start || :
485 vserver ${BASE} exec svn update /build
486 # get environment from the first run
487 FCDISTRO=$(vserver ${BASE} exec /build/getdistroname.sh)
489 PLDISTRO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTRO)
490 PLDISTROTAGS=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTROTAGS)
491 build_SVNPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +build-SVNPATH)
492 PERSONALITY=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PERSONALITY)
493 MAILTO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +MAILTO)
496 # create vserver: check it does not exist yet
498 while [ -d /vservers/${BASE}${i} ] ; do
499 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
500 [ -z ${i} ] && BASE=${BASE}-n
502 if [ $i -gt 100 ] ; then
503 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
509 # manage LOG - beware it might be a symlink so nuke it first
510 LOG=/vservers/${BASE}.log.txt
514 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
517 ### extract the whole build - much simpler
518 tmpdir=/tmp/$COMMAND-$$
519 svn export $build_SVNPATH $tmpdir
522 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
526 # Extract build again - in the vserver
527 vserver ${BASE} exec svn checkout ${build_SVNPATH} /build
529 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
531 # The log inside the vserver contains everything
532 LOG2=/vservers/${BASE}/log.txt
533 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
535 echo "==================== END VSERVER Transcript of vserver creation" ; \
536 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
537 ### not too nice : nuke the former log, symlink it to the new one
538 rm $LOG; ln -s $LOG2 $LOG
543 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
544 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
547 # where to store the log for web access
548 WEBLOG=${WEBPATH}/${BASE}.log.txt
549 # compute the log URL - inserted in the mail messages for convenience
550 LOG_URL=$(echo ${WEBLOG} | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
551 TESTLOGS_URL=$(echo ${WEBPATH}/${BASE}/testlogs | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
553 if [ -n "$DO_BUILD" ] ; then
555 cp $COMMANDPATH /vservers/${BASE}/build/
557 # invoke this command in the vserver for building (-T)
558 vserver ${BASE} exec chmod +x /build/$COMMAND
559 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
562 # publish to the web so runtest can find them
563 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
564 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
565 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
566 # publish myplc-release
567 rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
569 # create yum repo and sign packages.
570 if [ -n "$SIGNYUMREPO" ] ; then
574 if [ -n "$DO_TEST" ] ; then