52 | 55 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,20 @@ |
0 |
+Buildbot |
|
1 |
+======== |
|
2 |
+ |
|
3 |
+Buildbot is a continuous integration system designed to automate the |
|
4 |
+build/test cycle. By automatically rebuilding and testing the tree each time |
|
5 |
+something has changed, build problems are pinpointed quickly, before other |
|
6 |
+developers are inconvenienced by the failure. |
|
7 |
+ |
|
8 |
+When running 'make hack' at the docker root directory, it spawns a virtual |
|
9 |
+machine in the background running a buildbot instance and adds a git |
|
10 |
+post-commit hook that automatically run docker tests for you. |
|
11 |
+ |
|
12 |
+You can check your buildbot instance at http://192.168.33.21:8010/waterfall |
|
13 |
+ |
|
14 |
+ |
|
15 |
+Buildbot dependencies |
|
16 |
+--------------------- |
|
17 |
+ |
|
18 |
+vagrant, virtualbox packages and python package requests |
|
19 |
+ |
0 | 20 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,28 @@ |
0 |
+# -*- mode: ruby -*- |
|
1 |
+# vi: set ft=ruby : |
|
2 |
+ |
|
3 |
+$BUILDBOT_IP = '192.168.33.21' |
|
4 |
+ |
|
5 |
+def v10(config) |
|
6 |
+ config.vm.box = "quantal64_3.5.0-25" |
|
7 |
+ config.vm.box_url = "http://get.docker.io/vbox/ubuntu/12.10/quantal64_3.5.0-25.box" |
|
8 |
+ config.vm.share_folder 'v-data', '/data/docker', File.dirname(__FILE__) + '/..' |
|
9 |
+ config.vm.network :hostonly, $BUILDBOT_IP |
|
10 |
+ |
|
11 |
+ # Ensure puppet is installed on the instance |
|
12 |
+ config.vm.provision :shell, :inline => 'apt-get -qq update; apt-get install -y puppet' |
|
13 |
+ |
|
14 |
+ config.vm.provision :puppet do |puppet| |
|
15 |
+ puppet.manifests_path = '.' |
|
16 |
+ puppet.manifest_file = 'buildbot.pp' |
|
17 |
+ puppet.options = ['--templatedir','.'] |
|
18 |
+ end |
|
19 |
+end |
|
20 |
+ |
|
21 |
+Vagrant::VERSION < '1.1.0' and Vagrant::Config.run do |config| |
|
22 |
+ v10(config) |
|
23 |
+end |
|
24 |
+ |
|
25 |
+Vagrant::VERSION >= '1.1.0' and Vagrant.configure('1') do |config| |
|
26 |
+ v10(config) |
|
27 |
+end |
0 | 28 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,43 @@ |
0 |
+#!/bin/bash |
|
1 |
+ |
|
2 |
+# Auto setup of buildbot configuration. Package installation is being done |
|
3 |
+# on buildbot.pp |
|
4 |
+# Dependencies: buildbot, buildbot-slave, supervisor |
|
5 |
+ |
|
6 |
+SLAVE_NAME='buildworker' |
|
7 |
+SLAVE_SOCKET='localhost:9989' |
|
8 |
+BUILDBOT_PWD='pass-docker' |
|
9 |
+USER='vagrant' |
|
10 |
+ROOT_PATH='/data/buildbot' |
|
11 |
+DOCKER_PATH='/data/docker' |
|
12 |
+BUILDBOT_CFG="$DOCKER_PATH/buildbot/buildbot-cfg" |
|
13 |
+IP=$(grep BUILDBOT_IP /data/docker/buildbot/Vagrantfile | awk -F "'" '{ print $2; }') |
|
14 |
+ |
|
15 |
+function run { su $USER -c "$1"; } |
|
16 |
+ |
|
17 |
+export PATH=/bin:sbin:/usr/bin:/usr/sbin:/usr/local/bin |
|
18 |
+ |
|
19 |
+# Exit if buildbot has already been installed |
|
20 |
+[ -d "$ROOT_PATH" ] && exit 0 |
|
21 |
+ |
|
22 |
+# Setup buildbot |
|
23 |
+run "mkdir -p ${ROOT_PATH}" |
|
24 |
+cd ${ROOT_PATH} |
|
25 |
+run "buildbot create-master master" |
|
26 |
+run "cp $BUILDBOT_CFG/master.cfg master" |
|
27 |
+run "sed -i 's/localhost/$IP/' master/master.cfg" |
|
28 |
+run "buildslave create-slave slave $SLAVE_SOCKET $SLAVE_NAME $BUILDBOT_PWD" |
|
29 |
+ |
|
30 |
+# Allow buildbot subprocesses (docker tests) to properly run in containers, |
|
31 |
+# in particular with docker -u |
|
32 |
+run "sed -i 's/^umask = None/umask = 000/' ${ROOT_PATH}/slave/buildbot.tac" |
|
33 |
+ |
|
34 |
+# Setup supervisor |
|
35 |
+cp $BUILDBOT_CFG/buildbot.conf /etc/supervisor/conf.d/buildbot.conf |
|
36 |
+sed -i "s/^chmod=0700.*0700./chmod=0770\nchown=root:$USER/" /etc/supervisor/supervisord.conf |
|
37 |
+kill -HUP `pgrep -f "/usr/bin/python /usr/bin/supervisord"` |
|
38 |
+ |
|
39 |
+# Add git hook |
|
40 |
+cp $BUILDBOT_CFG/post-commit $DOCKER_PATH/.git/hooks |
|
41 |
+sed -i "s/localhost/$IP/" $DOCKER_PATH/.git/hooks/post-commit |
|
42 |
+ |
0 | 43 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,18 @@ |
0 |
+[program:buildmaster] |
|
1 |
+command=su vagrant -c "buildbot start master" |
|
2 |
+directory=/data/buildbot |
|
3 |
+chown= root:root |
|
4 |
+redirect_stderr=true |
|
5 |
+stdout_logfile=/var/log/supervisor/buildbot-master.log |
|
6 |
+stderr_logfile=/var/log/supervisor/buildbot-master.log |
|
7 |
+ |
|
8 |
+[program:buildworker] |
|
9 |
+command=buildslave start slave |
|
10 |
+directory=/data/buildbot |
|
11 |
+chown= root:root |
|
12 |
+redirect_stderr=true |
|
13 |
+stdout_logfile=/var/log/supervisor/buildbot-slave.log |
|
14 |
+stderr_logfile=/var/log/supervisor/buildbot-slave.log |
|
15 |
+ |
|
16 |
+[group:buildbot] |
|
17 |
+programs=buildmaster,buildworker |
0 | 18 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,46 @@ |
0 |
+import os |
|
1 |
+from buildbot.buildslave import BuildSlave |
|
2 |
+from buildbot.schedulers.forcesched import ForceScheduler |
|
3 |
+from buildbot.config import BuilderConfig |
|
4 |
+from buildbot.process.factory import BuildFactory |
|
5 |
+from buildbot.steps.shell import ShellCommand |
|
6 |
+from buildbot.status import html |
|
7 |
+from buildbot.status.web import authz, auth |
|
8 |
+ |
|
9 |
+PORT_WEB = 8010 # Buildbot webserver port |
|
10 |
+PORT_MASTER = 9989 # Port where buildbot master listen buildworkers |
|
11 |
+TEST_USER = 'buildbot' # Credential to authenticate build triggers |
|
12 |
+TEST_PWD = 'docker' # Credential to authenticate build triggers |
|
13 |
+BUILDER_NAME = 'docker' |
|
14 |
+BUILDPASSWORD = 'pass-docker' # Credential to authenticate buildworkers |
|
15 |
+DOCKER_PATH = '/data/docker' |
|
16 |
+ |
|
17 |
+ |
|
18 |
+c = BuildmasterConfig = {} |
|
19 |
+ |
|
20 |
+c['title'] = "Docker" |
|
21 |
+c['titleURL'] = "waterfall" |
|
22 |
+c['buildbotURL'] = "http://localhost:{0}/".format(PORT_WEB) |
|
23 |
+c['db'] = {'db_url':"sqlite:///state.sqlite"} |
|
24 |
+c['slaves'] = [BuildSlave('buildworker', BUILDPASSWORD)] |
|
25 |
+c['slavePortnum'] = PORT_MASTER |
|
26 |
+ |
|
27 |
+c['schedulers'] = [ForceScheduler(name='trigger',builderNames=[BUILDER_NAME])] |
|
28 |
+ |
|
29 |
+# Docker test command |
|
30 |
+test_cmd = """( |
|
31 |
+ cd {0}/..; rm -rf docker-tmp; git clone docker docker-tmp; |
|
32 |
+ cd docker-tmp; make test; exit_status=$?; |
|
33 |
+ cd ..; rm -rf docker-tmp; exit $exit_status)""".format(DOCKER_PATH) |
|
34 |
+ |
|
35 |
+# Builder |
|
36 |
+factory = BuildFactory() |
|
37 |
+factory.addStep(ShellCommand(description='Docker',logEnviron=False, |
|
38 |
+ usePTY=True,command=test_cmd)) |
|
39 |
+c['builders'] = [BuilderConfig(name=BUILDER_NAME,slavenames=['buildworker'], |
|
40 |
+ factory=factory)] |
|
41 |
+ |
|
42 |
+# Status |
|
43 |
+authz_cfg=authz.Authz(auth=auth.BasicAuth([(TEST_USER,TEST_PWD)]), |
|
44 |
+ forceBuild='auth') |
|
45 |
+c['status'] = [html.WebStatus(http_port=PORT_WEB, authz=authz_cfg)] |
0 | 46 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,21 @@ |
0 |
+#!/usr/bin/python |
|
1 |
+ |
|
2 |
+'''Trigger buildbot docker test build |
|
3 |
+ |
|
4 |
+ post-commit git hook designed to automatically trigger buildbot on |
|
5 |
+ the provided vagrant docker VM.''' |
|
6 |
+ |
|
7 |
+import requests |
|
8 |
+ |
|
9 |
+USERNAME = 'buildbot' |
|
10 |
+PASSWORD = 'docker' |
|
11 |
+BASE_URL = 'http://localhost:8010' |
|
12 |
+path = lambda s: BASE_URL + '/' + s |
|
13 |
+ |
|
14 |
+try: |
|
15 |
+ session = requests.session() |
|
16 |
+ session.post(path('login'),data={'username':USERNAME,'passwd':PASSWORD}) |
|
17 |
+ session.post(path('builders/docker/force'), |
|
18 |
+ data={'forcescheduler':'trigger','reason':'Test commit'}) |
|
19 |
+except: |
|
20 |
+ pass |
0 | 21 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,32 @@ |
0 |
+node default { |
|
1 |
+ $USER = 'vagrant' |
|
2 |
+ $ROOT_PATH = '/data/buildbot' |
|
3 |
+ $DOCKER_PATH = '/data/docker' |
|
4 |
+ |
|
5 |
+ exec {'apt_update': command => '/usr/bin/apt-get update' } |
|
6 |
+ Package { require => Exec['apt_update'] } |
|
7 |
+ group {'puppet': ensure => 'present'} |
|
8 |
+ |
|
9 |
+ # Install dependencies |
|
10 |
+ Package { ensure => 'installed' } |
|
11 |
+ package { ['python-dev','python-pip','supervisor','lxc','bsdtar','git','golang']: } |
|
12 |
+ |
|
13 |
+ file{[ '/data' ]: |
|
14 |
+ owner => $USER, group => $USER, ensure => 'directory' } |
|
15 |
+ |
|
16 |
+ file {'/var/tmp/requirements.txt': |
|
17 |
+ content => template('requirements.txt') } |
|
18 |
+ |
|
19 |
+ exec {'requirements': |
|
20 |
+ require => [ Package['python-dev'], Package['python-pip'], |
|
21 |
+ File['/var/tmp/requirements.txt'] ], |
|
22 |
+ cwd => '/var/tmp', |
|
23 |
+ command => "/bin/sh -c '(/usr/bin/pip install -r requirements.txt; |
|
24 |
+ rm /var/tmp/requirements.txt)'" } |
|
25 |
+ |
|
26 |
+ exec {'buildbot-cfg-sh': |
|
27 |
+ require => [ Package['supervisor'], Exec['requirements']], |
|
28 |
+ path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin', |
|
29 |
+ cwd => '/data', |
|
30 |
+ command => "$DOCKER_PATH/buildbot/buildbot-cfg/buildbot-cfg.sh" } |
|
31 |
+} |