From 8867889800efcb321d0061893fe6092f8932c4d3 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Tue, 5 Aug 2014 14:52:57 +0000 Subject: Add Mason scripts on top of distbuild system The distbuild system can be configured to act as a CI controller. Providing appropriate config makes it copy all the scripts and systemd units out of the mason directory onto the target, such that it will start building and testing the configured cluster morphology on boot. --- mason/mason-report.sh | 209 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100755 mason/mason-report.sh (limited to 'mason/mason-report.sh') diff --git a/mason/mason-report.sh b/mason/mason-report.sh new file mode 100755 index 00000000..d6cf0c19 --- /dev/null +++ b/mason/mason-report.sh @@ -0,0 +1,209 @@ +#!/bin/bash + +set -x + +. /root/mason.conf + +REPORT_PATH=/root/report.html +SERVER_PATH=/srv/mason + +sed_escape() { + printf "%s\n" "$1" | sed -e 's/\W/\\&/g' +} + +create_report() { +cat > $REPORT_PATH <<'EOF' + + + + + + + +

Mason

+

Baserock: Continuous Delivery

+

Build log of changes to BRANCH from TROVE. Most recent first.

+ + + + + + + + +
StartedRefDurationResult
+ + + +EOF + + sed -i 's/BRANCH/'"$(sed_escape "$1")"'/' $REPORT_PATH + sed -i 's/TROVE/'"$(sed_escape "$2")"'/' $REPORT_PATH +} + +update_report() { + # Give function params sensible names + build_start_time="$1" + build_trove_host="$2" + build_ref="$3" + build_sha1="$4" + build_duration="$5" + build_result="$6" + + # Generate template if report file is not there + if [ ! -f $REPORT_PATH ]; then + create_report $build_ref $build_trove_host + fi + + # Build table row for insertion into report file + msg=''"${build_start_time}"''"${build_sha1}"''"${build_duration}s"''"${build_result}"'' + + # Insert report line, newest at top + sed -i 's//\n'"$(sed_escape "$msg")"'/' $REPORT_PATH +} + +START_TIME=`date +%Y-%m-%d\ %T` + +logfile="$(mktemp)" +/root/mason.sh 2>&1 | tee "$logfile" +case "${PIPESTATUS[0]}" in +0) + RESULT=pass + ;; +33) + RESULT=skip + ;; +*) + RESULT=fail + ;; +esac + +# TODO: Update page with last executed time +if [ "$RESULT" = skip ]; then + rm "$logfile" + exit 0 +fi + +DURATION=$(( $(date +%s) - $(date --date="$START_TIME" +%s) )) +SHA1="$(cd "ws/$DEFINITIONS_REF/$UPSTREAM_TROVE_ADDRESS/baserock/baserock/definitions" && git rev-parse HEAD)" + +update_report "$START_TIME" \ + "$DISTBUILD_TROVE_ADDRESS" \ + "$DEFINITIONS_REF" \ + "$SHA1" \ + "$DURATION" \ + "$RESULT" + + +# +# Copy report into server directory +# + +cp "$REPORT_PATH" "$SERVER_PATH/index.html" +mkdir /srv/mason/log +mv "$logfile" /srv/mason/log/"$SHA1--$START_TIME.log" -- cgit v1.2.1