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[@]}")
186 MAKEVARS=("BASE=${BASE}" "${MAKEVARS[@]}")
189 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
190 # store tests_svnpath
191 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true tests_svnpath
193 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
195 make -C /build $DRY_RUN "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
199 # this was formerly run in the myplc-devel chroot but now is run in the root context,
200 # this is so that the .ssh config gets done manually, and once and for all
201 function runtest () {
206 echo -n "============================== Starting $COMMAND:runtest on $(date)"
208 # where to find TESTS_SVNPATH
209 stamp=/vservers/$BASE/build/tests_svnpath
210 if [ ! -f $stamp ] ; then
211 echo "$COMMAND: Cannot figure TESTS_SVNPATH from missing $stamp"
215 TESTS_SVNPATH=$(cat $stamp)
216 # xxx - Thierry - need to rework the test framework in tests/system so it can work
217 # with the entire tests/ module checked out, rather than only tests/system/
218 # ugly workaround for now
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 url=$(echo $archdir | sed -e "s,/vservers/$BASE/build,${TESTBUILDURL}${PLDISTRO}/${BASE},")
231 if [ -z "$url" ] ; then
232 echo "$COMMAND: Cannot locate arch URL for testing"
237 testmaster_ssh="root@${TESTMASTER}"
239 # test directory name on test box
242 ssh -n ${testmaster_ssh} rm -rf ${testdir}
244 ssh -n ${testmaster_ssh} svn co ${TESTS_SYSTEM_SVNPATH} ${testdir}
245 # check out the entire tests/ module (with system/ duplicated) as a subdir - see xxx above
246 ssh -n ${testmaster_ssh} svn co ${TESTS_SVNPATH} ${testdir}/tests
247 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
249 for config in ${TESTCONFIG} ; do
250 configs="$configs --config $config"
252 test_env="-p $PERSONALITY -d $PLDISTRO -f $FCDISTRO"
254 # need to proceed despite of set -e
256 ssh 2>&1 -n ${testmaster_ssh} ${testdir}/runtest --build ${build_SVNPATH} --url ${url} $configs $test_env --all || success=
258 # gather logs in the vserver
259 mkdir -p /vservers/$BASE/build/testlogs
260 ssh 2>&1 -n ${testmaster_ssh} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
261 # push them to the build web
262 chmod -R a+r /vservers/$BASE/build/testlogs/
263 rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
265 if [ -z "$success" ] ; then
269 echo -n "============================== End $COMMAND:runtest on $(date)"
272 function in_root_context () {
273 rpm -q util-vserver > /dev/null
276 # this part won't work with a remote(rsync) WEBPATH
277 function sign_node_packages () {
279 echo "Signing node packages"
283 repository=$WEBPATH/$BASE/RPMS/
284 # the rpms that need signing
286 # and the corresponding stamps
289 for package in $(find $repository/ -name '*.rpm') ; do
290 stamp=$repository/signed-stamps/$(basename $package).signed
291 # If package is newer than signature stamp
292 if [ $package -nt $stamp ] ; then
293 new_rpms="$new_rpms $package"
294 new_stamps="$new_stamps $stamp"
296 # Or than createrepo database
297 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
300 if [ -n "$new_rpms" ] ; then
301 # Create a stamp once the package gets signed
302 mkdir $repository/signed-stamps 2> /dev/null
304 # Sign RPMS. setsid detaches rpm from the terminal,
305 # allowing the (hopefully blank) GPG password to be
306 # entered from stdin instead of /dev/tty.
308 --define "_signature gpg" \
309 --define "_gpg_path $GPGPATH" \
310 --define "_gpg_name $GPGUID" \
311 --resign $new_rpms && touch $new_stamps
314 # Update repository index / yum metadata.
315 if [ -n "$need_createrepo" ] ; then
316 echo "Indexing node packages after signing"
317 if [ -f $repository/yumgroups.xml ] ; then
318 createrepo --quiet -g yumgroups.xml $repository
320 createrepo --quiet $repository
325 function show_env () {
327 echo FCDISTRO=$FCDISTRO
328 echo PLDISTRO=$PLDISTRO
329 echo PERSONALITY=$PERSONALITY
331 echo build_SVNPATH=$build_SVNPATH
332 echo MAKEVARS="${MAKEVARS[@]}"
333 echo DRY_RUN="$DRY_RUN"
334 echo PLDISTROTAGS="$PLDISTROTAGS"
335 # this does not help, it's not yet set when we run show_env
336 #echo WEBPATH="$WEBPATH"
337 echo TESTBUILDURL="$TESTBUILDURL"
338 if in_root_context ; then
339 echo PLDISTROTAGS="$PLDISTROTAGS"
341 if [ -f /build/$PLDISTROTAGS ] ; then
342 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
343 cat /build/$PLDISTROTAGS
344 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
346 echo "XXXXXXXXXXXXXXXXXXXX Cannot find tags definition file /build/$PLDISTROTAGS, assuming remote pldistro"
353 echo "Usage: $COMMAND [option] [var=value...] make-targets"
354 echo "This is $REVISION"
355 echo "Supported options"
356 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
357 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
358 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
359 echo " -m mailto - no default"
360 echo " -s svnpath - where to fetch the build module - defaults to $DEFAULT_build_SVNPATH"
361 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
362 echo " -b base - defaults to $DEFAULT_BASE"
363 echo " @NAME@ replaced as appropriate"
364 echo " -o base: (overwrite) do not re-create vserver, re-use base instead"
365 echo " the -f/-d/-p/-m/-s/-t options are uneffective in this case"
366 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
367 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
368 echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL"
369 echo " -r webroot - defaults to $DEFAULT_WEBROOT - the fs point where testbuildurl actually sits"
370 echo " -M testmaster - defaults to $DEFAULT_TESTMASTER"
371 echo " -y sign yum repo in webpath"
372 echo " -g path to gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
373 echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
374 echo " -B : run build only"
375 echo " -T : run test only"
376 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
377 echo " -v : be verbose"
378 echo " -7 : uses weekday-@FCDISTRO@ as base"
379 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
394 while getopts "f:d:p:m:s:t:b:o:c:w:W:M:yg:u:BTnv7i:" opt ; do
396 f) FCDISTRO=$OPTARG ;;
397 d) PLDISTRO=$OPTARG ;;
398 p) PERSONALITY=$OPTARG ;;
400 s) build_SVNPATH=$OPTARG ;;
401 t) PLDISTROTAGS=$OPTARG ;;
403 o) OVERBASE=$OPTARG ;;
404 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
405 w) WEBPATH=$OPTARG ;;
406 W) TESTBUILDURL=$OPTARG ;;
407 r) WEBROOT=$OPTARG ;;
408 M) TESTMASTER=$OPTARG ;;
409 y) SIGNYUMREPO=true ;;
410 g) GPGPATH=$OPTARG ;;
416 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
422 # preserve options for passing them again later, together with expanded base
424 toshift=$(($OPTIND - 1))
425 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
427 # allow var=value stuff;
428 for target in "$@" ; do
429 # check if contains '='
430 target1=$(echo $target | sed -e s,=,,)
431 if [ "$target" = "$target1" ] ; then
432 MAKETARGETS=(${MAKETARGETS[@]} "$target")
434 MAKEVARS=(${MAKEVARS[@]} "$target")
439 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
440 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
441 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
442 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
443 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
444 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
445 [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
446 [ -z "$WEBROOT" ] && WEBROOT="$DEFAULT_WEBROOT"
447 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
448 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
449 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
450 [ -z "$build_SVNPATH" ] && build_SVNPATH="$DEFAULT_build_SVNPATH"
451 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
452 [ -z "$TESTMASTER" ] && TESTMASTER="$DEFAULT_TESTMASTER"
454 [ -n "$DRY_RUN" ] && MAILTO=""
456 if [ -n "$OVERBASE" ] ; then
457 sedargs="-e s,@DATE@,${DATE},g"
458 BASE=$(echo ${OVERBASE} | sed $sedargs)
460 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
461 BASE=$(echo ${BASE} | sed $sedargs)
464 ### elaborate mail subject
465 if [ -n "$DO_BUILD" -a -n "$DO_TEST" ] ; then
466 MAIL_SUBJECT="complete"
467 elif [ -n "$DO_BUILD" ] ; then
468 MAIL_SUBJECT="package-only"
469 elif [ -n "$DO_TEST" ] ; then
470 MAIL_SUBJECT="test-only"
472 if [ -n "$OVERBASE" ] ; then
473 MAIL_SUBJECT="$MAIL_SUBJECT incremental run on"
475 MAIL_SUBJECT="$MAIL_SUBJECT fresh build"
478 if ! in_root_context ; then
480 echo "==================== Within vserver BEG $(date)"
482 echo "==================== Within vserver END $(date)"
486 # we run in the root context :
487 # (*) create or check for the vserver to use
488 # (*) copy this command in the vserver
491 if [ -n "$OVERBASE" ] ; then
492 ### Re-use a vserver (finish an unfinished build..)
493 if [ ! -d /vservers/${BASE} ] ; then
494 echo $COMMAND : cannot find vserver $BASE
497 # manage LOG - beware it might be a symlink so nuke it first
498 LOG=/vservers/${BASE}.log.txt
502 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
503 # start in case e.g. we just rebooted
504 vserver ${BASE} start || :
506 vserver ${BASE} exec svn update /build
507 # get environment from the first run
508 FCDISTRO=$(vserver ${BASE} exec /build/getdistroname.sh)
510 PLDISTRO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTRO)
511 PLDISTROTAGS=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PLDISTROTAGS)
512 build_SVNPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +build-SVNPATH)
513 PERSONALITY=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +PERSONALITY)
514 MAILTO=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +MAILTO)
515 WEBPATH=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +WEBPATH)
516 TESTBUILDURL=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +TESTBUILDURL)
517 WEBROOT=$(vserver ${BASE} exec make --no-print-directory -C /build stage1=skip +WEBROOT)
520 # create vserver: check it does not exist yet
522 while [ -d /vservers/${BASE}${i} ] ; do
523 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
524 [ -z ${i} ] && BASE=${BASE}-n
526 if [ $i -gt 100 ] ; then
527 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
533 # manage LOG - beware it might be a symlink so nuke it first
534 LOG=/vservers/${BASE}.log.txt
538 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
541 ### extract the whole build - much simpler
542 tmpdir=/tmp/$COMMAND-$$
543 svn export $build_SVNPATH $tmpdir
546 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
550 # Extract build again - in the vserver
551 vserver ${BASE} exec svn checkout ${build_SVNPATH} /build
553 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
555 # The log inside the vserver contains everything
556 LOG2=/vservers/${BASE}/log.txt
557 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
559 echo "==================== END VSERVER Transcript of vserver creation" ; \
560 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
561 ### not too nice : nuke the former log, symlink it to the new one
562 rm $LOG; ln -s $LOG2 $LOG
567 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
568 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
571 # where to store the log for web access
572 WEBLOG=${WEBPATH}/${BASE}.log.txt
573 # compute the log URL - inserted in the mail messages for convenience
574 LOG_URL=$(echo ${WEBLOG} | sed -e "s,//,/,g" -e "s,${WEBROOT},${TESTBUILDURL},")
575 TESTLOGS_URL=$(echo ${WEBPATH}/${BASE}/testlogs | sed -e "s,//,/,g" -e "s,${WEBROOT},${TESTBUILDURL},")
577 if [ -n "$DO_BUILD" ] ; then
579 cp $COMMANDPATH /vservers/${BASE}/build/
581 # invoke this command in the vserver for building (-T)
582 vserver ${BASE} exec chmod +x /build/$COMMAND
583 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
586 # publish to the web so runtest can find them
587 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
588 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
589 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
590 # publish myplc-release
591 rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
593 # create yum repo and sign packages.
594 if [ -n "$SIGNYUMREPO" ] ; then
598 if [ -n "$DO_TEST" ] ; then