2 REVISION=$(echo '$Revision$' | sed -e 's,\$,,g' -e 's,^\w*:\s,,' )
7 # default values, tunable with command-line options
9 DEFAULT_PLDISTRO=planetlab
10 DEFAULT_PERSONALITY=linux32
11 DEFAULT_BASE="@DATE@--@PLDISTRO@-@FCDISTRO@-@PERSONALITY@"
12 DEFAULT_SVNPATH="http://svn.planet-lab.org/svn/build/trunk"
13 # TESTSVNPATH to be computed from the -tags.mk file - no default anymore
14 DEFAULT_TESTCONFIG="default"
17 # web publishing results
18 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
20 # default gpg path used in signing yum repo
21 DEFAULT_GPGPATH="/etc/planetlab"
22 # default email to use in gpg secring
23 DEFAULT_GPGUID="root@$( /bin/hostname )"
26 TESTBUILDURL="http://build.one-lab.org/"
27 TESTBOXSSH=root@testbox.one-lab.org
29 # assuming vserver runs in UTC
30 DATE=$(date +'%Y.%m.%d')
32 # temporary - wrap a quick summary of suspicious stuff
33 # this is to focus on installation that go wrong
34 # use with care, a *lot* of other things can go bad as well
37 echo "******************** BEG SUMMARY"
40 # read a full log and tries to extract the interesting stuff
43 m_show_line=re.compile(".* BEG (RPM|VSERVER).*|.*'boot'.*|\* .*|.*is not installed.*")
44 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
45 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
46 m_installing_end=re.compile('Installed:.*')
47 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
48 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
50 def summary (filename):
59 for line in f.xreadlines():
60 # first off : discard warnings related to doc
61 if m_installing_doc1.match(line):
62 (begin,end)=m_installing_doc1.match(line).groups()
64 if m_installing_doc2.match(line):
65 (begin,end)=m_installing_doc2.match(line).groups()
67 # unconditionnally show these lines
68 if m_show_line.match(line):
70 # an 'installing' line with messages afterwards : needs to be echoed
71 elif m_installing_err.match(line):
72 (installing,error)=m_installing_err.match(line).groups()
73 print '>>>',installing
76 # closing an 'installing' section
77 elif m_installing_end.match(line):
79 # any 'installing' line
80 elif m_installing_any.match(line):
82 installing=m_installing_any.match(line).group(1)
83 print '>>>',installing
85 # print lines when echo is true
87 if echo: print '>>>',line,
90 print 'Failed to analyze',filename
92 for arg in sys.argv[1:]:
95 echo "******************** END SUMMARY"
99 # Notify recipient of failure or success, manage various stamps
102 WEBLOG=${WEBPATH}/${BASE}.log.txt
105 summary $LOG >> ${WEBLOG}
106 (echo -n "============================== $COMMAND: failure at " ; date ; tail -c 30k $WEBLOG) > ${WEBLOG}.ko
107 if [ -n "$MAILTO" ] ; then
108 tail -c 30k ${WEBLOG} | mail -s "Failures for build ${BASE}" $MAILTO
113 function success () {
115 WEBLOG=${WEBPATH}/${BASE}.log.txt
118 summary $LOG >> ${WEBLOG}
119 if [ -n "$DO_TEST" ] ; then
120 echo "Successfully built and tested - see testlogs for details" > ${WEBLOG}.pass
123 echo "Successfully built"> ${WEBLOG}.ok
125 if [ -n "$MAILTO" ] ; then
126 (echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ) | mail -s "Successful build for ${BASE}" $MAILTO
131 # run in the vserver - do not manage success/failure, will be done from the root ctx
136 echo -n "============================== Starting $COMMAND:build on "
140 # if TAGSRELEASE specified : update PLDISTROTAGS with this tag
141 if [ -n "$TAGSRELEASE" ] ; then
142 svn up -r $TAGSRELEASE $PLDISTROTAGS
147 echo "Running make IN $(pwd)"
149 # stuff our own variable settings
150 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
151 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
152 MAKEVARS=("NIGHTLY_BASE=${BASE}" "${MAKEVARS[@]}")
153 MAKEVARS=("NIGHTLY_PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
154 MAKEVARS=("build-SVNPATH=${SVNPATH}" "${MAKEVARS[@]}")
157 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
159 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
161 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true testsvnpath
163 make -C /build $DRY_RUN "${MAKEVARS[@]}" $MAKETARGETS
167 # this was formerly run in the myplc-devel chroot but now is run in the root context,
168 # this is so that the .ssh config gets done manually, and once and for all
169 function runtest () {
174 echo -n "============================== Starting $COMMAND:runtest on $(date)"
176 # where to find TESTSVNPATH
177 stamp=/vservers/$BASE/build/testsvnpath
178 if [ ! -f $stamp ] ; then
179 echo "$COMMAND: Cannot figure TESTSVNPATH from missing $stamp"
183 TESTSVNPATH=$(cat $stamp)
184 # use only this pat of the tests right now
185 TESTSVNPATH=${TESTSVNPATH}/system
187 ### the URL to the RPMS/<arch> location
189 for a in i386 x86_64; do
190 archdir=/vservers/$BASE/build/RPMS/$a
191 if [ -d $archdir ] ; then
192 url=$(echo $archdir | sed -e "s,/vservers/$BASE/build,${TESTBUILDURL}${PLDISTRO}/${BASE},")
197 if [ -z "$url" ] ; then
198 echo "$COMMAND: Cannot locate arch URL for testing"
203 # test directory name on test box
206 ssh -n ${TESTBOXSSH} rm -rf ${testdir}
208 ssh -n ${TESTBOXSSH} svn co ${TESTSVNPATH} ${testdir}
209 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-vserver.sh
211 for config in ${TESTCONFIG} ; do
212 configs="$configs --config $config"
215 # need to proceed despite of set -e
217 ssh 2>&1 -n ${TESTBOXSSH} ${testdir}/runtest --build ${SVNPATH} --url ${url} $configs --all || success=
219 # gather logs in the vserver
220 mkdir -p /vservers/$BASE/build/testlogs
221 ssh 2>&1 -n ${TESTBOXSSH} tar -C ${testdir}/logs -cf - . | tar -C /vservers/$BASE/build/testlogs -xf - || true
222 # push them to the build web
223 rsync --archive --delete /vservers/$BASE/build/testlogs/ $WEBPATH/$BASE/testlogs/
224 chmod -R a+r $WEBPATH/$BASE/testlogs/
226 if [ -z "$success" ] ; then
230 echo -n "============================== End $COMMAND:runtest on $(date)"
233 function show_env () {
235 echo FCDISTRO=$FCDISTRO
236 echo PLDISTRO=$PLDISTRO
238 echo SVNPATH=$SVNPATH
239 echo MAKEVARS="${MAKEVARS[@]}"
240 echo DRY_RUN="$DRY_RUN"
241 echo PLDISTROTAGS="$PLDISTROTAGS"
242 echo TAGSRELEASE="$TAGSRELEASE"
243 echo -n "(might be unexpanded)"
244 echo WEBPATH="$WEBPATH"
245 if [ -d /vservers ] ; then
246 echo PLDISTROTAGS="$PLDISTROTAGS"
248 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
249 cat /build/$PLDISTROTAGS
250 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
256 echo "Usage: $COMMAND [option] make-targets"
257 echo "This is $REVISION"
258 echo "Supported options"
259 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
260 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
261 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
262 echo " -b base - defaults to $DEFAULT_BASE"
263 echo " @NAME@ replaced as appropriate"
264 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
265 echo " -r tagsrelease - a release number that refers to PLDISTROTAGS - defaults to HEAD"
266 echo " -s svnpath - where to fetch the build module"
267 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
268 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
269 echo " -y create (and sign) yum repo in webpath"
270 echo " -g path to gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
271 echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
272 echo " -m mailto - no default"
273 echo " -O : overwrite - re-run in base directory, do not re-create vserver"
274 echo " -B : run build only"
275 echo " -T : run test only"
276 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
277 echo " -v : be verbose"
278 echo " -7 : uses weekday-@FCDISTRO@ as base"
279 echo " -a makevar=value - space in values are not supported"
280 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
293 while getopts "f:d:p:b:t:r:s:x:c:w:g:u:m:OBTnyv7a:i:" opt ; do
295 f) FCDISTRO=$OPTARG ;;
296 d) PLDISTRO=$OPTARG ;;
297 p) PERSONALITY=$OPTARG ;;
299 t) PLDISTROTAGS=$OPTARG ;;
300 r) TAGSRELEASE=$OPTARG ;;
301 s) SVNPATH=$OPTARG ;;
302 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
303 w) WEBPATH=$OPTARG ;;
304 y) MKYUMREPO=$OPTARG;;
308 O) OVERWRITEMODE=true ;;
310 T) DO_BUILD= ; OVERWRITEMODE=true ;;
313 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
314 a) MAKEVARS=(${MAKEVARS[@]} "$OPTARG") ;;
320 # preserve options for passing them again later, together with expanded base
322 toshift=$(($OPTIND - 1))
323 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
328 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
329 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
330 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
331 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
332 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
333 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
334 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
335 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
336 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
337 [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
338 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
340 [ -n "$DRY_RUN" ] && MAILTO=""
342 ### set BASE from DISTRO, if unspecified
343 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
344 BASE=$(echo ${BASE} | sed $sedargs)
345 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
347 if [ ! -d /vservers ] ; then
349 echo "==================== Within vserver BEG $(date)"
351 echo "==================== Within vserver END $(date)"
355 # we run in the root context :
356 # (*) create or check for the vserver to use
357 # (*) copy this command in the vserver
360 if [ -n "$OVERWRITEMODE" ] ; then
361 ### Re-use a vserver (finish an unfinished build..)
362 if [ ! -d /vservers/${BASE} ] ; then
363 echo $COMMAND : cannot find vserver $BASE
366 # manage LOG - beware it might be a symlink so nuke it first
367 LOG=/vservers/${BASE}.log.txt
371 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
373 # start in case e.g. we just rebooted
374 vserver ${BASE} start || :
376 vserver ${BASE} exec svn update /build
378 # create vserver: check it does not exist yet
380 while [ -d /vservers/${BASE}${i} ] ; do
381 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
382 [ -z ${i} ] && BASE=${BASE}-n
384 if [ $i -gt 100 ] ; then
385 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
391 # manage LOG - beware it might be a symlink so nuke it first
392 LOG=/vservers/${BASE}.log.txt
396 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
399 ### extract the whole build - much simpler
400 tmpdir=/tmp/$COMMAND-$$
401 svn export $SVNPATH $tmpdir
404 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
408 # Extract build again - in the vserver
409 vserver ${BASE} exec svn checkout ${SVNPATH} /build
411 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
413 # The log inside the vserver contains everything
414 LOG2=/vservers/${BASE}/log.txt
415 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
417 echo "==================== END VSERVER Transcript of vserver creation" ; \
418 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
419 ### not too nice : nuke the former log, symlink it to the new one
420 rm $LOG; ln -s $LOG2 $LOG
425 if [ -n "$DO_BUILD" ] ; then
427 cp $COMMANDPATH /vservers/${BASE}/build/
429 # invoke this command in the vserver for building (-T)
430 vserver ${BASE} exec chmod +x /build/$COMMAND
431 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" $MAKETARGETS
434 # publish to the web so runtest can find them
435 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
436 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
437 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
438 # publish myplc-release
439 rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
441 # create yum repo and sign packages.
442 if [ -n $MKYUMREPO ] ; then
443 echo "Signing signing node packages"
445 ### availability of repo indexing tools
446 # old one - might be needed for old-style nodes
447 type -p yum-arch > /dev/null && have_yum_arch="true"
449 type -p createrepo > /dev/null && have_createrepo="true"
451 repository=$WEBPATH/$BASE/RPMS/
452 # the rpms that need signing
454 # and the corresponding stamps
456 # is there a need to refresh yum metadata
460 # right after installation, no package is present
461 # but we still need to create index
462 [ -n "$have_yum_arch" -a ! -f $repository/headers/header.info ] && need_yum_arch=true
463 [ -n "$have_createrepo" -a ! -f $repository/repodata/repomd.xml ] && need_createrepo=true
465 for package in $(find $repository/ -name '*.rpm') ; do
466 stamp=$repository/signed-stamps/$(basename $package).signed
467 # If package is newer than signature stamp
468 if [ $package -nt $stamp ] ; then
469 new_rpms="$new_rpms $package"
470 new_stamps="$new_stamps $stamp"
472 # Or than yum-arch headers
473 [ -n "$have_yum_arch" ] && [ $package -nt $repository/headers/header.info ] && need_yum
475 # Or than createrepo database
476 [ -n "$have_createrepo" ] && [ $package -nt $repository/repodata/repomd.xml ] && need_c
480 if [ -n "$new_rpms" ] ; then
481 # Create a stamp once the package gets signed
482 mkdir $repository/signed-stamps 2> /dev/null
484 # Sign RPMS. setsid detaches rpm from the terminal,
485 # allowing the (hopefully blank) GPG password to be
486 # entered from stdin instead of /dev/tty.
488 --define "_signature gpg" \
489 --define "_gpg_path $GPGPATH" \
490 --define "_gpg_name $GPGUID" \
491 --resign $new_rpms && touch $new_stamps
494 # Update repository index / yum metadata.
496 if [ -n "$need_yum_arch" ] ; then
497 # yum-arch sometimes leaves behind
498 # .oldheaders and .olddata directories accidentally.
499 rm -rf $repository/{.oldheaders,.olddata}
503 if [ -n "$need_createrepo" ] ; then
504 if [ -f $repository/yumgroups.xml ] ; then
505 createrepo --quiet -g yumgroups.xml $repository
507 createrepo --quiet $repository
513 if [ -n "$DO_TEST" ] ; then