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"
15 # default gpg path used in signing yum repo
16 DEFAULT_GPGPATH="/etc/planetlab"
17 # default email to use in gpg secring
18 DEFAULT_GPGUID="root@$( /bin/hostname )"
20 # web publishing results
21 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
25 y=$(hostname|sed -e s,inria,,)
27 if [ "$x" != "$y" ] ; then
28 DEFAULT_TESTBUILDURL="http://build.onelab.eu/"
29 DEFAULT_TESTMASTER="testmaster.onelab.eu"
30 DEFAULT_TESTCONFIG="1default"
32 DEFAULT_TESTBUILDURL="http://build.planet-lab.org/"
33 ### xxx change as appropriate
34 DEFAULT_TESTMASTER="p-testmaster.onelab.eu"
35 DEFAULT_TESTCONFIG="pdefault"
39 # assuming vserver runs in UTC
40 DATE=$(date +'%Y.%m.%d')
42 # temporary - wrap a quick summary of suspicious stuff
43 # this is to focus on installation that go wrong
44 # use with care, a *lot* of other things can go bad as well
47 echo "******************** BEG SUMMARY"
50 # read a full log and tries to extract the interesting stuff
53 m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*|.*PROPFIND.*|.*Starting.*:runtest.*")
54 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
55 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
56 m_installing_end=re.compile('Installed:.*')
57 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
58 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
60 def summary (filename):
69 for line in f.xreadlines():
70 # first off : discard warnings related to doc
71 if m_installing_doc1.match(line):
72 (begin,end)=m_installing_doc1.match(line).groups()
74 if m_installing_doc2.match(line):
75 (begin,end)=m_installing_doc2.match(line).groups()
77 # unconditionnally show these lines
78 if m_show_line.match(line):
80 # an 'installing' line with messages afterwards : needs to be echoed
81 elif m_installing_err.match(line):
82 (installing,error)=m_installing_err.match(line).groups()
83 print '>>>',installing
86 # closing an 'installing' section
87 elif m_installing_end.match(line):
89 # any 'installing' line
90 elif m_installing_any.match(line):
92 installing=m_installing_any.match(line).group(1)
93 print '>>>',installing
95 # print lines when echo is true
97 if echo: print '>>>',line,
100 print 'Failed to analyze',filename
102 for arg in sys.argv[1:]:
105 echo "******************** END SUMMARY"
109 # Notify recipient of failure or success, manage various stamps
112 # early stage ? - let's not create /build/@PLDISTRO@
113 if [ ! -d ${WEBPATH} ] ; then
115 WEBLOG=/tmp/vbuild-early.log.txt
118 summary $LOG >> ${WEBLOG}
119 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 30k $WEBLOG) > ${WEBLOG}.ko
120 if [ -n "$MAILTO" ] ; then
122 echo "See full build log at ${LOG_URL}" ; \
123 echo "and tail version at ${LOG_URL}.ko" ; \
124 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
125 tail -c 30k ${WEBLOG} ) | mail -s "Failures with ${MAIL_SUBJECT} ${BASE}" $MAILTO
130 function success () {
132 # early stage ? - let's not create /build/@PLDISTRO@
133 if [ ! -d ${WEBPATH} ] ; then
135 WEBLOG=/tmp/vbuild-early-$(date +%Y-%m-%d).log.txt
138 summary $LOG >> ${WEBLOG}
139 if [ -n "$DO_TEST" ] ; then
141 echo "Successfully built and tested" ; \
142 echo "See full build log at ${LOG_URL}" ; \
143 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
145 rm -f ${WEBLOG}.pkg-ok ${WEBLOG}.ko
148 echo "Successful package-only build, no test requested" ; \
149 echo "See full build log at ${LOG_URL}" ; \
153 if [ -n "$MAILTO" ] ; then
155 echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ; \
156 echo "See full build log at ${LOG_URL}" ; \
157 [ -n "$DO_TEST" ] && echo "See complete set of testlogs at ${TESTLOGS_URL}" ) \
158 | mail -s "Success with ${MAIL_SUBJECT} ${BASE}" $MAILTO
163 # run in the vserver - do not manage success/failure, will be done from the root ctx
168 echo -n "============================== Starting $COMMAND:build on "
174 echo "Running make IN $(pwd)"
176 # stuff our own variable settings
177 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
178 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
179 MAKEVARS=("build-SVNPATH=${build_SVNPATH}" "${MAKEVARS[@]}")
180 MAKEVARS=("PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
181 MAKEVARS=("MAILTO=${MAILTO}" "${MAKEVARS[@]}")
183 MAKEVARS=("BASE=${BASE}" "${MAKEVARS[@]}")
186 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
187 # store tests_svnpath
188 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true tests_svnpath
190 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
192 make -C /build $DRY_RUN "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
196 # this was formerly run in the myplc-devel chroot but now is run in the root context,
197 # this is so that the .ssh config gets done manually, and once and for all
198 function runtest () {
203 echo -n "============================== Starting $COMMAND:runtest on $(date)"
205 # where to find TESTS_SVNPATH
206 stamp=/vservers/$BASE/build/tests_svnpath
207 if [ ! -f $stamp ] ; then
208 echo "$COMMAND: Cannot figure TESTS_SVNPATH from missing $stamp"
212 TESTS_SVNPATH=$(cat $stamp)
213 # xxx - Thierry - need to rework the test framework in tests/system so it can work
214 # with the entire tests/ module checked out, rather than only tests/system/
215 # ugly workaround for now
216 TESTS_SYSTEM_SVNPATH=${TESTS_SVNPATH}/system
218 ### the URL to the RPMS/<arch> location
220 for a in i386 x86_64; do
221 archdir=/vservers/$BASE/build/RPMS/$a
222 if [ -d $archdir ] ; then
223 url=$(echo $archdir | sed -e "s,/vservers/$BASE/build,${TESTBUILDURL}${PLDISTRO}/${BASE},")
228 if [ -z "$url" ] ; then
229 echo "$COMMAND: Cannot locate arch URL for testing"
234 testmaster_ssh="root@${TESTMASTER}"
236 # test directory name on test box
239 ssh -n ${testmaster_ssh} rm -rf ${testdir}
241 ssh -n ${testmaster_ssh} svn co ${TESTS_SYSTEM_SVNPATH} ${testdir}
242 # check out the entire tests/ module (with system/ duplicated) as a subdir - see xxx above
243 ssh -n ${testmaster_ssh} svn co ${TESTS_SVNPATH} ${testdir}/tests
244 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
246 for config in ${TESTCONFIG} ; do
247 configs="$configs --config $config"
249 test_env="-p $PERSONALITY -d $PLDISTRO -f $FCDISTRO"
251 # need to proceed despite of set -e
253 ssh 2>&1 -n ${testmaster_ssh} ${testdir}/runtest --build ${build_SVNPATH} --url ${url} $configs $test_env --all || success=
255 # gather logs in the vserver
256 mkdir -p /vservers/$BASE/build/testlogs
257 ssh 2>&1 -n ${testmaster_ssh} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
258 # push them to the build web
259 chmod -R a+r /vservers/$BASE/build/testlogs/
260 rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
262 if [ -z "$success" ] ; then
266 echo -n "============================== End $COMMAND:runtest on $(date)"
269 function in_root_context () {
270 rpm -q util-vserver > /dev/null
273 # this part won't work with a remote(rsync) WEBPATH
274 function sign_node_packages () {
276 echo "Signing node packages"
280 repository=$WEBPATH/$BASE/RPMS/
281 # the rpms that need signing
283 # and the corresponding stamps
286 for package in $(find $repository/ -name '*.rpm') ; do
287 stamp=$repository/signed-stamps/$(basename $package).signed
288 # If package is newer than signature stamp
289 if [ $package -nt $stamp ] ; then
290 new_rpms="$new_rpms $package"
291 new_stamps="$new_stamps $stamp"
293 # Or than createrepo database
294 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
297 if [ -n "$new_rpms" ] ; then
298 # Create a stamp once the package gets signed
299 mkdir $repository/signed-stamps 2> /dev/null
301 # Sign RPMS. setsid detaches rpm from the terminal,
302 # allowing the (hopefully blank) GPG password to be
303 # entered from stdin instead of /dev/tty.
305 --define "_signature gpg" \
306 --define "_gpg_path $GPGPATH" \
307 --define "_gpg_name $GPGUID" \
308 --resign $new_rpms && touch $new_stamps
311 # Update repository index / yum metadata.
312 if [ -n "$need_createrepo" ] ; then
313 echo "Indexing node packages after signing"
314 if [ -f $repository/yumgroups.xml ] ; then
315 createrepo --quiet -g yumgroups.xml $repository
317 createrepo --quiet $repository
322 function show_env () {
324 echo FCDISTRO=$FCDISTRO
325 echo PLDISTRO=$PLDISTRO
326 echo PERSONALITY=$PERSONALITY
328 echo build_SVNPATH=$build_SVNPATH
329 echo MAKEVARS="${MAKEVARS[@]}"
330 echo DRY_RUN="$DRY_RUN"
331 echo PLDISTROTAGS="$PLDISTROTAGS"
332 # this does not help, it's not yet set when we run show_env
333 #echo WEBPATH="$WEBPATH"
334 echo TESTBUILDURL="$TESTBUILDURL"
335 if in_root_context ; then
336 echo PLDISTROTAGS="$PLDISTROTAGS"
338 if [ -f /build/$PLDISTROTAGS ] ; then
339 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
340 cat /build/$PLDISTROTAGS
341 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
343 echo "XXXXXXXXXXXXXXXXXXXX Cannot find tags definition file /build/$PLDISTROTAGS, assuming remote pldistro"
350 echo "Usage: $COMMAND [option] [var=value...] make-targets"
351 echo "This is $REVISION"
352 echo "Supported options"
353 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
354 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
355 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
356 echo " -m mailto - no default"
357 echo " -s svnpath - where to fetch the build module - defaults to $DEFAULT_build_SVNPATH"
358 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
359 echo " -b base - defaults to $DEFAULT_BASE"
360 echo " @NAME@ replaced as appropriate"
361 echo " -o base: (overwrite) do not re-create vserver, re-use base instead"
362 echo " the -f/-d/-p/-m/-s/-t options are uneffective in this case"
363 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
364 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
365 echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL"
366 echo " -M testmaster - defaults to $DEFAULT_TESTMASTER"
367 echo " -y sign yum repo in webpath"
368 echo " -g path to gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
369 echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
370 echo " -B : run build only"
371 echo " -T : run test only"
372 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
373 echo " -v : be verbose"
374 echo " -7 : uses weekday-@FCDISTRO@ as base"
375 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
390 while getopts "f:d:p:m:s:t:b:o:c:w:W:M:yg:u:BTnv7i:" opt ; do
392 f) FCDISTRO=$OPTARG ;;
393 d) PLDISTRO=$OPTARG ;;
394 p) PERSONALITY=$OPTARG ;;
396 s) build_SVNPATH=$OPTARG ;;
397 t) PLDISTROTAGS=$OPTARG ;;
399 o) OVERBASE=$OPTARG ;;
400 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
401 w) WEBPATH=$OPTARG ;;
402 W) TESTBUILDURL=$OPTARG ;;
403 M) TESTMASTER=$OPTARG ;;
404 y) SIGNYUMREPO=true ;;
405 g) GPGPATH=$OPTARG ;;
411 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
417 # preserve options for passing them again later, together with expanded base
419 toshift=$(($OPTIND - 1))
420 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
422 # allow var=value stuff;
423 for target in "$@" ; do
424 # check if contains '='
425 target1=$(echo $target | sed -e s,=,,)
426 if [ "$target" = "$target1" ] ; then
427 MAKETARGETS=(${MAKETARGETS[@]} "$target")
429 MAKEVARS=(${MAKEVARS[@]} "$target")
434 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
435 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
436 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
437 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
438 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
439 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
440 [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
441 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
442 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
443 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
444 [ -z "$build_SVNPATH" ] && build_SVNPATH="$DEFAULT_build_SVNPATH"
445 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
446 [ -z "$TESTMASTER" ] && TESTMASTER="$DEFAULT_TESTMASTER"
448 [ -n "$DRY_RUN" ] && MAILTO=""
450 if [ -n "$OVERBASE" ] ; then
451 sedargs="-e s,@DATE@,${DATE},g"
452 BASE=$(echo ${OVERBASE} | sed $sedargs)
454 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
455 BASE=$(echo ${BASE} | sed $sedargs)
458 ### elaborate mail subject
459 if [ -n "$DO_BUILD" -a -n "$DO_TEST" ] ; then
460 MAIL_SUBJECT="complete"
461 elif [ -n "$DO_BUILD" ] ; then
462 MAIL_SUBJECT="package-only"
463 elif [ -n "$DO_TEST" ] ; then
464 MAIL_SUBJECT="test-only"
466 if [ -n "$OVERBASE" ] ; then
467 MAIL_SUBJECT="$MAIL_SUBJECT incremental run on"
469 MAIL_SUBJECT="$MAIL_SUBJECT fresh build"
472 if ! in_root_context ; then
474 echo "==================== Within vserver BEG $(date)"
476 echo "==================== Within vserver END $(date)"
480 # we run in the root context :
481 # (*) create or check for the vserver to use
482 # (*) copy this command in the vserver
485 if [ -n "$OVERBASE" ] ; then
486 ### Re-use a vserver (finish an unfinished build..)
487 if [ ! -d /vservers/${BASE} ] ; then
488 echo $COMMAND : cannot find vserver $BASE
491 # manage LOG - beware it might be a symlink so nuke it first
492 LOG=/vservers/${BASE}.log.txt
496 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
497 # start in case e.g. we just rebooted
498 vserver ${BASE} start || :
500 vserver ${BASE} exec svn update /build
501 # get environment from the first run
502 FCDISTRO=$(vserver ${BASE} exec /build/getdistroname.sh)
504 PLDISTRO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTRO)
505 PLDISTROTAGS=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTROTAGS)
506 build_SVNPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +build-SVNPATH)
507 PERSONALITY=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PERSONALITY)
508 MAILTO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +MAILTO)
511 # create vserver: check it does not exist yet
513 while [ -d /vservers/${BASE}${i} ] ; do
514 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
515 [ -z ${i} ] && BASE=${BASE}-n
517 if [ $i -gt 100 ] ; then
518 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
524 # manage LOG - beware it might be a symlink so nuke it first
525 LOG=/vservers/${BASE}.log.txt
529 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
532 ### extract the whole build - much simpler
533 tmpdir=/tmp/$COMMAND-$$
534 svn export $build_SVNPATH $tmpdir
537 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
541 # Extract build again - in the vserver
542 vserver ${BASE} exec svn checkout ${build_SVNPATH} /build
544 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
546 # The log inside the vserver contains everything
547 LOG2=/vservers/${BASE}/log.txt
548 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
550 echo "==================== END VSERVER Transcript of vserver creation" ; \
551 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
552 ### not too nice : nuke the former log, symlink it to the new one
553 rm $LOG; ln -s $LOG2 $LOG
558 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
559 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
562 # where to store the log for web access
563 WEBLOG=${WEBPATH}/${BASE}.log.txt
564 # compute the log URL - inserted in the mail messages for convenience
565 LOG_URL=$(echo ${WEBLOG} | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
566 TESTLOGS_URL=$(echo ${WEBPATH}/${BASE}/testlogs | sed -e "s,//,/,g" -e "s,/build/,${TESTBUILDURL},")
568 if [ -n "$DO_BUILD" ] ; then
570 cp $COMMANDPATH /vservers/${BASE}/build/
572 # invoke this command in the vserver for building (-T)
573 vserver ${BASE} exec chmod +x /build/$COMMAND
574 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
577 # publish to the web so runtest can find them
578 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
579 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
580 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
581 # publish myplc-release
582 rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
584 # create yum repo and sign packages.
585 if [ -n "$SIGNYUMREPO" ] ; then
589 if [ -n "$DO_TEST" ] ; then