1#!/bin/bash
2
3# Setup of buildbot configuration. Package installation is being done by
4# Vagrantfile
5# Dependencies: buildbot, buildbot-slave, supervisor
6
7USER=$1
8GOPATH=$2
9DOCKER_PATH=$3
10CFG_PATH=$4
11BUILDBOT_PATH=$5
12SLAVE_NAME="buildworker"
13SLAVE_SOCKET="localhost:9989"
14BUILDBOT_PWD="pass-docker"
15IP=$(sed -nE 's/VM_IP = "(.+)"/\1/p' ${DOCKER_PATH}/hack/Vagrantfile)
16export PATH="/bin:sbin:/usr/bin:/usr/sbin:/usr/local/bin"
17
18function run { su $USER -c "$1"; }
19
20# Exit if buildbot has already been installed
21[ -d "$BUILDBOT_PATH" ] && exit 0
22
23# Setup buildbot
24run "mkdir -p $BUILDBOT_PATH"
25cd $BUILDBOT_PATH
26run "buildbot create-master master"
27run "cp $CFG_PATH/master.cfg master"
28run "sed -i 's/localhost/$IP/' master/master.cfg"
29run "sed -i -E 's#(GOPATH = ).+#\1\"$GOPATH\"#' master/master.cfg"
30run "sed -i -E 's#(DOCKER_PATH = ).+#\1\"$DOCKER_PATH\"#' master/master.cfg"
31run "buildslave create-slave slave $SLAVE_SOCKET $SLAVE_NAME $BUILDBOT_PWD"
32
33# Allow buildbot subprocesses (docker tests) to properly run in containers,
34# in particular with docker -u
35run "sed -i 's/^umask = None/umask = 000/' slave/buildbot.tac"
36
37# Setup supervisor
38cp $CFG_PATH/buildbot.conf /etc/supervisor/conf.d/buildbot.conf
39sed -i -E "s/^chmod=0700.+/chmod=0770\nchown=root:$USER/" /etc/supervisor/supervisord.conf
40kill -HUP $(pgrep -f "/usr/bin/python /usr/bin/supervisord")
41
42# Add git hook
43cp $CFG_PATH/post-commit $DOCKER_PATH/.git/hooks
44sed -i "s/localhost/$IP/" $DOCKER_PATH/.git/hooks/post-commit
45
46