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 # for publishing results, and the tests settings
22 y=$(hostname|sed -e s,inria,,)
24 if [ "$x" != "$y" ] ; then
25 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
26 DEFAULT_TESTBUILDURL="http://build.onelab.eu/"
27 # this is where the buildurl is pointing towards
28 DEFAULT_WEBROOT="/build/"
29 DEFAULT_TESTMASTER="testmaster.onelab.eu"
30 DEFAULT_TESTCONFIG="1default"
32 DEFAULT_WEBPATH="/build/@FCDISTRO@/@PLDISTRO@/"
33 DEFAULT_TESTBUILDURL="http://build.planet-lab.org/"
34 # this is where the buildurl is pointing towards
35 DEFAULT_WEBROOT="/build/"
36 ### xxx change as appropriate
37 DEFAULT_TESTMASTER="p-testmaster.onelab.eu"
38 DEFAULT_TESTCONFIG="pdefault"
42 # assuming vserver runs in UTC
43 DATE=$(date +'%Y.%m.%d')
45 # temporary - wrap a quick summary of suspicious stuff
46 # this is to focus on installation that go wrong
47 # use with care, a *lot* of other things can go bad as well
50 echo "******************** BEG SUMMARY"
53 # read a full log and tries to extract the interesting stuff
56 m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*|.*PROPFIND.*|.*Starting.*:runtest.*")
57 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
58 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
59 m_installing_end=re.compile('Installed:.*')
60 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
61 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
63 def summary (filename):
72 for line in f.xreadlines():
73 # first off : discard warnings related to doc
74 if m_installing_doc1.match(line):
75 (begin,end)=m_installing_doc1.match(line).groups()
77 if m_installing_doc2.match(line):
78 (begin,end)=m_installing_doc2.match(line).groups()
80 # unconditionnally show these lines
81 if m_show_line.match(line):
83 # an 'installing' line with messages afterwards : needs to be echoed
84 elif m_installing_err.match(line):
85 (installing,error)=m_installing_err.match(line).groups()
86 print '>>>',installing
89 # closing an 'installing' section
90 elif m_installing_end.match(line):
92 # any 'installing' line
93 elif m_installing_any.match(line):
95 installing=m_installing_any.match(line).group(1)
96 print '>>>',installing
98 # print lines when echo is true
100 if echo: print '>>>',line,
103 print 'Failed to analyze',filename
105 for arg in sys.argv[1:]:
108 echo "******************** END SUMMARY"
112 # Notify recipient of failure or success, manage various stamps
115 # early stage ? - let's not create /build/@PLDISTRO@
116 if [ ! -d ${WEBPATH} ] ; then
118 WEBLOG=/tmp/vbuild-early.log.txt
121 summary $LOG >> ${WEBLOG}
122 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 30k $WEBLOG) > ${WEBLOG}.ko
123 if [ -n "$MAILTO" ] ; then
125 echo "See full build log at ${LOG_URL}" ; \
126 echo "and tail version at ${LOG_URL}.ko" ; \
127 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
128 tail -c 30k ${WEBLOG} ) | mail -s "Failures with ${MAIL_SUBJECT} ${BASE}" $MAILTO
133 function success () {
135 # early stage ? - let's not create /build/@PLDISTRO@
136 if [ ! -d ${WEBPATH} ] ; then
138 WEBLOG=/tmp/vbuild-early-$(date +%Y-%m-%d).log.txt
141 summary $LOG >> ${WEBLOG}
142 if [ -n "$DO_TEST" ] ; then
144 echo "Successfully built and tested" ; \
145 echo "See full build log at ${LOG_URL}" ; \
146 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
148 rm -f ${WEBLOG}.pkg-ok ${WEBLOG}.ko
151 echo "Successful package-only build, no test requested" ; \
152 echo "See full build log at ${LOG_URL}" ; \
156 if [ -n "$MAILTO" ] ; then
158 echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ; \
159 echo "See full build log at ${LOG_URL}" ; \
160 [ -n "$DO_TEST" ] && echo "See complete set of testlogs at ${TESTLOGS_URL}" ) \
161 | mail -s "Success with ${MAIL_SUBJECT} ${BASE}" $MAILTO
166 # run in the vserver - do not manage success/failure, will be done from the root ctx
171 echo -n "============================== Starting $COMMAND:build on "
177 echo "Running make IN $(pwd)"
179 # stuff our own variable settings
180 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
181 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
182 MAKEVARS=("build-SVNPATH=${build_SVNPATH}" "${MAKEVARS[@]}")
183 MAKEVARS=("PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
184 MAKEVARS=("MAILTO=${MAILTO}" "${MAKEVARS[@]}")
185 MAKEVARS=("WEBPATH=${WEBPATH}" "${MAKEVARS[@]}")
186 MAKEVARS=("TESTBUILDURL=${TESTBUILDURL}" "${MAKEVARS[@]}")
187 MAKEVARS=("WEBROOT=${WEBROOT}" "${MAKEVARS[@]}")
189 MAKEVARS=("BASE=${BASE}" "${MAKEVARS[@]}")
192 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
193 # store tests_svnpath
194 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true tests_svnpath
196 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
198 make -C /build $DRY_RUN "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
202 # this was formerly run in the myplc-devel chroot but now is run in the root context,
203 # this is so that the .ssh config gets done manually, and once and for all
204 function runtest () {
209 echo -n "============================== Starting $COMMAND:runtest on $(date)"
211 # where to find TESTS_SVNPATH
212 stamp=/vservers/$BASE/build/tests_svnpath
213 if [ ! -f $stamp ] ; then
214 echo "$COMMAND: Cannot figure TESTS_SVNPATH from missing $stamp"
218 TESTS_SVNPATH=$(cat $stamp)
219 # xxx - Thierry - need to rework the test framework in tests/system so it can work
220 # with the entire tests/ module checked out, rather than only tests/system/
221 # ugly workaround for now
222 TESTS_SYSTEM_SVNPATH=${TESTS_SVNPATH}/system
224 ### the URL to the RPMS/<arch> location
226 for a in i386 x86_64; do
227 archdir=/vservers/$BASE/build/RPMS/$a
228 if [ -d $archdir ] ; then
229 # where was that installed
230 url=$(echo $archdir | sed -e "s,/vservers/${BASE}/build,${WEBPATH}/${BASE},")
231 url=$(echo $url | sed -e "s,${WEBROOT},${TESTBUILDURL},")
236 if [ -z "$url" ] ; then
237 echo "$COMMAND: Cannot locate arch URL for testing"
242 testmaster_ssh="root@${TESTMASTER}"
244 # test directory name on test box
247 ssh -n ${testmaster_ssh} rm -rf ${testdir}
249 ssh -n ${testmaster_ssh} svn co ${TESTS_SYSTEM_SVNPATH} ${testdir}
250 # check out the entire tests/ module (with system/ duplicated) as a subdir - see xxx above
251 ssh -n ${testmaster_ssh} svn co ${TESTS_SVNPATH} ${testdir}/tests
252 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
254 for config in ${TESTCONFIG} ; do
255 configs="$configs --config $config"
257 test_env="-p $PERSONALITY -d $PLDISTRO -f $FCDISTRO"
259 # need to proceed despite of set -e
261 ssh 2>&1 -n ${testmaster_ssh} ${testdir}/runtest --build ${build_SVNPATH} --url ${url} $configs $test_env --all || success=
263 # gather logs in the vserver
264 mkdir -p /vservers/$BASE/build/testlogs
265 ssh 2>&1 -n ${testmaster_ssh} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
266 # push them to the build web
267 chmod -R a+r /vservers/$BASE/build/testlogs/
268 rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
270 if [ -z "$success" ] ; then
274 echo -n "============================== End $COMMAND:runtest on $(date)"
277 function in_root_context () {
278 rpm -q util-vserver > /dev/null
281 # this part won't work with a remote(rsync) WEBPATH
282 function sign_node_packages () {
284 echo "Signing node packages"
288 repository=$WEBPATH/$BASE/RPMS/
289 # the rpms that need signing
291 # and the corresponding stamps
294 for package in $(find $repository/ -name '*.rpm') ; do
295 stamp=$repository/signed-stamps/$(basename $package).signed
296 # If package is newer than signature stamp
297 if [ $package -nt $stamp ] ; then
298 new_rpms="$new_rpms $package"
299 new_stamps="$new_stamps $stamp"
301 # Or than createrepo database
302 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
305 if [ -n "$new_rpms" ] ; then
306 # Create a stamp once the package gets signed
307 mkdir $repository/signed-stamps 2> /dev/null
309 # Sign RPMS. setsid detaches rpm from the terminal,
310 # allowing the (hopefully blank) GPG password to be
311 # entered from stdin instead of /dev/tty.
313 --define "_signature gpg" \
314 --define "_gpg_path $GPGPATH" \
315 --define "_gpg_name $GPGUID" \
316 --resign $new_rpms && touch $new_stamps
319 # Update repository index / yum metadata.
320 if [ -n "$need_createrepo" ] ; then
321 echo "Indexing node packages after signing"
322 if [ -f $repository/yumgroups.xml ] ; then
323 createrepo --quiet -g yumgroups.xml $repository
325 createrepo --quiet $repository
330 function show_env () {
332 echo FCDISTRO=$FCDISTRO
333 echo PLDISTRO=$PLDISTRO
334 echo PERSONALITY=$PERSONALITY
336 echo build_SVNPATH=$build_SVNPATH
337 echo MAKEVARS="${MAKEVARS[@]}"
338 echo DRY_RUN="$DRY_RUN"
339 echo PLDISTROTAGS="$PLDISTROTAGS"
340 # this does not help, it's not yet set when we run show_env
341 #echo WEBPATH="$WEBPATH"
342 echo TESTBUILDURL="$TESTBUILDURL"
343 if in_root_context ; then
344 echo PLDISTROTAGS="$PLDISTROTAGS"
346 if [ -f /build/$PLDISTROTAGS ] ; then
347 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
348 cat /build/$PLDISTROTAGS
349 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
351 echo "XXXXXXXXXXXXXXXXXXXX Cannot find tags definition file /build/$PLDISTROTAGS, assuming remote pldistro"
358 echo "Usage: $COMMAND [option] [var=value...] make-targets"
359 echo "This is $REVISION"
360 echo "Supported options"
361 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
362 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
363 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
364 echo " -m mailto - no default"
365 echo " -s svnpath - where to fetch the build module - defaults to $DEFAULT_build_SVNPATH"
366 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
367 echo " -b base - defaults to $DEFAULT_BASE"
368 echo " @NAME@ replaced as appropriate"
369 echo " -o base: (overwrite) do not re-create vserver, re-use base instead"
370 echo " the -f/-d/-p/-m/-s/-t options are uneffective in this case"
371 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
372 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
373 echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL"
374 echo " -r webroot - defaults to $DEFAULT_WEBROOT - the fs point where testbuildurl actually sits"
375 echo " -M testmaster - defaults to $DEFAULT_TESTMASTER"
376 echo " -y sign yum repo in webpath"
377 echo " -g path to gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
378 echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
379 echo " -B : run build only"
380 echo " -T : run test only"
381 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
382 echo " -v : be verbose"
383 echo " -7 : uses weekday-@FCDISTRO@ as base"
384 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
399 while getopts "f:d:p:m:s:t:b:o:c:w:W:r:M:yg:u:BTnv7i:" opt ; do
401 f) FCDISTRO=$OPTARG ;;
402 d) PLDISTRO=$OPTARG ;;
403 p) PERSONALITY=$OPTARG ;;
405 s) build_SVNPATH=$OPTARG ;;
406 t) PLDISTROTAGS=$OPTARG ;;
408 o) OVERBASE=$OPTARG ;;
409 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
410 w) WEBPATH=$OPTARG ;;
411 W) TESTBUILDURL=$OPTARG ;;
412 r) WEBROOT=$OPTARG ;;
413 M) TESTMASTER=$OPTARG ;;
414 y) SIGNYUMREPO=true ;;
415 g) GPGPATH=$OPTARG ;;
421 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
427 # preserve options for passing them again later, together with expanded base
429 toshift=$(($OPTIND - 1))
430 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
432 # allow var=value stuff;
433 for target in "$@" ; do
434 # check if contains '='
435 target1=$(echo $target | sed -e s,=,,)
436 if [ "$target" = "$target1" ] ; then
437 MAKETARGETS=(${MAKETARGETS[@]} "$target")
439 MAKEVARS=(${MAKEVARS[@]} "$target")
444 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
445 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
446 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
447 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
448 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
449 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
450 [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
451 [ -z "$WEBROOT" ] && WEBROOT="$DEFAULT_WEBROOT"
452 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
453 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
454 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
455 [ -z "$build_SVNPATH" ] && build_SVNPATH="$DEFAULT_build_SVNPATH"
456 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
457 [ -z "$TESTMASTER" ] && TESTMASTER="$DEFAULT_TESTMASTER"
459 [ -n "$DRY_RUN" ] && MAILTO=""
461 if [ -n "$OVERBASE" ] ; then
462 sedargs="-e s,@DATE@,${DATE},g"
463 BASE=$(echo ${OVERBASE} | sed $sedargs)
465 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
466 BASE=$(echo ${BASE} | sed $sedargs)
469 ### elaborate mail subject
470 if [ -n "$DO_BUILD" -a -n "$DO_TEST" ] ; then
471 MAIL_SUBJECT="complete"
472 elif [ -n "$DO_BUILD" ] ; then
473 MAIL_SUBJECT="package-only"
474 elif [ -n "$DO_TEST" ] ; then
475 MAIL_SUBJECT="test-only"
477 if [ -n "$OVERBASE" ] ; then
478 MAIL_SUBJECT="$MAIL_SUBJECT incremental run on"
480 MAIL_SUBJECT="$MAIL_SUBJECT fresh build"
483 if ! in_root_context ; then
485 echo "==================== Within vserver BEG $(date)"
487 echo "==================== Within vserver END $(date)"
491 # we run in the root context :
492 # (*) create or check for the vserver to use
493 # (*) copy this command in the vserver
496 if [ -n "$OVERBASE" ] ; then
497 ### Re-use a vserver (finish an unfinished build..)
498 if [ ! -d /vservers/${BASE} ] ; then
499 echo $COMMAND : cannot find vserver $BASE
502 # manage LOG - beware it might be a symlink so nuke it first
503 LOG=/vservers/${BASE}.log.txt
507 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
508 # start in case e.g. we just rebooted
509 vserver ${BASE} start || :
511 vserver ${BASE} exec svn update /build
512 # get environment from the first run
513 FCDISTRO=$(vserver ${BASE} exec /build/getdistroname.sh)
515 PLDISTRO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTRO)
516 PLDISTROTAGS=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTROTAGS)
517 build_SVNPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +build-SVNPATH)
518 PERSONALITY=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PERSONALITY)
519 MAILTO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +MAILTO)
520 WEBPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +WEBPATH)
521 TESTBUILDURL=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +TESTBUILDURL)
522 WEBROOT=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +WEBROOT)
525 # create vserver: check it does not exist yet
527 while [ -d /vservers/${BASE}${i} ] ; do
528 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
529 [ -z ${i} ] && BASE=${BASE}-n
531 if [ $i -gt 100 ] ; then
532 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
538 # manage LOG - beware it might be a symlink so nuke it first
539 LOG=/vservers/${BASE}.log.txt
543 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
546 ### extract the whole build - much simpler
547 tmpdir=/tmp/$COMMAND-$$
548 svn export $build_SVNPATH $tmpdir
551 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
555 # Extract build again - in the vserver
556 vserver ${BASE} exec svn checkout ${build_SVNPATH} /build
558 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
560 # The log inside the vserver contains everything
561 LOG2=/vservers/${BASE}/log.txt
562 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
564 echo "==================== END VSERVER Transcript of vserver creation" ; \
565 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
566 ### not too nice : nuke the former log, symlink it to the new one
567 rm $LOG; ln -s $LOG2 $LOG
572 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
573 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
576 # where to store the log for web access
577 WEBLOG=${WEBPATH}/${BASE}.log.txt
578 # compute the log URL - inserted in the mail messages for convenience
579 LOG_URL=$(echo ${WEBLOG} | sed -e "s,//,/,g" -e "s,${WEBROOT},${TESTBUILDURL},")
580 TESTLOGS_URL=$(echo ${WEBPATH}/${BASE}/testlogs | sed -e "s,//,/,g" -e "s,${WEBROOT},${TESTBUILDURL},")
582 if [ -n "$DO_BUILD" ] ; then
584 cp $COMMANDPATH /vservers/${BASE}/build/
586 # invoke this command in the vserver for building (-T)
587 vserver ${BASE} exec chmod +x /build/$COMMAND
588 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
591 # publish to the web so runtest can find them
592 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
593 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
594 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
595 # publish myplc-release
596 rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
598 # create yum repo and sign packages.
599 if [ -n "$SIGNYUMREPO" ] ; then
603 if [ -n "$DO_TEST" ] ; then