6 # old guests have e.g. mount in /bin but this is no longer part of
7 # the standard PATH in recent hosts after usrmove, so let's keep it simple
8 export PATH=$PATH:/bin:/sbin
10 # default values, tunable with command-line options
12 DEFAULT_PLDISTRO=planetlab
13 DEFAULT_PERSONALITY=linux64
14 DEFAULT_BASE="@DATE@--@PLDISTRO@-@FCDISTRO@-@PERSONALITY@"
15 DEFAULT_BUILD_SCM_URL="git://git.onelab.eu/build"
17 # default gpg path used in signing yum repo
18 DEFAULT_GPGPATH="/etc/planetlab"
19 # default email to use in gpg secring
20 DEFAULT_GPGUID="root@$( /bin/hostname )"
22 DEFAULT_TESTCONFIG="default"
23 # for passing args to run_log
26 # for publishing results, and the tests settings
28 y=$(hostname|sed -e s,inria,,)
30 if [ "$x" != "$y" ] ; then
31 DEFAULT_WEBPATH="/build/@PLDISTRO@/"
32 DEFAULT_TESTBUILDURL="http://build.onelab.eu/"
33 # this is where the buildurl is pointing towards
34 DEFAULT_WEBROOT="/build/"
35 DEFAULT_TESTMASTER="testmaster.onelab.eu"
37 DEFAULT_WEBPATH="/build/@FCDISTRO@/@PLDISTRO@/"
38 DEFAULT_TESTBUILDURL="http://build.planet-lab.org/"
39 # this is where the buildurl is pointing towards
40 DEFAULT_WEBROOT="/build/"
41 DEFAULT_TESTMASTER="manager.test.planet-lab.org"
45 # assuming vm runs in UTC
46 DATE=$(date +'%Y.%m.%d')
47 BUILD_BEG=$(date +'%H:%M')
48 BUILD_BEG_S=$(date +'%s')
50 # still using /vservers for legacy reasons
51 # as far as the build & test infra, we could adopt a new name
52 # but the PL code still uses this name for now, so let's keep it simple
59 echo /vservers/$slice.log.txt
62 # wrap a quick summary of suspicious stuff
63 # this is to focus on installation that go wrong
64 # use with care, a *lot* of other things can go bad as well
67 echo "******************** BEG SUMMARY"
70 # read a full log and tries to extract the interesting stuff
73 m_show_line=re.compile(".* (BEG|END) (RPM|LXC).*|.*'boot'.*|\* .*| \* .*|.*is not installed.*|.*PROPFIND.*|.* (BEG|END).*:run_log.*|.* Within LXC (BEG|END) .*|.* MAIN (BEG|END).*")
74 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
75 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
76 m_installing_end=re.compile('Installed:.*')
77 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
78 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
80 def summary (filename):
89 for line in f.xreadlines():
90 # first off : discard warnings related to doc
91 if m_installing_doc1.match(line):
92 (begin,end)=m_installing_doc1.match(line).groups()
94 if m_installing_doc2.match(line):
95 (begin,end)=m_installing_doc2.match(line).groups()
97 # unconditionnally show these lines
98 if m_show_line.match(line):
100 # an 'installing' line with messages afterwards : needs to be echoed
101 elif m_installing_err.match(line):
102 (installing,error)=m_installing_err.match(line).groups()
103 print '>>>',installing
106 # closing an 'installing' section
107 elif m_installing_end.match(line):
109 # any 'installing' line
110 elif m_installing_any.match(line):
112 installing=m_installing_any.match(line).group(1)
113 print '>>>',installing
115 # print lines when echo is true
117 if echo: print '>>>',line,
120 print 'Failed to analyze',filename
122 for arg in sys.argv[1:]:
125 echo "******************** END SUMMARY"
128 ### we might build on a box other than the actual web server
129 # utilities for handling the pushed material (rpms, logfiles, ...)
130 function webpublish_misses_dir () { ssh root@${WEBHOST} "bash -c \"test \! -d $1\"" ; }
131 function webpublish () { ssh root@${WEBHOST} "$@" ; }
132 function webpublish_cp_local_to_remote () { scp $1 root@${WEBHOST}:$2 ; }
133 function webpublish_cp_stdin_to_file () { ssh root@${WEBHOST} cat \> $1; }
134 function webpublish_append_stdin_to_file () { ssh root@${WEBHOST} cat \>\> $1; }
135 # provide remote dir as first argument, so any number of local files can be passed next
136 function webpublish_rsync_dir () { rsync --archive --delete $VERBOSE $2 root@${WEBHOST}:$1 ; }
137 function webpublish_rsync_files () {
139 rsync --archive $VERBOSE "$@" root@${WEBHOST}:"$remote" ;
142 function pretty_duration () {
143 total_seconds=$1; shift
145 seconds=$(($total_seconds%60))
146 total_minutes=$(($total_seconds/60))
147 minutes=$(($total_minutes%60))
148 hours=$(($total_minutes/60))
150 printf "%02d:%02d:%02d" $hours $minutes $seconds
153 # Notify recipient of failure or success, manage various stamps
156 # early stage ? - let's not create /build/@PLDISTRO@
157 if test -z "$WEBLOG" ; then
160 WEBBASE=/tmp/lbuild-early-$(date +%Y-%m-%d)
161 WEBLOG=/tmp/lbuild-early-$(date +%Y-%m-%d).log.txt
163 webpublish mkdir -p $WEBBASE ||:
164 webpublish_cp_local_to_remote $LOG $WEBLOG ||:
165 summary $LOG | webpublish_append_stdin_to_file $WEBLOG ||:
166 (echo -n "============================== $COMMAND: failure at " ; date ; \
167 webpublish tail --lines=1000 $WEBLOG) | \
168 webpublish_cp_stdin_to_file $WEBBASE.ko ||:
169 if [ -n "$MAILTO" ] ; then
171 echo "Subject: KO ${BASE} ${MAIL_SUBJECT}" ; \
172 echo "To: $MAILTO" ; \
173 echo "see build results at $WEBBASE_URL" ; \
174 echo "including full build log at $WEBBASE_URL/log.txt" ; \
175 echo "and complete test logs at $WEBBASE_URL/testlogs" ; \
176 echo "........................................" ; \
177 webpublish tail --lines=1000 $WEBLOG ) | \
183 function success () {
185 # early stage ? - let's not create /build/@PLDISTRO@
186 if test -z "$WEBLOG" ; then
189 WEBLOG=/tmp/lbuild-early-$(date +%Y-%m-%d).log.txt
191 webpublish mkdir -p $WEBBASE
192 webpublish_cp_local_to_remote $LOG $WEBLOG
193 summary $LOG | webpublish_append_stdin_to_file $WEBLOG
194 if [ -n "$DO_TEST" ] ; then
197 if [ -n "$IGNORED" ] ; then short_message="PASS/WARN"; ext="warn"; fi
199 echo "Successfully built and tested" ; \
200 echo "see build results at $WEBBASE_URL" ; \
201 echo "including full build log at $WEBBASE_URL/log.txt" ; \
202 echo "and complete test logs at $WEBBASE_URL/testlogs" ; \
203 [ -n "$IGNORED" ] && echo "WARNING: some tests steps failed but were ignored - see trace file" ; \
204 ) | webpublish_cp_stdin_to_file $WEBBASE.$ext
205 webpublish rm -f $WEBBASE.pkg-ok $WEBBASE.ko
207 short_message="PKGOK"
209 echo "Successful package-only build, no test requested" ; \
210 echo "see build results at $WEBBASE_URL" ; \
211 echo "including full build log at $WEBBASE_URL/log.txt" ; \
212 ) | webpublish_cp_stdin_to_file $WEBBASE.pkg-ok
213 webpublish rm -f $WEBBASE.ko
215 BUILD_END=$(date +'%H:%M')
216 BUILD_END_S=$(date +'%s')
217 if [ -n "$MAILTO" ] ; then
219 echo "Subject: $short_message ${BASE} ${MAIL_SUBJECT}" ; \
220 echo "To: $MAILTO" ; \
221 echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ; \
222 echo "see build results at $WEBBASE_URL" ; \
223 echo "including full build log at $WEBBASE_URL/log.txt" ; \
224 [ -n "$DO_TEST" ] && echo "and complete test logs at $WEBBASE_URL/testlogs" ; \
225 [ -n "$IGNORED" ] && echo "WARNING: some tests steps failed but were ignored - see trace file" ; \
226 echo "BUILD TIME: begin $BUILD_BEG -- end $BUILD_END -- duration $(pretty_duration $(($BUILD_END_S-$BUILD_BEG_S)))" ; \
229 # XXX For some reason, we haven't been getting this email for successful builds. If this sleep
230 # doesn't fix the problem, I'll remove it -- Sapan.
235 ##############################
236 # manage root / container contexts
237 function in_root_context () {
238 rpm -q libvirt > /dev/null
241 # run in the vm - do not manage success/failure, will be done from the root ctx
246 echo -n "============================== Starting $COMMAND:build on "
252 echo "Running make IN $(pwd)"
254 # stuff our own variable settings
255 MAKEVARS=("build-GITPATH=${BUILD_SCM_URL}" "${MAKEVARS[@]}")
256 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
257 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
258 MAKEVARS=("PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
259 MAKEVARS=("MAILTO=${MAILTO}" "${MAKEVARS[@]}")
260 MAKEVARS=("WEBPATH=${WEBPATH}" "${MAKEVARS[@]}")
261 MAKEVARS=("TESTBUILDURL=${TESTBUILDURL}" "${MAKEVARS[@]}")
262 MAKEVARS=("WEBROOT=${WEBROOT}" "${MAKEVARS[@]}")
264 MAKEVARS=("BASE=${BASE}" "${MAKEVARS[@]}")
267 /build/latex-first-run.sh || :
270 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
272 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
274 make -C /build $DRY_RUN "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
278 # this was formerly run in the myplc-devel chroot but now is run in the root context,
279 # this is so that the .ssh config gets done manually, and once and for all
280 function run_log () {
285 echo "============================== BEG $COMMAND:run_log on $(date)"
287 ### the URL to the RPMS/<arch> location
288 # f12 now has everything in i686; try i386 first as older fedoras have both
290 for a in i386 i686 x86_64; do
291 archdir=$(rootdir $BASE)/build/RPMS/$a
292 if [ -d $archdir ] ; then
293 # where was that installed
294 url=$(echo $archdir | sed -e "s,$(rootdir $BASE)/build,${WEBPATH}/${BASE},")
295 url=$(echo $url | sed -e "s,${WEBROOT},${TESTBUILDURL},")
300 if [ -z "$url" ] ; then
301 echo "$COMMAND: Cannot locate arch URL for testing"
306 testmaster_ssh="root@${TESTMASTER}"
308 # test directory name on test box
312 ssh -n ${testmaster_ssh} rm -rf ${testdir} ${testdir}.git
314 # check it out in the build
315 virsh -c lxc:/// lxc-enter-namespace $BASE /bin/bash -c "make -C /build tests-module"
317 # push it onto the testmaster - just the 'system' subdir is enough
318 rsync --verbose --archive $(rootdir $BASE)/build/MODULES/tests/system/ ${testmaster_ssh}:${BASE}
319 # toss the build in the bargain, so the tests don't need to mess with extracting it
320 rsync --verbose --archive $(rootdir $BASE)/build/MODULES/build ${testmaster_ssh}:${BASE}/
322 # invoke test on testbox - pass url and build url - so the tests can use vtest-init-lxc.sh
323 run_log_env="-p $PERSONALITY -d $PLDISTRO -f $FCDISTRO"
325 # temporarily turn off set -e
327 ssh 2>&1 -n ${testmaster_ssh} ${testdir}/run_log --build ${BUILD_SCM_URL} --url ${url} $run_log_env $RUN_LOG_EXTRAS $VERBOSE --all; retcod=$?
330 # interpret retcod of TestMain.py; 2 means there were ignored steps that failed
331 echo "received from run_log" $retcod
333 0) success=true; IGNORED="" ;;
334 2) success=true; IGNORED=true ;;
335 *) success=""; IGNORED="" ;;
338 # gather logs in the build vm
339 mkdir -p $(rootdir $BASE)/build/testlogs
340 rsync --verbose --archive ${testmaster_ssh}:$BASE/logs/ $(rootdir $BASE)/build/testlogs
341 # push them to the build web
342 chmod -R a+r $(rootdir $BASE)/build/testlogs/
343 webpublish_rsync_dir $WEBPATH/$BASE/testlogs/ $(rootdir $BASE)/build/testlogs/
345 echo "============================== END $COMMAND:run_log on $(date)"
347 if [ -z "$success" ] ; then
348 echo "Tests have failed - bailing out"
354 # this part won't work if WEBHOST does not match the local host
355 # would need to be made webpublish_* compliant
356 # but do we really need this feature anyway ?
357 function sign_node_packages () {
359 echo "Signing node packages"
363 repository=$WEBPATH/$BASE/RPMS/
364 # the rpms that need signing
366 # and the corresponding stamps
369 for package in $(find $repository/ -name '*.rpm') ; do
370 stamp=$repository/signed-stamps/$(basename $package).signed
371 # If package is newer than signature stamp
372 if [ $package -nt $stamp ] ; then
373 new_rpms="$new_rpms $package"
374 new_stamps="$new_stamps $stamp"
376 # Or than createrepo database
377 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
380 if [ -n "$new_rpms" ] ; then
381 # Create a stamp once the package gets signed
382 mkdir $repository/signed-stamps 2> /dev/null
384 # Sign RPMS. setsid detaches rpm from the terminal,
385 # allowing the (hopefully blank) GPG password to be
386 # entered from stdin instead of /dev/tty.
388 --define "_signature gpg" \
389 --define "_gpg_path $GPGPATH" \
390 --define "_gpg_name $GPGUID" \
391 --resign $new_rpms && touch $new_stamps
394 # Update repository index / yum metadata.
395 if [ -n "$need_createrepo" ] ; then
396 echo "Indexing node packages after signing"
397 if [ -f $repository/yumgroups.xml ] ; then
398 createrepo --quiet -g yumgroups.xml $repository
400 createrepo --quiet $repository
405 function show_env () {
407 echo FCDISTRO=$FCDISTRO
408 echo PLDISTRO=$PLDISTRO
409 echo PERSONALITY=$PERSONALITY
411 echo BUILD_SCM_URL=$BUILD_SCM_URL
412 echo MAKEVARS="${MAKEVARS[@]}"
413 echo DRY_RUN="$DRY_RUN"
414 echo PLDISTROTAGS="$PLDISTROTAGS"
415 # this does not help, it's not yet set when we run show_env
416 #echo WEBPATH="$WEBPATH"
417 echo TESTBUILDURL="$TESTBUILDURL"
418 echo WEBHOST="$WEBHOST"
419 if in_root_context ; then
420 echo PLDISTROTAGS="$PLDISTROTAGS"
422 if [ -f /build/$PLDISTROTAGS ] ; then
423 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
424 cat /build/$PLDISTROTAGS
425 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
427 echo "XXXXXXXXXXXXXXXXXXXX Cannot find tags definition file /build/$PLDISTROTAGS, assuming remote pldistro"
433 function setupssh () {
437 if [ -f ${sshkey} ] ; then
438 SSHDIR=$(rootdir ${base})/root/.ssh
440 cp $sshkey ${SSHDIR}/thekey
442 echo " IdentityFile ~/.ssh/thekey"; \
443 echo " StrictHostKeyChecking no" ) > ${SSHDIR}/config
445 chmod 400 ${SSHDIR}/*
447 echo "WARNING : could not find provided ssh key $sshkey - ignored"
452 echo "Usage: $COMMAND [option] [var=value...] make-targets"
453 echo "Supported options"
454 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
455 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
456 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
457 echo " -m mailto - no default"
458 echo " -s build_scm_url - git URL where to fetch the build module - defaults to $DEFAULT_BUILD_SCM_URL"
459 echo " define GIT tag or branch name appending @tagname to url"
460 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
461 echo " -b base - defaults to $DEFAULT_BASE"
462 echo " @NAME@ replaced as appropriate"
463 echo " -o base: (overwrite) do not re-create vm, re-use base instead"
464 echo " the -f/-d/-p/-m/-s/-t options are uneffective in this case"
465 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
466 echo " -y {pl,pg} - passed to run_log"
467 echo " -e step - passed to run_log"
468 echo " -i step - passed to run_log"
469 echo " -X : passes --lxc to run_log"
470 echo " -S : passes --vs to run_log"
471 echo " -x <run_log_args> - a hook to pass other arguments to run_log"
472 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
473 echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL; this is also used to get the hostname where to publish builds"
474 echo " -r webroot - defaults to $DEFAULT_WEBROOT - the fs point where testbuildurl actually sits"
475 echo " -M testmaster - defaults to $DEFAULT_TESTMASTER"
476 echo " -Y - sign yum repo in webpath"
477 echo " -g gpg_path - to the gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
478 echo " -u gpg_uid - email used in secring. Defaults to $DEFAULT_GPGUID"
479 echo " -K sshkey - specify ssh key to use when reaching git over ssh"
480 echo " -S - do not publish source rpms"
481 echo " -B - run build only"
482 echo " -T - run test only"
483 echo " -n - dry-run: -n passed to make - vm gets created though - no mail sent"
484 echo " -v - be verbose"
485 echo " -7 - uses weekday-@FCDISTRO@ as base"
486 echo " --build-branch branch - build using the branch from build module"
505 OPTS=$(getopt -o "f:d:p:m:s:t:b:o:c:y:e:i:XSx:w:W:r:M:Yg:u:K:SBTnv7i:P:h" -l "build-branch:" -- $@)
513 -f) FCDISTRO=$2; shift 2 ;;
514 -d) PLDISTRO=$2; shift 2 ;;
515 -p) PERSONALITY=$2; shift 2 ;;
516 -m) MAILTO=$2; shift 2 ;;
517 -s) BUILD_SCM_URL=$2; shift 2 ;;
518 -t) PLDISTROTAGS=$2; shift 2 ;;
519 -b) BASE=$2; shift 2 ;;
520 -o) OVERBASE=$2; shift 2 ;;
521 -c) TESTCONFIG="$TESTCONFIG $2"; shift 2 ;;
522 ########## passing stuff to run_log
523 # -y foo -> run_log -y foo
524 -y) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --rspec-style $2"; shift 2 ;;
525 # -e foo -> run_log -e foo
526 -e) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --exclude $2"; shift 2 ;;
527 -i) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --ignore $2"; shift 2 ;;
528 # -X -> run_log --lxc
529 -X) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --lxc"; shift;;
531 -S) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --vs"; shift;;
532 # more general form to pass args to run_log
533 # -x foo -> run_log foo
534 -x) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS $2"; shift 2;;
536 -w) WEBPATH=$2; shift 2 ;;
537 -W) TESTBUILDURL=$2; shift 2 ;;
538 -r) WEBROOT=$2; shift 2 ;;
539 -M) TESTMASTER=$2; shift 2 ;;
540 -Y) SIGNYUMREPO=true; shift ;;
541 -g) GPGPATH=$2; shift 2 ;;
542 -u) GPGUID=$2; shift 2 ;;
543 -K) SSH_KEY=$2; shift 2 ;;
544 -S) PUBLISH_SRPMS="" ; shift ;;
545 -B) DO_TEST= ; shift ;;
546 -T) DO_BUILD= ; shift;;
547 -n) DRY_RUN="-n" ; shift ;;
548 -v) set -x ; VERBOSE="-v" ; shift ;;
549 -7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ; shift ;;
550 -P) PREINSTALLED="-P $2"; shift 2;;
556 # preserve options for passing them again later, together with expanded base
559 # allow var=value stuff;
560 for target in "$@" ; do
561 # check if contains '='
562 target1=$(echo $target | sed -e s,=,,)
563 if [ "$target" = "$target1" ] ; then
564 MAKETARGETS=(${MAKETARGETS[@]} "$target")
566 MAKEVARS=(${MAKEVARS[@]} "$target")
571 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
572 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
573 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
574 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
575 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
576 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
577 [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
578 [ -z "$WEBROOT" ] && WEBROOT="$DEFAULT_WEBROOT"
579 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
580 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
581 [ -z "$BUILD_SCM_URL" ] && BUILD_SCM_URL="$DEFAULT_BUILD_SCM_URL"
582 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
583 [ -z "$TESTMASTER" ] && TESTMASTER="$DEFAULT_TESTMASTER"
585 [ -n "$DRY_RUN" ] && MAILTO=""
587 # elaborate the extra args to be passed to run_log
588 for config in ${TESTCONFIG} ; do
589 RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --config $config"
593 if [ -n "$OVERBASE" ] ; then
594 sedargs="-e s,@DATE@,${DATE},g"
595 BASE=$(echo ${OVERBASE} | sed $sedargs)
597 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
598 BASE=$(echo ${BASE} | sed $sedargs)
601 ### elaborate mail subject
602 if [ -n "$DO_BUILD" -a -n "$DO_TEST" ] ; then
604 elif [ -n "$DO_BUILD" ] ; then
605 MAIL_SUBJECT="pkg-only"
606 elif [ -n "$DO_TEST" ] ; then
607 MAIL_SUBJECT="test-only"
609 if [ -n "$OVERBASE" ] ; then
610 MAIL_SUBJECT="${MAIL_SUBJECT} rerun"
612 MAIL_SUBJECT="${MAIL_SUBJECT} fresh"
614 short_hostname=$(hostname | cut -d. -f1)
615 MAIL_SUBJECT="on ${short_hostname} - ${MAIL_SUBJECT}"
617 ### compute WEBHOST from TESTBUILDURL
618 # this is to avoid having to change the builds configs everywhere
619 # simplistic way to extract hostname from a URL
620 WEBHOST=$(echo "$TESTBUILDURL" | cut -d/ -f 3)
622 if ! in_root_context ; then
624 echo "==================== Within LXC BEG $(date)"
626 echo "==================== Within LXC END $(date)"
630 # we run in the root context :
631 # (*) create or check for the vm to use
632 # (*) copy this command in the vm
635 if [ -n "$OVERBASE" ] ; then
636 ### Re-use a vm (finish an unfinished build..)
637 if [ ! -d $(rootdir ${BASE}) ] ; then
638 echo $COMMAND : cannot find vm $BASE
641 # manage LOG - beware it might be a symlink so nuke it first
642 LOG=$(logfile ${BASE})
646 echo "XXXXXXXXXX $COMMAND: using existing vm $BASE" $(date)
647 # start in case e.g. we just rebooted
648 virsh -c lxc:/// start ${BASE} || :
649 # retrieve environment from the previous run
650 FCDISTRO=$(virsh -c lxc:/// lxc-enter-namespace ${BASE} /build/getdistroname.sh)
651 BUILD_SCM_URL=$(virsh -c lxc:/// lxc-enter-namespace ${BASE} /bin/bash -c "make --no-print-directory -C /build stage1=skip +build-GITPATH")
652 # for efficiency, crop everything in one make run
653 tmp=/tmp/${BASE}-env.sh
654 virsh -c lxc:/// lxc-enter-namespace ${BASE} /bin/bash -c "make --no-print-directory -C /build stage1=skip \
655 ++PLDISTRO ++PLDISTROTAGS ++PERSONALITY ++MAILTO ++WEBPATH ++TESTBUILDURL ++WEBROOT" > $tmp
659 [ -n "$SSH_KEY" ] && setupssh ${BASE} ${SSH_KEY}
660 virsh -c lxc:/// lxc-enter-namespace $BASE /bin/bash -c "cd /build; git pull; make tests-clean"
661 # make sure we refresh the tests place in case it has changed
662 rm -f /build/MODULES/tests
663 options=(${options[@]} -d $PLDISTRO -t $PLDISTROTAGS -s $BUILD_SCM_URL)
664 [ -n "$PERSONALITY" ] && options=(${options[@]} -p $PERSONALITY)
665 [ -n "$MAILTO" ] && options=(${options[@]} -m $MAILTO)
666 [ -n "$WEBPATH" ] && options=(${options[@]} -w $WEBPATH)
667 [ -n "$TESTBUILDURL" ] && options=(${options[@]} -W $TESTBUILDURL)
668 [ -n "$WEBROOT" ] && options=(${options[@]} -r $WEBROOT)
671 # create vm: check it does not exist yet
673 while [ -d $(rootdir ${BASE})${i} ] ; do
674 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
675 [ -z ${i} ] && BASE=${BASE}-n
677 if [ $i -gt 100 ] ; then
678 echo "$COMMAND: Failed to create build vm $(rootdir ${BASE})${i}"
684 # manage LOG - beware it might be a symlink so nuke it first
685 LOG=$(logfile ${BASE})
689 echo "XXXXXXXXXX $COMMAND: creating vm $BASE" $(date)
692 ### extract the whole build - much simpler
693 tmpdir=/tmp/$COMMAND-$$
694 GIT_REPO=$(echo $BUILD_SCM_URL | cut -d@ -f1)
695 GIT_TAG=$(echo $BUILD_SCM_URL | cut -s -d@ -f2)
696 GIT_TAG=${GIT_TAG:-master}
697 mkdir -p $tmpdir; git archive --remote=$GIT_REPO $GIT_TAG | tar -C $tmpdir -xf -
701 ./lbuild-initvm.sh $VERBOSE -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} ${PREINSTALLED} ${BASE}
705 # Extract build again - in the vm
706 [ -n "$SSH_KEY" ] && setupssh ${BASE} ${SSH_KEY}
707 # xxx not working as of now - waiting for Sapan to look into this
708 virsh -c lxc:/// lxc-enter-namespace $BASE /bin/bash -c "git clone $GIT_REPO /build; cd /build; git checkout $GIT_TAG"
710 echo "XXXXXXXXXX $COMMAND: preparation of vm $BASE done" $(date)
712 # The log inside the vm contains everything
713 LOG2=$(rootdir ${BASE})/log.txt
714 (echo "==================== BEG LXC Transcript of vm creation" ; \
716 echo "==================== END LXC Transcript of vm creation" ; \
717 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
718 ### not too nice : nuke the former log, symlink it to the new one
719 rm $LOG; ln -s $LOG2 $LOG
724 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
725 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
726 webpublish mkdir -p ${WEBPATH}
728 # where to store the log for web access
729 WEBBASE=${WEBPATH}/${BASE}
730 WEBLOG=${WEBPATH}/${BASE}/log.txt
731 # compute the log URL - inserted in the mail messages for convenience
732 WEBBASE_URL=$(echo $WEBBASE | sed -e "s,//,/,g" -e "s,${WEBROOT},${TESTBUILDURL},")
734 if [ -n "$DO_BUILD" ] ; then
736 # invoke this command into the build directory of the vm
737 cp $COMMANDPATH $(rootdir ${BASE})/build/
739 # invoke this command in the vm for building (-T)
740 virsh -c lxc:/// lxc-enter-namespace ${BASE} /bin/bash -c "chmod +x /build/$COMMAND"
741 virsh -c lxc:/// lxc-enter-namespace ${BASE} /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
744 # publish to the web so run_log can find them
746 webpublish rm -rf $WEBPATH/$BASE
747 # guess if we've been doing any debian-related build
748 if [ ! -f $(rootdir $BASE)/etc/debian_version ] ; then
749 webpublish mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
750 webpublish_rsync_dir $WEBPATH/$BASE/RPMS/ $(rootdir $BASE)/build/RPMS/
751 [[ -n "$PUBLISH_SRPMS" ]] && webpublish_rsync_dir $WEBPATH/$BASE/SRPMS/ $(rootdir $BASE)/build/SRPMS/
753 # run scanpackages so we can use apt-get on this
754 # (not needed on fedora b/c this is done by the regular build already)
755 virsh -c lxc:/// lxc-enter-namespace $BASE /bin/bash -c "(cd /build ; dpkg-scanpackages DEBIAN/ | gzip -9c > Packages.gz)"
756 webpublish mkdir -p $WEBPATH/$BASE/DEBIAN
757 webpublish_rsync_files $WEBPATH/$BASE/DEBIAN/ $(rootdir $BASE)/build/DEBIAN/*.deb
758 webpublish_rsync_files $WEBPATH/$BASE/ $(rootdir $BASE)/build/Packages.gz
760 # publish myplc-release if this exists
761 release=$(rootdir $BASE)/build/myplc-release
762 [ -f $release ] && webpublish_rsync_files $WEBPATH/$BASE $release
765 # create yum repo and sign packages.
766 if [ -n "$SIGNYUMREPO" ] ; then
767 # this script does not yet support signing on a remote (webhost) repo
768 sign_here=$(hostname) ; sign_web=$(webpublish hostname)
769 if [ "$hostname" = "$sign_here" ] ; then
772 echo "$COMMAND does not support signing on a remote yum repo"
773 echo "you might want to turn off the -y option, or run this on the web server box itself"
778 if [ -n "$DO_TEST" ] ; then
784 echo "==================== MAIN END $(date)"