6 # close stdin, as with ubuntu and debian VMs this script tends to hang and wait for input ..
9 # old guests have e.g. mount in /bin but this is no longer part of
10 # the standard PATH in recent hosts after usrmove, so let's keep it simple
11 export PATH=$PATH:/bin:/sbin
13 # default values, tunable with command-line options
16 DEFAULT_PERSONALITY=linux64
17 DEFAULT_MAILDEST="build at onelab.eu"
18 DEFAULT_BUILD_SCM_URL="git://git.onelab.eu/build"
19 DEFAULT_BASE="@DATE@--@PLDISTRO@-@FCDISTRO@-@PERSONALITY@"
21 # default gpg path used in signing yum repo
22 DEFAULT_GPGPATH="/etc/planetlab"
23 # default email to use in gpg secring
24 DEFAULT_GPGUID="root@$( /bin/hostname )"
26 DEFAULT_TESTCONFIG="default"
27 # for passing args to run_log
30 # for publishing results, and the tests settings
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"
38 # assuming vm runs in UTC
39 DATE=$(date +'%Y.%m.%d')
40 BUILD_BEG=$(date +'%H:%M')
41 BUILD_BEG_S=$(date +'%s')
43 # still using /vservers for legacy reasons
44 # as far as the build & test infra, we could adopt a new name
45 # but the PL code still uses this name for now, so let's keep it simple
52 echo /vservers/$slice.log.txt
55 # wrap a quick summary of suspicious stuff
56 # this is to focus on installation that go wrong
57 # use with care, a *lot* of other things can go bad as well
60 echo "******************** BEG SUMMARY"
63 # read a full log and tries to extract the interesting stuff
66 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).*")
67 m_installing_any=re.compile('\r (Installing:[^\]]*]) ')
68 m_installing_err=re.compile('\r (Installing:[^\]]*])(..+)')
69 m_installing_end=re.compile('Installed:.*')
70 m_installing_doc1=re.compile("(.*)install-info: No such file or directory for /usr/share/info/\S+(.*)")
71 m_installing_doc2=re.compile("(.*)grep: /usr/share/info/dir: No such file or directory(.*)")
73 def summary (filename):
82 for line in f.xreadlines():
83 # first off : discard warnings related to doc
84 if m_installing_doc1.match(line):
85 (begin,end)=m_installing_doc1.match(line).groups()
87 if m_installing_doc2.match(line):
88 (begin,end)=m_installing_doc2.match(line).groups()
90 # unconditionnally show these lines
91 if m_show_line.match(line):
93 # an 'installing' line with messages afterwards : needs to be echoed
94 elif m_installing_err.match(line):
95 (installing,error)=m_installing_err.match(line).groups()
96 print '>>>',installing
99 # closing an 'installing' section
100 elif m_installing_end.match(line):
102 # any 'installing' line
103 elif m_installing_any.match(line):
105 installing=m_installing_any.match(line).group(1)
106 print '>>>',installing
108 # print lines when echo is true
110 if echo: print '>>>',line,
113 print 'Failed to analyze',filename
115 for arg in sys.argv[1:]:
118 echo "******************** END SUMMARY"
121 ### we might build on a box other than the actual web server
122 # utilities for handling the pushed material (rpms, logfiles, ...)
123 function webpublish_misses_dir () { ssh root@${WEBHOST} "bash -c \"test \! -d $1\"" ; }
124 function webpublish () { ssh root@${WEBHOST} "$@" ; }
125 function webpublish_cp_local_to_remote () { scp $1 root@${WEBHOST}:$2 ; }
126 function webpublish_cp_stdin_to_file () { ssh root@${WEBHOST} cat \> $1; }
127 function webpublish_append_stdin_to_file () { ssh root@${WEBHOST} cat \>\> $1; }
128 # provide remote dir as first argument, so any number of local files can be passed next
129 function webpublish_rsync_dir () { rsync --archive --delete $VERBOSE $2 root@${WEBHOST}:$1 ; }
130 function webpublish_rsync_files () {
132 rsync --archive $VERBOSE "$@" root@${WEBHOST}:"$remote" ;
135 function pretty_duration () {
136 total_seconds=$1; shift
138 seconds=$(($total_seconds%60))
139 total_minutes=$(($total_seconds/60))
140 minutes=$(($total_minutes%60))
141 hours=$(($total_minutes/60))
143 printf "%02d:%02d:%02d" $hours $minutes $seconds
146 # Notify recipient of failure or success, manage various stamps
149 # early stage ? - let's not create /build/@PLDISTRO@
150 if [ -z "$WEBLOG" ] ; then
153 WEBBASE=/tmp/lbuild-early-$(date +%Y-%m-%d)
154 WEBLOG=/tmp/lbuild-early-$(date +%Y-%m-%d).log.txt
156 webpublish mkdir -p $WEBBASE ||:
157 webpublish_cp_local_to_remote $LOG $WEBLOG ||:
158 summary $LOG | webpublish_append_stdin_to_file $WEBLOG ||:
159 (echo -n "============================== $COMMAND: failure at " ; date ; \
160 webpublish tail --lines=1000 $WEBLOG) | \
161 webpublish_cp_stdin_to_file $WEBBASE.ko ||:
162 if [ -n "$MAILDEST" ] ; then
164 echo "Subject: KO ${BASE} ${MAIL_SUBJECT}" ; \
165 echo "To: $MAILDEST" ; \
166 echo "see build results at $WEBBASE_URL" ; \
167 echo "including full build log at $WEBBASE_URL/log.txt" ; \
168 echo "and complete test logs at $WEBBASE_URL/testlogs" ; \
169 echo "........................................" ; \
170 webpublish tail --lines=1000 $WEBLOG ) | \
176 function success () {
178 # early stage ? - let's not create /build/@PLDISTRO@
179 if [ -z "$WEBLOG" ] ; then
182 WEBLOG=/tmp/lbuild-early-$(date +%Y-%m-%d).log.txt
184 webpublish mkdir -p $WEBBASE
185 webpublish_cp_local_to_remote $LOG $WEBLOG
186 summary $LOG | webpublish_append_stdin_to_file $WEBLOG
187 if [ -n "$DO_TEST" ] ; then
190 if [ -n "$IGNORED" ] ; then short_message="PASS/WARN"; ext="warn"; fi
192 echo "Successfully built and tested" ; \
193 echo "see build results at $WEBBASE_URL" ; \
194 echo "including full build log at $WEBBASE_URL/log.txt" ; \
195 echo "and complete test logs at $WEBBASE_URL/testlogs" ; \
196 [ -n "$IGNORED" ] && echo "WARNING: some tests steps failed but were ignored - see trace file" ; \
197 ) | webpublish_cp_stdin_to_file $WEBBASE.$ext
198 webpublish rm -f $WEBBASE.pkg-ok $WEBBASE.ko
200 short_message="PKGOK"
202 echo "Successful package-only build, no test requested" ; \
203 echo "see build results at $WEBBASE_URL" ; \
204 echo "including full build log at $WEBBASE_URL/log.txt" ; \
205 ) | webpublish_cp_stdin_to_file $WEBBASE.pkg-ok
206 webpublish rm -f $WEBBASE.ko
208 BUILD_END=$(date +'%H:%M')
209 BUILD_END_S=$(date +'%s')
210 if [ -n "$MAILDEST" ] ; then
212 echo "Subject: $short_message ${BASE} ${MAIL_SUBJECT}" ; \
213 echo "To: $MAILDEST" ; \
214 echo "$PLDISTRO ($BASE) build for $FCDISTRO completed on $(date)" ; \
215 echo "see build results at $WEBBASE_URL" ; \
216 echo "including full build log at $WEBBASE_URL/log.txt" ; \
217 [ -n "$DO_TEST" ] && echo "and complete test logs at $WEBBASE_URL/testlogs" ; \
218 [ -n "$IGNORED" ] && echo "WARNING: some tests steps failed but were ignored - see trace file" ; \
219 echo "BUILD TIME: begin $BUILD_BEG -- end $BUILD_END -- duration $(pretty_duration $(($BUILD_END_S-$BUILD_BEG_S)))" ; \
220 ) | sendmail $MAILDEST
222 # XXX For some reason, we haven't been getting this email for successful builds. If this sleep
223 # doesn't fix the problem, I'll remove it -- Sapan.
228 ##############################
229 # manage root / container contexts
230 function in_root_context () {
231 rpm -q libvirt > /dev/null
234 # convenient for simple commands
235 function run_in_build_guest () {
237 ssh -o "StrictHostKeyChecking no" root@$(guest_ipv4 $buildname) "$@"
240 # run in the vm - do not manage success/failure, will be done from the root ctx
245 echo -n "============================== Starting $COMMAND:build on "
251 echo "Running make IN $(pwd)"
253 # stuff our own variable settings
254 MAKEVARS=("build-GITPATH=${BUILD_SCM_URL}" "${MAKEVARS[@]}")
255 MAKEVARS=("PLDISTRO=${PLDISTRO}" "${MAKEVARS[@]}")
256 MAKEVARS=("PLDISTROTAGS=${PLDISTROTAGS}" "${MAKEVARS[@]}")
257 MAKEVARS=("PERSONALITY=${PERSONALITY}" "${MAKEVARS[@]}")
258 MAKEVARS=("MAILDEST=${MAILDEST}" "${MAKEVARS[@]}")
259 MAKEVARS=("WEBPATH=${WEBPATH}" "${MAKEVARS[@]}")
260 MAKEVARS=("TESTBUILDURL=${TESTBUILDURL}" "${MAKEVARS[@]}")
261 MAKEVARS=("WEBROOT=${WEBROOT}" "${MAKEVARS[@]}")
263 MAKEVARS=("BASE=${BASE}" "${MAKEVARS[@]}")
266 /build/latex-first-run.sh || :
269 make -C /build $DRY_RUN "${MAKEVARS[@]}" stage1=true
271 make -C /build $DRY_RUN "${MAKEVARS[@]}" versions
273 make -C /build $DRY_RUN "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
277 # this was formerly run in the myplc-devel chroot but now is run in the root context,
278 # this is so that the .ssh config gets done manually, and once and for all
279 function run_log () {
284 echo "============================== BEG $COMMAND:run_log on $(date)"
286 ### the URL to the RPMS/<arch> location
287 # f12 now has everything in i686; try i386 first as older fedoras have both
289 for a in i386 i686 x86_64; do
290 archdir=$(rootdir $BASE)/build/RPMS/$a
291 if [ -d $archdir ] ; then
292 # where was that installed
293 url=$(echo $archdir | sed -e "s,$(rootdir $BASE)/build,${WEBPATH}/${BASE},")
294 url=$(echo $url | sed -e "s,${WEBROOT},${TESTBUILDURL},")
299 if [ -z "$url" ] ; then
300 echo "$COMMAND: Cannot locate arch URL for testing"
305 testmaster_ssh="root@${TESTMASTER}"
307 # test directory name on test box
311 ssh -n ${testmaster_ssh} rm -rf ${testdir} ${testdir}.git
313 # check it out in the build
314 run_in_build_guest $BASE make -C /build tests-module ${MAKEVARS[@]}
316 # push it onto the testmaster - just the 'system' subdir is enough
317 rsync --verbose --archive $(rootdir $BASE)/build/MODULES/tests/system/ ${testmaster_ssh}:${BASE}
318 # toss the build in the bargain, so the tests don't need to mess with extracting it
319 rsync --verbose --archive $(rootdir $BASE)/build/MODULES/build ${testmaster_ssh}:${BASE}/
321 # invoke test on testbox - pass url and build url - so the tests can use lbuild-initvm.sh
322 run_log_env="-p $PERSONALITY -d $PLDISTRO -f $FCDISTRO"
324 # temporarily turn off set -e
327 ssh 2>&1 ${testmaster_ssh} ${testdir}/run_log --build ${BUILD_SCM_URL} --url ${url} $run_log_env $RUN_LOG_EXTRAS $VERBOSE --all; retcod=$?
331 # interpret retcod of TestMain.py; 2 means there were ignored steps that failed
332 echo "retcod from run_log" $retcod
334 0) success=true; IGNORED="" ;;
335 2) success=true; IGNORED=true ;;
336 *) success=""; IGNORED="" ;;
339 # gather logs in the build vm
340 mkdir -p $(rootdir $BASE)/build/testlogs
341 rsync --verbose --archive ${testmaster_ssh}:$BASE/logs/ $(rootdir $BASE)/build/testlogs
342 # push them to the build web
343 chmod -R a+r $(rootdir $BASE)/build/testlogs/
344 webpublish_rsync_dir $WEBPATH/$BASE/testlogs/ $(rootdir $BASE)/build/testlogs/
346 echo "============================== END $COMMAND:run_log on $(date)"
348 if [ -z "$success" ] ; then
349 echo "Tests have failed - bailing out"
355 # this part won't work if WEBHOST does not match the local host
356 # would need to be made webpublish_* compliant
357 # but do we really need this feature anyway ?
358 function sign_node_packages () {
360 echo "Signing node packages"
364 repository=$WEBPATH/$BASE/RPMS/
365 # the rpms that need signing
367 # and the corresponding stamps
370 for package in $(find $repository/ -name '*.rpm') ; do
371 stamp=$repository/signed-stamps/$(basename $package).signed
372 # If package is newer than signature stamp
373 if [ $package -nt $stamp ] ; then
374 new_rpms="$new_rpms $package"
375 new_stamps="$new_stamps $stamp"
377 # Or than createrepo database
378 [ $package -nt $repository/repodata/repomd.xml ] && need_createrepo=true
381 if [ -n "$new_rpms" ] ; then
382 # Create a stamp once the package gets signed
383 mkdir $repository/signed-stamps 2> /dev/null
385 # Sign RPMS. setsid detaches rpm from the terminal,
386 # allowing the (hopefully blank) GPG password to be
387 # entered from stdin instead of /dev/tty.
389 --define "_signature gpg" \
390 --define "_gpg_path $GPGPATH" \
391 --define "_gpg_name $GPGUID" \
392 --resign $new_rpms && touch $new_stamps
395 # Update repository index / yum metadata.
396 if [ -n "$need_createrepo" ] ; then
397 echo "Indexing node packages after signing"
398 if [ -f $repository/yumgroups.xml ] ; then
399 createrepo --quiet -g yumgroups.xml $repository
401 createrepo --quiet $repository
406 function show_env () {
408 echo FCDISTRO=$FCDISTRO
409 echo PLDISTRO=$PLDISTRO
410 echo PERSONALITY=$PERSONALITY
412 echo BUILD_SCM_URL=$BUILD_SCM_URL
413 echo MAKEVARS="${MAKEVARS[@]}"
414 echo DRY_RUN="$DRY_RUN"
415 echo PLDISTROTAGS="$PLDISTROTAGS"
416 # this does not help, it's not yet set when we run show_env
417 #echo WEBPATH="$WEBPATH"
418 echo TESTBUILDURL="$TESTBUILDURL"
419 echo WEBHOST="$WEBHOST"
420 if in_root_context ; then
421 echo PLDISTROTAGS="$PLDISTROTAGS"
423 if [ -f /build/$PLDISTROTAGS ] ; then
424 echo "XXXXXXXXXXXXXXXXXXXX Contents of tags definition file /build/$PLDISTROTAGS"
425 cat /build/$PLDISTROTAGS
426 echo "XXXXXXXXXXXXXXXXXXXX end tags definition"
428 echo "XXXXXXXXXXXXXXXXXXXX Cannot find tags definition file /build/$PLDISTROTAGS, assuming remote pldistro"
434 function setupssh () {
438 if [ -f ${sshkey} ] ; then
439 SSHDIR=$(rootdir ${base})/root/.ssh
441 cp $sshkey ${SSHDIR}/thekey
443 echo " IdentityFile ~/.ssh/thekey"; \
444 echo " StrictHostKeyChecking no" ) > ${SSHDIR}/config
446 chmod 400 ${SSHDIR}/*
448 echo "WARNING : could not find provided ssh key $sshkey - ignored"
453 echo "Usage: $COMMAND [option] [var=value...] make-targets"
454 echo "Supported options"
455 echo " -f fcdistro - defaults to $DEFAULT_FCDISTRO"
456 echo " -d pldistro - defaults to $DEFAULT_PLDISTRO"
457 echo " -p personality - defaults to $DEFAULT_PERSONALITY"
458 echo " -m mailto - defaults to $DEFAULT_MAILDEST"
459 echo " -s build_scm_url - git URL where to fetch the build module - defaults to $DEFAULT_BUILD_SCM_URL"
460 echo " define GIT tag or branch name appending @tagname to url"
461 echo " -t pldistrotags - defaults to \${PLDISTRO}-tags.mk"
462 echo " -b base - defaults to $DEFAULT_BASE"
463 echo " @NAME@ replaced as appropriate"
464 echo " -o base: (overwrite) do not re-create vm, re-use base instead"
465 echo " the -f/-d/-p/-m/-s/-t options are uneffective in this case"
466 echo " -c testconfig - defaults to $DEFAULT_TESTCONFIG"
467 echo " -y {pl,pg} - passed to run_log"
468 echo " -e step - passed to run_log"
469 echo " -i step - passed to run_log"
470 echo " -X : passes --lxc to run_log"
471 echo " -S : passes --vs to run_log"
472 echo " -x <run_log_args> - a hook to pass other arguments to run_log"
473 echo " -w webpath - defaults to $DEFAULT_WEBPATH"
474 echo " -W testbuildurl - defaults to $DEFAULT_TESTBUILDURL; this is also used to get the hostname where to publish builds"
475 echo " -r webroot - defaults to $DEFAULT_WEBROOT - the fs point where testbuildurl actually sits"
476 echo " -M testmaster - defaults to $DEFAULT_TESTMASTER"
477 echo " -Y - sign yum repo in webpath"
478 echo " -g gpg_path - to the gpg secring used to sign rpms. Defaults to $DEFAULT_GPGPATH"
479 echo " -u gpg_uid - email used in secring. Defaults to $DEFAULT_GPGUID"
480 echo " -K sshkey - specify ssh key to use when reaching git over ssh"
481 echo " -S - do not publish source rpms"
482 echo " -B - run build only"
483 echo " -T - run test only"
484 echo " -n - dry-run: -n passed to make - vm gets created though - no mail sent"
485 echo " -v - be verbose"
486 echo " -7 - uses weekday-@FCDISTRO@ as base"
487 echo " --build-branch branch - build using the branch from build module"
507 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:" -- $@)
515 -f) FCDISTRO=$2; shift 2 ;;
516 -d) PLDISTRO=$2; shift 2 ;;
517 -p) PERSONALITY=$2; shift 2 ;;
518 -m) MAILDEST=$2; shift 2 ;;
519 -s) BUILD_SCM_URL=$2; shift 2 ;;
520 -t) PLDISTROTAGS=$2; shift 2 ;;
521 -b) BASE=$2; shift 2 ;;
522 -o) OVERBASE=$2; shift 2 ;;
523 -c) TESTCONFIG="$TESTCONFIG $2"; shift 2 ;;
524 ########## passing stuff to run_log
525 # -y foo -> run_log -y foo
526 -y) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --rspec-style $2"; shift 2 ;;
527 # -e foo -> run_log -e foo
528 -e) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --exclude $2"; shift 2 ;;
529 -i) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --ignore $2"; shift 2 ;;
530 # -X -> run_log --lxc
531 -X) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --lxc"; shift;;
533 -S) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --vs"; shift;;
534 # more general form to pass args to run_log
535 # -x foo -> run_log foo
536 -x) RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS $2"; shift 2;;
538 -w) WEBPATH=$2; shift 2 ;;
539 -W) TESTBUILDURL=$2; shift 2 ;;
540 -r) WEBROOT=$2; shift 2 ;;
541 -M) TESTMASTER=$2; shift 2 ;;
542 -Y) SIGNYUMREPO=true; shift ;;
543 -g) GPGPATH=$2; shift 2 ;;
544 -u) GPGUID=$2; shift 2 ;;
545 -K) SSH_KEY=$2; shift 2 ;;
546 -S) PUBLISH_SRPMS="" ; shift ;;
547 -B) DO_TEST= ; shift ;;
548 -T) DO_BUILD= ; shift;;
549 -n) DRY_RUN="-n" ; shift ;;
550 -v) set -x ; VERBOSE="-v" ; shift ;;
551 -7) BASE="$(date +%a|tr A-Z a-z)-@FCDISTRO@" ; shift ;;
552 -P) PREINSTALLED="-P $2"; shift 2;;
558 # preserve options for passing them again later, together with expanded base
561 # allow var=value stuff;
562 for target in "$@" ; do
563 # check if contains '='
564 target1=$(echo $target | sed -e s,=,,)
565 if [ "$target" = "$target1" ] ; then
566 MAKETARGETS=(${MAKETARGETS[@]} "$target")
568 MAKEVARS=(${MAKEVARS[@]} "$target")
573 [ -z "$FCDISTRO" ] && FCDISTRO=$DEFAULT_FCDISTRO
574 [ -z "$PLDISTRO" ] && PLDISTRO=$DEFAULT_PLDISTRO
575 [ -z "$PERSONALITY" ] && PERSONALITY=$DEFAULT_PERSONALITY
576 [ -z "$MAILDEST" ] && MAILDEST=$(echo $DEFAULT_MAILDEST | sed -e 's, at ,@,')
577 [ -z "$PLDISTROTAGS" ] && PLDISTROTAGS="${PLDISTRO}-tags.mk"
578 [ -z "$BASE" ] && BASE="$DEFAULT_BASE"
579 [ -z "$WEBPATH" ] && WEBPATH="$DEFAULT_WEBPATH"
580 [ -z "$TESTBUILDURL" ] && TESTBUILDURL="$DEFAULT_TESTBUILDURL"
581 [ -z "$WEBROOT" ] && WEBROOT="$DEFAULT_WEBROOT"
582 [ -z "$GPGPATH" ] && GPGPATH="$DEFAULT_GPGPATH"
583 [ -z "$GPGUID" ] && GPGUID="$DEFAULT_GPGUID"
584 [ -z "$BUILD_SCM_URL" ] && BUILD_SCM_URL="$DEFAULT_BUILD_SCM_URL"
585 [ -z "$TESTCONFIG" ] && TESTCONFIG="$DEFAULT_TESTCONFIG"
586 [ -z "$TESTMASTER" ] && TESTMASTER="$DEFAULT_TESTMASTER"
588 [ -n "$DRY_RUN" ] && MAILDEST=""
590 # elaborate the extra args to be passed to run_log
591 for config in ${TESTCONFIG} ; do
592 RUN_LOG_EXTRAS="$RUN_LOG_EXTRAS --config $config"
596 if [ -n "$OVERBASE" ] ; then
597 sedargs="-e s,@DATE@,${DATE},g"
598 BASE=$(echo ${OVERBASE} | sed $sedargs)
600 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
601 BASE=$(echo ${BASE} | sed $sedargs)
604 ### elaborate mail subject
605 if [ -n "$DO_BUILD" -a -n "$DO_TEST" ] ; then
607 elif [ -n "$DO_BUILD" ] ; then
608 MAIL_SUBJECT="pkg-only"
609 elif [ -n "$DO_TEST" ] ; then
610 MAIL_SUBJECT="test-only"
612 if [ -n "$OVERBASE" ] ; then
613 MAIL_SUBJECT="${MAIL_SUBJECT} rerun"
615 MAIL_SUBJECT="${MAIL_SUBJECT} fresh"
617 short_hostname=$(hostname | cut -d. -f1)
618 MAIL_SUBJECT="on ${short_hostname} - ${MAIL_SUBJECT}"
620 ### compute WEBHOST from TESTBUILDURL
621 # this is to avoid having to change the builds configs everywhere
622 # simplistic way to extract hostname from a URL
623 WEBHOST=$(echo "$TESTBUILDURL" | cut -d/ -f 3)
625 if ! in_root_context ; then
627 echo "==================== Within LXC BEG $(date)"
629 echo "==================== Within LXC END $(date)"
633 # we run in the root context :
634 # (*) create or check for the vm to use
635 # (*) copy this command in the vm
638 if [ -n "$OVERBASE" ] ; then
639 ### Re-use a vm (finish an unfinished build..)
640 if [ ! -d $(rootdir ${BASE}) ] ; then
641 echo $COMMAND : cannot find vm $BASE
644 # manage LOG - beware it might be a symlink so nuke it first
645 LOG=$(logfile ${BASE})
649 echo "XXXXXXXXXX $COMMAND: using existing vm $BASE" $(date)
650 # start in case e.g. we just rebooted
651 virsh -c lxc:/// start ${BASE} || :
652 # retrieve environment from the previous run
653 FCDISTRO=$(run_in_build_guest $BASE /build/getdistroname.sh)
654 BUILD_SCM_URL=$(run_in_build_guest $BASE make --no-print-directory -C /build stage1=skip +build-GITPATH)
655 # for efficiency, crop everything in one make run
656 tmp=/tmp/${BASE}-env.sh
657 run_in_build_guest $BASE make --no-print-directory -C /build stage1=skip \
658 ++PLDISTRO ++PLDISTROTAGS ++PERSONALITY ++MAILDEST ++WEBPATH ++TESTBUILDURL ++WEBROOT > $tmp
662 [ -n "$SSH_KEY" ] && setupssh ${BASE} ${SSH_KEY}
663 run_in_build_guest $BASE "(cd /build; git pull; make tests-clean)"
664 # make sure we refresh the tests place in case it has changed
665 rm -f /build/MODULES/tests
666 options=(${options[@]} -d $PLDISTRO -t $PLDISTROTAGS -s $BUILD_SCM_URL)
667 [ -n "$PERSONALITY" ] && options=(${options[@]} -p $PERSONALITY)
668 [ -n "$MAILDEST" ] && options=(${options[@]} -m $MAILDEST)
669 [ -n "$WEBPATH" ] && options=(${options[@]} -w $WEBPATH)
670 [ -n "$TESTBUILDURL" ] && options=(${options[@]} -W $TESTBUILDURL)
671 [ -n "$WEBROOT" ] && options=(${options[@]} -r $WEBROOT)
674 # create vm: check it does not exist yet
676 while [ -d $(rootdir ${BASE})${i} ] ; do
677 # we name subsequent builds <base>-n<i> so the logs and builds get sorted properly
678 [ -z ${i} ] && BASE=${BASE}-n
680 if [ $i -gt 100 ] ; then
681 echo "$COMMAND: Failed to create build vm $(rootdir ${BASE})${i}"
687 # manage LOG - beware it might be a symlink so nuke it first
688 LOG=$(logfile ${BASE})
692 echo "XXXXXXXXXX $COMMAND: creating vm $BASE" $(date)
695 ### extract the whole build - much simpler
696 tmpdir=/tmp/$COMMAND-$$
697 GIT_REPO=$(echo $BUILD_SCM_URL | cut -d@ -f1)
698 GIT_TAG=$(echo $BUILD_SCM_URL | cut -s -d@ -f2)
699 GIT_TAG=${GIT_TAG:-master}
701 ( git archive --remote=$GIT_REPO $GIT_TAG | tar -C $tmpdir -xf -) || \
702 ( echo "==================== git archive FAILED, trying git clone instead" ; \
703 git clone $GIT_REPO $tmpdir && cd $tmpdir && git checkout $GIT_TAG && rm -rf .git)
707 ./lbuild-initvm.sh $VERBOSE -f ${FCDISTRO} -d ${PLDISTRO} -p ${PERSONALITY} ${PREINSTALLED} ${BASE}
711 # Extract build again - in the vm
712 [ -n "$SSH_KEY" ] && setupssh ${BASE} ${SSH_KEY}
713 run_in_build_guest $BASE "(git clone $GIT_REPO /build; cd /build; git checkout $GIT_TAG)"
715 echo "XXXXXXXXXX $COMMAND: preparation of vm $BASE done" $(date)
717 # The log inside the vm contains everything
718 LOG2=$(rootdir ${BASE})/log.txt
719 (echo "==================== BEG LXC Transcript of vm creation" ; \
721 echo "==================== END LXC Transcript of vm creation" ; \
722 echo "xxxxxxxxxx Messing with logs, symlinking $LOG2 to $LOG" ) >> $LOG2
723 ### not too nice : nuke the former log, symlink it to the new one
724 rm $LOG; ln -s $LOG2 $LOG
729 sedargs="-e s,@DATE@,${DATE},g -e s,@FCDISTRO@,${FCDISTRO},g -e s,@PLDISTRO@,${PLDISTRO},g -e s,@PERSONALITY@,${PERSONALITY},g"
730 WEBPATH=$(echo ${WEBPATH} | sed $sedargs)
731 webpublish mkdir -p ${WEBPATH}
733 # where to store the log for web access
734 WEBBASE=${WEBPATH}/${BASE}
735 WEBLOG=${WEBPATH}/${BASE}/log.txt
736 # compute the log URL - inserted in the mail messages for convenience
737 WEBBASE_URL=$(echo $WEBBASE | sed -e "s,//,/,g" -e "s,${WEBROOT},${TESTBUILDURL},")
739 if [ -n "$DO_BUILD" ] ; then
741 # invoke this command into the build directory of the vm
742 cp $COMMANDPATH $(rootdir ${BASE})/build/
744 # invoke this command in the vm for building (-T)
745 run_in_build_guest $BASE chmod +x /build/$COMMAND
746 run_in_build_guest $BASE /build/$COMMAND "${options[@]}" -b "${BASE}" "${MAKEVARS[@]}" "${MAKETARGETS[@]}"
749 # publish to the web so run_log can find them
752 webpublish rm -rf $WEBPATH/$BASE
753 # guess if we've been doing any debian-related build
754 if [ ! -f $(rootdir $BASE)/etc/debian_version ] ; then
755 webpublish mkdir -p $WEBPATH/$BASE/{RPMS,SRPMS}
756 webpublish_rsync_dir $WEBPATH/$BASE/RPMS/ $(rootdir $BASE)/build/RPMS/
757 [[ -n "$PUBLISH_SRPMS" ]] && webpublish_rsync_dir $WEBPATH/$BASE/SRPMS/ $(rootdir $BASE)/build/SRPMS/
759 # run scanpackages so we can use apt-get on this
760 # (not needed on fedora b/c this is done by the regular build already)
761 run_in_build_guest $BASE "(cd /build ; dpkg-scanpackages DEBIAN/ | gzip -9c > Packages.gz)"
762 webpublish mkdir -p $WEBPATH/$BASE/DEBIAN
763 webpublish_rsync_files $WEBPATH/$BASE/DEBIAN/ $(rootdir $BASE)/build/DEBIAN/*.deb
764 webpublish_rsync_files $WEBPATH/$BASE/ $(rootdir $BASE)/build/Packages.gz
766 # publish myplc-release if this exists
767 release=$(rootdir $BASE)/build/myplc-release
768 [ -f $release ] && webpublish_rsync_files $WEBPATH/$BASE $release
772 # create yum repo and sign packages.
773 if [ -n "$SIGNYUMREPO" ] ; then
774 # this script does not yet support signing on a remote (webhost) repo
775 sign_here=$(hostname) ; sign_web=$(webpublish hostname)
776 if [ "$hostname" = "$sign_here" ] ; then
779 echo "$COMMAND does not support signing on a remote yum repo"
780 echo "you might want to turn off the -y option, or run this on the web server box itself"
785 if [ -n "$DO_TEST" ] ; then
791 echo "==================== MAIN END $(date)"