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 in_root_context () {
234 rpm -q util-vserver > /dev/null
237 function show_env () {
239 echo FCDISTRO=$FCDISTRO
240 echo PLDISTRO=$PLDISTRO
242 echo SVNPATH=$SVNPATH
243 echo MAKEVARS="${MAKEVARS[@]}"
244 echo DRY_RUN="$DRY_RUN"
245 echo PLDISTROTAGS="$PLDISTROTAGS"
246 echo TAGSRELEASE="$TAGSRELEASE"
247 echo -n "(might be unexpanded)"
248 echo WEBPATH="$WEBPATH"
249 if in_root_context ; then
250 echo PLDISTROTAGS="$PLDISTROTAGS"
252 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
253 cat /build/$PLDISTROTAGS
254 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
260 echo "Usage: $COMMAND [option] make-targets"
261 echo "This is $REVISION"
262 echo "Supported options"
263 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
264 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
265 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
266 echo " -b base - defaults to $DEFAULT_BASE"
267 echo " @NAME@ replaced as appropriate"
268 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
269 echo " -r tagsrelease - a release number that refers to PLDISTROTAGS - defaults to HEAD"
270 echo " -s svnpath - where to fetch the build module"
271 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
272 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
273 echo " -y create (and sign) yum repo in webpath"
274 echo " -g path to gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
275 echo " -u gpg email used in secring. Defaults to $DEFAULT_GPGUID"
276 echo " -m mailto - no default"
277 echo " -O : overwrite - re-run in base directory, do not re-create vserver"
278 echo " -B : run build only"
279 echo " -T : run test only"
280 echo " -n dry-run : -n passed to make - vserver gets created though - no mail sent"
281 echo " -v : be verbose"
282 echo " -7 : uses weekday-@FCDISTRO@ as base"
283 echo " -a makevar=value - space in values are not supported"
284 echo " -i ifname - defaults to $DEFAULT_IFNAME - used to determine local IP"
297 while getopts "f:d:p:b:t:r:s:x:c:w:g:u:m:OBTnyv7a:i:" opt ; do
299 f) FCDISTRO=$OPTARG ;;
300 d) PLDISTRO=$OPTARG ;;
301 p) PERSONALITY=$OPTARG ;;
303 t) PLDISTROTAGS=$OPTARG ;;
304 r) TAGSRELEASE=$OPTARG ;;
305 s) SVNPATH=$OPTARG ;;
306 c) TESTCONFIG="$TESTCONFIG $OPTARG" ;;
307 w) WEBPATH=$OPTARG ;;
308 y) MKYUMREPO=$OPTARG;;
312 O) OVERWRITEMODE=true ;;
314 T) DO_BUILD= ; OVERWRITEMODE=true ;;
317 7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ;;
318 a) MAKEVARS=(${MAKEVARS[@]} "$OPTARG") ;;
324 # preserve options for passing them again later, together with expanded base
326 toshift=$(($OPTIND - 1))
327 arg=1; while [ $arg -le $toshift ] ; do options=(${options[@]} "$1") ; shift; arg=$(($arg+1)) ; done
332 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
333 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
334 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
335 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
336 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
337 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
338 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
339 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
340 [ -z "$IFNAME" ] && IFNAME="$DEFAULT_IFNAME"
341 [ -z "$SVNPATH" ] && SVNPATH="$DEFAULT_SVNPATH"
342 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
344 [ -n "$DRY_RUN" ] && MAILTO=""
346 ### set BASE from DISTRO, if unspecified
347 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
348 BASE=$(echo ${BASE} | sed $sedargs)
349 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
351 if ! in_root_context ; then
353 echo "==================== Within vserver BEG $(date)"
355 echo "==================== Within vserver END $(date)"
359 # we run in the root context :
360 # (*) create or check for the vserver to use
361 # (*) copy this command in the vserver
364 if [ -n "$OVERWRITEMODE" ] ; then
365 ### Re-use a vserver (finish an unfinished build..)
366 if [ ! -d /vservers/${BASE} ] ; then
367 echo $COMMAND : cannot find vserver $BASE
370 # manage LOG - beware it might be a symlink so nuke it first
371 LOG=/vservers/${BASE}.log.txt
375 echo "XXXXXXXXXX $COMMAND: using existing vserver $BASE" $(date)
377 # start in case e.g. we just rebooted
378 vserver ${BASE} start || :
380 vserver ${BASE} exec svn update /build
382 # create vserver: check it does not exist yet
384 while [ -d /vservers/${BASE}${i} ] ; do
385 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
386 [ -z ${i} ] && BASE=${BASE}-n
388 if [ $i -gt 100 ] ; then
389 echo "$COMMAND: Failed to create build vserver /vservers/${BASE}${i}"
395 # manage LOG - beware it might be a symlink so nuke it first
396 LOG=/vservers/${BASE}.log.txt
400 echo "XXXXXXXXXX $COMMAND: creating vserver $BASE" $(date)
403 ### extract the whole build - much simpler
404 tmpdir=/tmp/$COMMAND-$$
405 svn export $SVNPATH $tmpdir
408 ./vbuild-init-vserver.sh -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} -i ${IFNAME} ${BASE}
412 # Extract build again - in the vserver
413 vserver ${BASE} exec svn checkout ${SVNPATH} /build
415 echo "XXXXXXXXXX $COMMAND: preparation of vserver $BASE done" $(date)
417 # The log inside the vserver contains everything
418 LOG2=/vservers/${BASE}/log.txt
419 (echo "==================== BEG VSERVER Transcript of vserver creation" ; \
421 echo "==================== END VSERVER Transcript of vserver creation" ; \
422 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
423 ### not too nice : nuke the former log, symlink it to the new one
424 rm $LOG; ln -s $LOG2 $LOG
429 if [ -n "$DO_BUILD" ] ; then
431 cp $COMMANDPATH /vservers/${BASE}/build/
433 # invoke this command in the vserver for building (-T)
434 vserver ${BASE} exec chmod +x /build/$COMMAND
435 vserver ${BASE} exec /build/$COMMAND "${options[@]}" -b "${BASE}" $MAKETARGETS
438 # publish to the web so runtest can find them
439 rm -rf $WEBPATH/$BASE ; mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
440 rsync --archive --delete --verbose /vservers/$BASE/build/RPMS/ $WEBPATH/$BASE/RPMS/
441 rsync --archive --delete --verbose /vservers/$BASE/build/SRPMS/ $WEBPATH/$BASE/SRPMS/
442 # publish myplc-release
443 rsync --verbose /vservers/$BASE/build/myplc-release $WEBPATH/$BASE
445 # create yum repo and sign packages.
446 if [ -n $MKYUMREPO ] ; then
447 echo "Signing signing node packages"
449 ### availability of repo indexing tools
450 # old one - might be needed for old-style nodes
451 type -p yum-arch > /dev/null && have_yum_arch="true"
453 type -p createrepo > /dev/null && have_createrepo="true"
455 repository=$WEBPATH/$BASE/RPMS/
456 # the rpms that need signing
458 # and the corresponding stamps
460 # is there a need to refresh yum metadata
464 # right after installation, no package is present
465 # but we still need to create index
466 [ -n "$have_yum_arch" -a ! -f $repository/headers/header.info ] && need_yum_arch=true
467 [ -n "$have_createrepo" -a ! -f $repository/repodata/repomd.xml ] && need_createrepo=true
469 for package in $(find $repository/ -name '*.rpm') ; do
470 stamp=$repository/signed-stamps/$(basename $package).signed
471 # If package is newer than signature stamp
472 if [ $package -nt $stamp ] ; then
473 new_rpms="$new_rpms $package"
474 new_stamps="$new_stamps $stamp"
476 # Or than yum-arch headers
477 [ -n "$have_yum_arch" ] && [ $package -nt $repository/headers/header.info ] && need_yum
479 # Or than createrepo database
480 [ -n "$have_createrepo" ] && [ $package -nt $repository/repodata/repomd.xml ] && need_c
484 if [ -n "$new_rpms" ] ; then
485 # Create a stamp once the package gets signed
486 mkdir $repository/signed-stamps 2> /dev/null
488 # Sign RPMS. setsid detaches rpm from the terminal,
489 # allowing the (hopefully blank) GPG password to be
490 # entered from stdin instead of /dev/tty.
492 --define "_signature gpg" \
493 --define "_gpg_path $GPGPATH" \
494 --define "_gpg_name $GPGUID" \
495 --resign $new_rpms && touch $new_stamps
498 # Update repository index / yum metadata.
500 if [ -n "$need_yum_arch" ] ; then
501 # yum-arch sometimes leaves behind
502 # .oldheaders and .olddata directories accidentally.
503 rm -rf $repository/{.oldheaders,.olddata}
507 if [ -n "$need_createrepo" ] ; then
508 if [ -f $repository/yumgroups.xml ] ; then
509 createrepo --quiet -g yumgroups.xml $repository
511 createrepo --quiet $repository
517 if [ -n "$DO_TEST" ] ; then