From 35e959f52594b8f75570c36f13e75d2863fe71ca Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Wed, 16 Dec 2015 11:56:24 -0800 Subject: [PATCH] Initial simple autobuilder. --- tools/autobuild/build.sh | 81 +++++++++++++++++++++++++++++++++++ tools/autobuild/install.sh | 86 ++++++++++++++++++++++++++++++++++++++ tools/autobuild/run.sh | 9 ++++ 3 files changed, 176 insertions(+) create mode 100755 tools/autobuild/build.sh create mode 100755 tools/autobuild/install.sh create mode 100755 tools/autobuild/run.sh diff --git a/tools/autobuild/build.sh b/tools/autobuild/build.sh new file mode 100755 index 00000000..db14b51f --- /dev/null +++ b/tools/autobuild/build.sh @@ -0,0 +1,81 @@ +#!/bin/bash +############################################################ +set -e + +AUTOBUILD_SCRIPT="$(realpath ${BASH_SOURCE[0]})" +ONL="$(realpath $(dirname $AUTOBUILD_SCRIPT)/../../)" + + +# Default build branch +BUILD_BRANCH=master + +while getopts ":b:v78" opt; do + case $opt in + 7) + ONLB_OPTIONS=--7 + if [ -z "$DOCKER_IMAGE" ]; then + echo "Selecting Debian 7 build..." + fi + ;; + 8) + ONLB_OPTIONS=--8 + if [ -z "$DOCKER_IMAGE" ]; then + echo "Selecting Debian 8 build..." + fi + ;; + b) + BUILD_BRANCH=$OPTARG + ;; + v) + set -x + ;; + esac +done + +if [ -z "$ONLB_OPTIONS" ]; then + # Build both suites + $AUTOBUILD_SCRIPT --7 $@ + $AUTOBUILD_SCRIPT --8 $@ + exit $? +fi + + + + +# +# Restart under correct builder environment. +# +if [ -z "$DOCKER_IMAGE" ]; then + # Execute ourselves under the builder + ONLB=/usr/local/bin/onlbuilder + if [ -x $ONLB ]; then + $ONLB $ONLB_OPTIONS --isolate $ONL --non-interactive -c $AUTOBUILD_SCRIPT $@ + exit $? + else + echo "Not running in a docker workspace and the onlbuilder script is not available." + exit 1 + fi +fi + +echo "Now running under $DOCKER_IMAGE..." + + +# The expectation is that we will already be on the required branch. +# This is to normalize environments where the checkout might instead +# be in a detached head (like jenkins) +echo "Switching to branch $BUILD_BRANCH..." +cd $ONL && git checkout $BUILD_BRANCH + + +# +# Full build +# +cd $ONL +. setup.env + +if false && make all; then + echo Build Failed. + exit 1 +fi + +echo Build Succeeded. diff --git a/tools/autobuild/install.sh b/tools/autobuild/install.sh new file mode 100755 index 00000000..5001997b --- /dev/null +++ b/tools/autobuild/install.sh @@ -0,0 +1,86 @@ +#!/bin/bash +############################################################ +set -e + +ONL="$(realpath $(dirname $BASH_SOURCE[0])/../../)" + +BUILD_BRANCH=${BUILD_BRANCH:-$(git rev-parse --abbrev-ref HEAD)} + +# +# Release artifacts can be automatically installed on a remote server +# after the build is completed. +# + +# Remote server name +REMOTE_SERVER= + +# Path on the remote server for builds. +# The final build artifacts will reside in $INSTALL_BASE_DIR/$BUILD_BRANCH/$BUILD_ID +REMOTE_BASE_DIR= + +# The remote user for RSYNC +REMOTE_USER= + +# The remote password for RSYNC +REMOTE_PASS= + +while getopts ":s:d:u:p:b:t:v" opt; do + case $opt in + s) + REMOTE_SERVER=$OPTARG + ;; + d) + REMOTE_BASE_DIR=$OPTARG + ;; + u) + REMOTE_USER=$OPTARG + ;; + p) + REMOTE_PASS=$OPTARG + ;; + b) + BUILD_BRANCH=$OPTARG + ;; + v) + set -x + esac +done + + +if [ -z "$REMOTE_SERVER" ]; then + echo "Remote instlallation requires a server (-s)" + exit 1 +fi + +if [ -z "$REMOTE_BASE_DIR" ]; then + echo "Remote installation requires a branch directory (-d)" + exit 1 +fi + +if [ -z "$REMOTE_USER" ]; then + echo "Remote installation requires a remote user (-u)" + exit 1 +fi + +if [ -z "$REMOTE_PASS" ]; then + echo "Remote installation requires a remote password (-p)" + exit 1 +fi + + +. $ONL/make/version-onl.sh +REMOTE_DIR="$REMOTE_BASE_DIR/$BUILD_BRANCH/$FNAME_BUILD_ID" + + +RSYNC=rsync +RSYNC_OPTS=" -v --copy-links --delete -a" + +_rsync() { + $RSYNC $RSYNC_OPTS --rsh="sshpass -p $REMOTE_PASS ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l $REMOTE_USER" $1 $2 +} + +sshpass -p $REMOTE_PASS ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l $REMOTE_USER $REMOTE_SERVER mkdir -p $REMOTE_DIR +_rsync $ONL/RELEASE/* $REMOTE_SERVER:$REMOTE_DIR + +make -C $ONL/REPO build-clean +_rsync $ONL/REPO $REMOTE_SERVER:$REMOTE_DIR diff --git a/tools/autobuild/run.sh b/tools/autobuild/run.sh new file mode 100755 index 00000000..ec0d71e6 --- /dev/null +++ b/tools/autobuild/run.sh @@ -0,0 +1,9 @@ +#!/bin/bash +############################################################ +set -e + +PARENT_DIR="$(realpath $(dirname $BASH_SOURCE[0]))" +cd $PARENT_DIR + +./build.sh $@ +./install.sh $@