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 DEFAULT_TESTCONFIG="default"
22 # for publishing results, and the tests settings
24 y=$(hostname|sed -e s,inria,,)
26 if [ "$x" != "$y" ] ; then
27 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
28 DEFAULT_TESTBUILDURL="http://build.onelab.eu/"
29 # this is where the buildurl is pointing towards
30 DEFAULT_WEBROOT="/build/"
31 DEFAULT_TESTMASTER="testmaster.onelab.eu"
33 DEFAULT_WEBPATH="/build/@FCDISTRO@/@PLDISTRO@/"
34 DEFAULT_TESTBUILDURL="http://build.planet-lab.org/"
35 # this is where the buildurl is pointing towards
36 DEFAULT_WEBROOT="/build/"
37 DEFAULT_TESTMASTER="manager.test.planet-lab.org"
41 # assuming vserver runs in UTC
42 DATE=$(date +'%Y.%m.%d')
44 # temporary - wrap a quick summary of suspicious stuff
45 # this is to focus on installation that go wrong
46 # use with care, a *lot* of other things can go bad as well
49 echo "******************** BEG SUMMARY"
52 # read a full log and tries to extract the interesting stuff
55 m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*|.*PROPFIND.*|.*Starting.*:run_log.*")
56 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
57 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
58 m_installing_end=re.compile('Installed:.*')
59 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
60 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
62 def summary (filename):
71 for line in f.xreadlines():
72 # first off : discard warnings related to doc
73 if m_installing_doc1.match(line):
74 (begin,end)=m_installing_doc1.match(line).groups()
76 if m_installing_doc2.match(line):
77 (begin,end)=m_installing_doc2.match(line).groups()
79 # unconditionnally show these lines
80 if m_show_line.match(line):
82 # an 'installing' line with messages afterwards : needs to be echoed
83 elif m_installing_err.match(line):
84 (installing,error)=m_installing_err.match(line).groups()
85 print '>>>',installing
88 # closing an 'installing' section
89 elif m_installing_end.match(line):
91 # any 'installing' line
92 elif m_installing_any.match(line):
94 installing=m_installing_any.match(line).group(1)
95 print '>>>',installing
97 # print lines when echo is true
99 if echo: print '>>>',line,
102 print 'Failed to analyze',filename
104 for arg in sys.argv[1:]:
107 echo "******************** END SUMMARY"
111 # Notify recipient of failure or success, manage various stamps
114 # early stage ? - let's not create /build/@PLDISTRO@
115 if [ ! -d ${WEBPATH} ] ; then
117 WEBLOG=/tmp/vbuild-early.log.txt
120 summary $LOG >> ${WEBLOG}
121 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 30k $WEBLOG) > ${WEBLOG}.ko
122 if [ -n "$MAILTO" ] ; then
124 echo "See full build log at ${LOG_URL}" ; \
125 echo "and tail version at ${LOG_URL}.ko" ; \
126 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
127 tail -c 30k ${WEBLOG} ) | mail -s "Failures with ${MAIL_SUBJECT} ${BASE}" $MAILTO
132 function success () {
134 # early stage ? - let's not create /build/@PLDISTRO@
135 if [ ! -d ${WEBPATH} ] ; then
137 WEBLOG=/tmp/vbuild-early-$(date +%Y-%m-%d).log.txt
140 summary $LOG >> ${WEBLOG}
141 if [ -n "$DO_TEST" ] ; then
143 echo "Successfully built and tested" ; \
144 echo "See full build log at ${LOG_URL}" ; \
145 echo "See complete set of testlogs at ${TESTLOGS_URL}" ; \
147 rm -f ${WEBLOG}.pkg-ok ${WEBLOG}.ko
150 echo "Successful package-only build, no test requested" ; \
151 echo "See full build log at ${LOG_URL}" ; \
155 if [ -n "$MAILTO" ] ; then
157 echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ; \
158 echo "See full build log at ${LOG_URL}" ; \
159 [ -n "$DO_TEST" ] && echo "See complete set of testlogs at ${TESTLOGS_URL}" ) \
160 | mail -s "Success with ${MAIL_SUBJECT} ${BASE}" $MAILTO
165 # run in the vserver - do not manage success/failure, will be done from the root ctx
170 echo -n "============================== Starting $COMMAND:build on "
176 echo "Running make IN $(pwd)"
178 # stuff our own variable settings
179 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
180 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
181 MAKEVARS=("build-SVNPATH=${build_SVNPATH}" "${MAKEVARS[@]}")
182 MAKEVARS=("PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
183 MAKEVARS=("MAILTO=${MAILTO}" "${MAKEVARS[@]}")
184 MAKEVARS=("WEBPATH=${WEBPATH}" "${MAKEVARS[@]}")
185 MAKEVARS=("TESTBUILDURL=${TESTBUILDURL}" "${MAKEVARS[@]}")
186 MAKEVARS=("WEBROOT=${WEBROOT}" "${MAKEVARS[@]}")
188 MAKEVARS=("BASE=${BASE}" "${MAKEVARS[@]}")
191 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
192 # store tests_svnpath
193 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true tests_svnpath
195 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
197 make -C /build $DRY_RUN "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
201 # this was formerly run in the myplc-devel chroot but now is run in the root context,
202 # this is so that the .ssh config gets done manually, and once and for all
203 function run_log () {
208 echo -n "============================== Starting $COMMAND:run_log on $(date)"
210 # where to find TESTS_SVNPATH
211 stamp=/vservers/$BASE/build/tests_svnpath
212 if [ ! -f $stamp ] ; then
213 echo "$COMMAND: Cannot figure TESTS_SVNPATH from missing $stamp"
217 TESTS_SVNPATH=$(cat $stamp)
218 # don't need the tests fulltree anymore
219 TESTS_SYSTEM_SVNPATH=${TESTS_SVNPATH}/system
221 ### the URL to the RPMS/<arch> location
223 for a in i386 x86_64; do
224 archdir=/vservers/$BASE/build/RPMS/$a
225 if [ -d $archdir ] ; then
226 # where was that installed
227 url=$(echo $archdir | sed -e "s,/vservers/${BASE}/build,${WEBPATH}/${BASE},")
228 url=$(echo $url | sed -e "s,${WEBROOT},${TESTBUILDURL},")
233 if [ -z "$url" ] ; then
234 echo "$COMMAND: Cannot locate arch URL for testing"
239 testmaster_ssh="root@${TESTMASTER}"
241 # test directory name on test box
244 ssh -n ${testmaster_ssh} rm -rf ${testdir}
246 ssh -n ${testmaster_ssh} svn co ${TESTS_SYSTEM_SVNPATH} ${testdir}
247 ### # check out the entire tests/ module (with system/ duplicated) as a subdir - see fulltree above
248 ### ssh -n ${testmaster_ssh} svn co ${TESTS_SVNPATH} ${testdir}/tests
249 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
251 for config in ${TESTCONFIG} ; do
252 configs="$configs --config $config"
254 test_env="-p $PERSONALITY -d $PLDISTRO -f $FCDISTRO"
256 # need to proceed despite of set -e
258 ssh 2>&1 -n ${testmaster_ssh} ${testdir}/run_log --build ${build_SVNPATH} --url ${url} $configs $test_env --verbose --all || success=
260 # gather logs in the vserver
261 mkdir -p /vservers/$BASE/build/testlogs
262 ssh 2>&1 -n ${testmaster_ssh} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
263 # push them to the build web
264 chmod -R a+r /vservers/$BASE/build/testlogs/
265 rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
267 if [ -z "$success" ] ; then
271 echo -n "============================== End $COMMAND:run_log on $(date)"
274 function in_root_context () {
275 rpm -q util-vserver > /dev/null
278 # this part won't work with a remote(rsync) WEBPATH
279 function sign_node_packages () {
281 echo "Signing node packages"
285 repository=$WEBPATH/$BASE/RPMS/
286 # the rpms that need signing
288 # and the corresponding stamps
291 for package in $(find $repository/ -name '*.rpm') ; do
292 stamp=$repository/signed-stamps/$(basename $package).signed
293 # If package is newer than signature stamp
294 if [ $package -nt $stamp ] ; then
295 new_rpms="$new_rpms $package"
296 new_stamps="$new_stamps $stamp"
298 # Or than createrepo database
299 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
302 if [ -n "$new_rpms" ] ; then
303 # Create a stamp once the package gets signed
304 mkdir $repository/signed-stamps 2> /dev/null
306 # Sign RPMS. setsid detaches rpm from the terminal,
307 # allowing the (hopefully blank) GPG password to be
308 # entered from stdin instead of /dev/tty.
310 --define "_signature gpg" \
311 --define "_gpg_path $GPGPATH" \
312 --define "_gpg_name $GPGUID" \
313 --resign $new_rpms && touch $new_stamps
316 # Update repository index / yum metadata.
317 if [ -n "$need_createrepo" ] ; then
318 echo "Indexing node packages after signing"
319 if [ -f $repository/yumgroups.xml ] ; then
320 createrepo --quiet -g yumgroups.xml $repository
322 createrepo --quiet $repository
327 function show_env () {
329 echo FCDISTRO=$FCDISTRO
330 echo PLDISTRO=$PLDISTRO
331 echo PERSONALITY=$PERSONALITY
333 echo build_SVNPATH=$build_SVNPATH
334 echo MAKEVARS="${MAKEVARS[@]}"
335 echo DRY_RUN="$DRY_RUN"
336 echo PLDISTROTAGS="$PLDISTROTAGS"
337 # this does not help, it's not yet set when we run show_env
338 #echo WEBPATH="$WEBPATH"
339 echo TESTBUILDURL="$TESTBUILDURL"
340 if in_root_context ; then
341 echo PLDISTROTAGS="$PLDISTROTAGS"
343 if [ -f /build/$PLDISTROTAGS ] ; then
344 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
345 cat /build/$PLDISTROTAGS
346 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
348 echo "XXXXXXXXXXXXXXXXXXXX Cannot find tags definition file /build/$PLDISTROTAGS, assuming remote pldistro"
355 echo "Usage: $COMMAND [option] [var=value...] make-targets"
356 echo "This is $REVISION"
357 echo "Supported options"
358 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
359 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
360 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
361 echo " -m mailto - no default"
362 echo " -s svnpath - where to fetch the build module - defaults to $DEFAULT_build_SVNPATH"
363 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
364 echo " -b base - defaults to $DEFAULT_BASE"
365 echo " @NAME@ replaced as appropriate"
366 echo " -o base: (overwrite) do not re-create vserver, re-use base instead"
367 echo " the -f/-d/-p/-m/-s/-t options are uneffective in this case"
368 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
369 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
370 echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL"
371 echo " -r webroot - defaults to $DEFAULT_WEBROOT - the fs point where testbuildurl actually sits"
372 echo " -M testmaster - defaults to $DEFAULT_TESTMASTER"
373 echo " -y sign yum repo in webpath"
374 echo " -g path to gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
375 echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
376 echo " -B : run build only"
377 echo " -T : run test only"
378 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
379 echo " -v : be verbose"
380 echo " -7 : uses weekday-@FCDISTRO@ as base"
381 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
396 while getopts "f:d:p:m:s:t:b:o:c:w:W:r:M:yg:u:BTnv7i:" opt ; do
398 f) FCDISTRO=$OPTARG ;;
399 d) PLDISTRO=$OPTARG ;;
400 p) PERSONALITY=$OPTARG ;;
402 s) build_SVNPATH=$OPTARG ;;
403 t) PLDISTROTAGS=$OPTARG ;;
405 o) OVERBASE=$OPTARG ;;
406 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
407 w) WEBPATH=$OPTARG ;;
408 W) TESTBUILDURL=$OPTARG ;;
409 r) WEBROOT=$OPTARG ;;
410 M) TESTMASTER=$OPTARG ;;
411 y) SIGNYUMREPO=true ;;
412 g) GPGPATH=$OPTARG ;;
418 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
424 # preserve options for passing them again later, together with expanded base
426 toshift=$(($OPTIND - 1))
427 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
429 # allow var=value stuff;
430 for target in "$@" ; do
431 # check if contains '='
432 target1=$(echo $target | sed -e s,=,,)
433 if [ "$target" = "$target1" ] ; then
434 MAKETARGETS=(${MAKETARGETS[@]} "$target")
436 MAKEVARS=(${MAKEVARS[@]} "$target")
441 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
442 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
443 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
444 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
445 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
446 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
447 [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
448 [ -z "$WEBROOT" ] && WEBROOT="$DEFAULT_WEBROOT"
449 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
450 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
451 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
452 [ -z "$build_SVNPATH" ] && build_SVNPATH="$DEFAULT_build_SVNPATH"
453 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
454 [ -z "$TESTMASTER" ] && TESTMASTER="$DEFAULT_TESTMASTER"
456 [ -n "$DRY_RUN" ] && MAILTO=""
458 if [ -n "$OVERBASE" ] ; then
459 sedargs="-e s,@DATE@,${DATE},g"
460 BASE=$(echo ${OVERBASE} | sed $sedargs)
462 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
463 BASE=$(echo ${BASE} | sed $sedargs)
466 ### elaborate mail subject
467 if [ -n "$DO_BUILD" -a -n "$DO_TEST" ] ; then
468 MAIL_SUBJECT="complete"
469 elif [ -n "$DO_BUILD" ] ; then
470 MAIL_SUBJECT="package-only"
471 elif [ -n "$DO_TEST" ] ; then
472 MAIL_SUBJECT="test-only"
474 if [ -n "$OVERBASE" ] ; then
475 MAIL_SUBJECT="$MAIL_SUBJECT incremental run on"
477 MAIL_SUBJECT="$MAIL_SUBJECT fresh build"
480 if ! in_root_context ; then
482 echo "==================== Within vserver BEG $(date)"
484 echo "==================== Within vserver END $(date)"
488 # we run in the root context :
489 # (*) create or check for the vserver to use
490 # (*) copy this command in the vserver
493 if [ -n "$OVERBASE" ] ; then
494 ### Re-use a vserver (finish an unfinished build..)
495 if [ ! -d /vservers/${BASE} ] ; then
496 echo $COMMAND : cannot find vserver $BASE
499 # manage LOG - beware it might be a symlink so nuke it first
500 LOG=/vservers/${BASE}.log.txt
504 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
505 # start in case e.g. we just rebooted
506 vserver ${BASE} start || :
508 vserver ${BASE} exec svn update /build
509 # get environment from the first run
510 FCDISTRO=$(vserver ${BASE} exec /build/getdistroname.sh)
512 PLDISTRO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTRO)
513 PLDISTROTAGS=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTROTAGS)
514 build_SVNPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +build-SVNPATH)
515 PERSONALITY=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PERSONALITY)
516 MAILTO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +MAILTO)
517 WEBPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +WEBPATH)
518 TESTBUILDURL=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +TESTBUILDURL)
519 WEBROOT=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +WEBROOT)
522 # create vserver: check it does not exist yet
524 while [ -d /vservers/${BASE}${i} ] ; do
525 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
526 [ -z ${i} ] && BASE=${BASE}-n
528 if [ $i -gt 100 ] ; then
529 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
535 # manage LOG - beware it might be a symlink so nuke it first
536 LOG=/vservers/${BASE}.log.txt
540 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
543 ### extract the whole build - much simpler
544 tmpdir=/tmp/$COMMAND-$$
545 svn export $build_SVNPATH $tmpdir
548 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
552 # Extract build again - in the vserver
553 vserver ${BASE} exec svn checkout ${build_SVNPATH} /build
555 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
557 # The log inside the vserver contains everything
558 LOG2=/vservers/${BASE}/log.txt
559 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
561 echo "==================== END VSERVER Transcript of vserver creation" ; \
562 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
563 ### not too nice : nuke the former log, symlink it to the new one
564 rm $LOG; ln -s $LOG2 $LOG
569 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
570 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
573 # where to store the log for web access
574 WEBLOG=${WEBPATH}/${BASE}.log.txt
575 # compute the log URL - inserted in the mail messages for convenience
576 LOG_URL=$(echo ${WEBLOG} | sed -e "s,//,/,g" -e "s,${WEBROOT},${TESTBUILDURL},")
577 TESTLOGS_URL=$(echo ${WEBPATH}/${BASE}/testlogs | sed -e "s,//,/,g" -e "s,${WEBROOT},${TESTBUILDURL},")
579 if [ -n "$DO_BUILD" ] ; then
581 cp $COMMANDPATH /vservers/${BASE}/build/
583 # invoke this command in the vserver for building (-T)
584 vserver ${BASE} exec chmod +x /build/$COMMAND
585 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
588 # publish to the web so run_log can find them
589 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
590 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
591 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
592 # publish myplc-release
593 rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
595 # create yum repo and sign packages.
596 if [ -n "$SIGNYUMREPO" ] ; then
600 if [ -n "$DO_TEST" ] ; then