Browse code

testing; issue #603: Create AWS testing buildbot instance for docker CI

Daniel Mizyrycki authored on 2013/05/14 15:10:00
Showing 12 changed files
1 1
deleted file mode 100644
... ...
@@ -1,20 +0,0 @@
1
-Buildbot
2
-========
3
-
4
-Buildbot is a continuous integration system designed to automate the
5
-build/test cycle. By automatically rebuilding and testing the tree each time
6
-something has changed, build problems are pinpointed quickly, before other
7
-developers are inconvenienced by the failure.
8
-
9
-When running 'make hack' at the docker root directory, it spawns a virtual
10
-machine in the background running a buildbot instance and adds a git
11
-post-commit hook that automatically run docker tests for you.
12
-
13
-You can check your buildbot instance at http://192.168.33.21:8010/waterfall
14
-
15
-
16
-Buildbot dependencies
17
-
18
-vagrant, virtualbox packages and python package requests
19
-
20 1
deleted file mode 100644
... ...
@@ -1,28 +0,0 @@
1
-# -*- mode: ruby -*-
2
-# vi: set ft=ruby :
3
-
4
-$BUILDBOT_IP = '192.168.33.21'
5
-
6
-def v10(config)
7
-  config.vm.box = "quantal64_3.5.0-25"
8
-  config.vm.box_url = "http://get.docker.io/vbox/ubuntu/12.10/quantal64_3.5.0-25.box"
9
-  config.vm.share_folder 'v-data', '/data/docker', File.dirname(__FILE__) + '/..'
10
-  config.vm.network :hostonly, $BUILDBOT_IP
11
-
12
-  # Ensure puppet is installed on the instance
13
-  config.vm.provision :shell, :inline => 'apt-get -qq update; apt-get install -y puppet'
14
-
15
-  config.vm.provision :puppet do |puppet|
16
-    puppet.manifests_path = '.'
17
-    puppet.manifest_file  = 'buildbot.pp'
18
-    puppet.options = ['--templatedir','.']
19
-  end
20
-end
21
-
22
-Vagrant::VERSION < '1.1.0' and Vagrant::Config.run do |config|
23
-  v10(config)
24
-end
25
-
26
-Vagrant::VERSION >= '1.1.0' and Vagrant.configure('1') do |config|
27
-  v10(config)
28
-end
29 1
deleted file mode 100755
... ...
@@ -1,43 +0,0 @@
1
-#!/bin/bash
2
-
3
-# Auto setup of buildbot configuration. Package installation is being done
4
-# on buildbot.pp
5
-# Dependencies: buildbot, buildbot-slave, supervisor
6
-
7
-SLAVE_NAME='buildworker'
8
-SLAVE_SOCKET='localhost:9989'
9
-BUILDBOT_PWD='pass-docker'
10
-USER='vagrant'
11
-ROOT_PATH='/data/buildbot'
12
-DOCKER_PATH='/data/docker'
13
-BUILDBOT_CFG="$DOCKER_PATH/buildbot/buildbot-cfg"
14
-IP=$(grep BUILDBOT_IP /data/docker/buildbot/Vagrantfile | awk -F "'" '{ print $2; }')
15
-
16
-function run { su $USER -c "$1"; }
17
-
18
-export PATH=/bin:sbin:/usr/bin:/usr/sbin:/usr/local/bin
19
-
20
-# Exit if buildbot has already been installed
21
-[ -d "$ROOT_PATH" ] && exit 0
22
-
23
-# Setup buildbot
24
-run "mkdir -p ${ROOT_PATH}"
25
-cd ${ROOT_PATH}
26
-run "buildbot create-master master"
27
-run "cp $BUILDBOT_CFG/master.cfg master"
28
-run "sed -i 's/localhost/$IP/' master/master.cfg"
29
-run "buildslave create-slave slave $SLAVE_SOCKET $SLAVE_NAME $BUILDBOT_PWD"
30
-
31
-# Allow buildbot subprocesses (docker tests) to properly run in containers,
32
-# in particular with docker -u
33
-run "sed -i 's/^umask = None/umask = 000/' ${ROOT_PATH}/slave/buildbot.tac"
34
-
35
-# Setup supervisor
36
-cp $BUILDBOT_CFG/buildbot.conf /etc/supervisor/conf.d/buildbot.conf
37
-sed -i "s/^chmod=0700.*0700./chmod=0770\nchown=root:$USER/" /etc/supervisor/supervisord.conf
38
-kill -HUP `pgrep -f "/usr/bin/python /usr/bin/supervisord"`
39
-
40
-# Add git hook
41
-cp $BUILDBOT_CFG/post-commit $DOCKER_PATH/.git/hooks
42
-sed -i "s/localhost/$IP/" $DOCKER_PATH/.git/hooks/post-commit
43
-
44 1
deleted file mode 100644
... ...
@@ -1,32 +0,0 @@
1
-node default {
2
-    $USER = 'vagrant'
3
-    $ROOT_PATH = '/data/buildbot'
4
-    $DOCKER_PATH = '/data/docker'
5
-
6
-    exec {'apt_update': command => '/usr/bin/apt-get update' }
7
-    Package { require => Exec['apt_update'] }
8
-    group {'puppet': ensure => 'present'}
9
-
10
-    # Install dependencies
11
-    Package { ensure => 'installed' }
12
-    package { ['python-dev','python-pip','supervisor','lxc','bsdtar','git','golang']: }
13
-
14
-    file{[ '/data' ]:
15
-        owner => $USER, group => $USER, ensure => 'directory' }
16
-
17
-    file {'/var/tmp/requirements.txt':
18
-        content => template('requirements.txt') }
19
-
20
-    exec {'requirements':
21
-        require => [ Package['python-dev'], Package['python-pip'],
22
-            File['/var/tmp/requirements.txt'] ],
23
-        cwd     => '/var/tmp',
24
-        command => "/bin/sh -c '(/usr/bin/pip install -r requirements.txt;
25
-            rm /var/tmp/requirements.txt)'" }
26
-
27
-    exec {'buildbot-cfg-sh':
28
-        require => [ Package['supervisor'], Exec['requirements']],
29
-        path    => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin',
30
-        cwd     => '/data',
31
-        command => "$DOCKER_PATH/buildbot/buildbot-cfg/buildbot-cfg.sh" }
32
-}
33 1
deleted file mode 100644
... ...
@@ -1,6 +0,0 @@
1
-sqlalchemy<=0.7.9
2
-sqlalchemy-migrate>=0.7.2
3
-buildbot==0.8.7p1
4
-buildbot_slave==0.8.7p1
5
-nose==1.2.1
6
-requests==1.1.0
7 1
new file mode 100644
... ...
@@ -0,0 +1,44 @@
0
+=======
1
+testing
2
+=======
3
+
4
+This directory contains testing related files.
5
+
6
+
7
+Buildbot
8
+========
9
+
10
+Buildbot is a continuous integration system designed to automate the
11
+build/test cycle. By automatically rebuilding and testing the tree each time
12
+something has changed, build problems are pinpointed quickly, before other
13
+developers are inconvenienced by the failure.
14
+
15
+We are running buildbot in an AWS instance to verify docker passes all tests
16
+when commits get pushed to the master branch.
17
+
18
+You can check docker's buildbot instance at http://docker-ci.dotcloud.com/waterfall
19
+
20
+
21
+Deployment
22
+~~~~~~~~~~
23
+
24
+::
25
+
26
+  # Define AWS credential environment variables
27
+  export AWS_ACCESS_KEY_ID=xxxxxxxxxxxx
28
+  export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxx
29
+  export AWS_KEYPAIR_NAME=xxxxxxxxxxxx
30
+  export AWS_SSH_PRIVKEY=xxxxxxxxxxxx
31
+
32
+  # Checkout docker
33
+  git clone git://github.com/dotcloud/docker.git
34
+
35
+  # Deploy docker on AWS
36
+  cd docker/testing
37
+  vagrant up --provider=aws
38
+
39
+
40
+Buildbot AWS dependencies
41
+-------------------------
42
+
43
+vagrant, virtualbox packages and vagrant aws plugin
0 44
new file mode 100644
... ...
@@ -0,0 +1,56 @@
0
+# -*- mode: ruby -*-
1
+# vi: set ft=ruby :
2
+
3
+BOX_NAME = "docker-ci"
4
+BOX_URI = "http://files.vagrantup.com/precise64.box"
5
+AWS_AMI = "ami-d0f89fb9"
6
+DOCKER_PATH = "/data/docker"
7
+CFG_PATH = "#{DOCKER_PATH}/testing/buildbot"
8
+BUILDBOT_IP = "192.168.33.41"
9
+on_vbox = File.file?("#{File.dirname(__FILE__)}/.vagrant/machines/default/virtualbox/id") | \
10
+  Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/default/*/id").empty? & \
11
+  (on_vbox=true; ARGV.each do |arg| on_vbox &&= !arg.downcase.start_with?("--provider") end; on_vbox)
12
+USER = on_vbox ? "vagrant": "ubuntu"
13
+
14
+Vagrant::Config.run do |config|
15
+  # Setup virtual machine box. This VM configuration code is always executed.
16
+  config.vm.box = BOX_NAME
17
+  config.vm.box_url = BOX_URI
18
+  config.vm.share_folder "v-data", DOCKER_PATH, "#{File.dirname(__FILE__)}/.."
19
+  config.vm.network :hostonly, BUILDBOT_IP
20
+
21
+  # Deploy buildbot and its dependencies if it was not done
22
+  if Dir.glob("#{File.dirname(__FILE__)}/.vagrant/machines/default/*/id").empty?
23
+    pkg_cmd = "apt-get update -qq; apt-get install -q -y linux-image-3.8.0-19-generic; "
24
+    # Deploy buildbot CI
25
+    pkg_cmd << "apt-get install -q -y python-dev python-pip supervisor; " \
26
+      "pip install -r #{CFG_PATH}/requirements.txt; " \
27
+      "chown #{USER}.#{USER} /data; cd /data; " \
28
+      "#{CFG_PATH}/setup.sh #{USER} #{CFG_PATH}; "
29
+    # Install docker dependencies
30
+    pkg_cmd << "apt-get install -q -y python-software-properties; " \
31
+      "add-apt-repository -y ppa:gophers/go/ubuntu; apt-get update -qq; " \
32
+      "DEBIAN_FRONTEND=noninteractive apt-get install -q -y lxc bsdtar git golang-stable make; "
33
+    # Activate new kernel
34
+    pkg_cmd << "shutdown -r +1; "
35
+    config.vm.provision :shell, :inline => pkg_cmd
36
+  end
37
+end
38
+
39
+# Providers were added on Vagrant >= 1.1.0
40
+Vagrant::VERSION >= "1.1.0" and Vagrant.configure("2") do |config|
41
+  config.vm.provider :aws do |aws, override|
42
+    aws.access_key_id = ENV["AWS_ACCESS_KEY_ID"]
43
+    aws.secret_access_key = ENV["AWS_SECRET_ACCESS_KEY"]
44
+    aws.keypair_name = ENV["AWS_KEYPAIR_NAME"]
45
+    override.ssh.private_key_path = ENV["AWS_SSH_PRIVKEY"]
46
+    override.ssh.username = USER
47
+    aws.ami = AWS_AMI
48
+    aws.region = "us-east-1"
49
+    aws.instance_type = "m1.small"
50
+    aws.security_groups = "gateway"
51
+  end
52
+
53
+  config.vm.provider :virtualbox do |vb|
54
+  end
55
+end
0 56
new file mode 100644
... ...
@@ -0,0 +1 @@
0
+Buildbot configuration and setup files (except Vagrantfile located on ..)
0 1
new file mode 100644
... ...
@@ -0,0 +1,18 @@
0
+[program:buildmaster]
1
+command=twistd --nodaemon --no_save -y buildbot.tac
2
+directory=/data/buildbot/master
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=twistd --nodaemon --no_save -y buildbot.tac
10
+directory=/data/buildbot/slave
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,55 @@
0
+import os
1
+from buildbot.buildslave import BuildSlave
2
+from buildbot.schedulers.forcesched import ForceScheduler
3
+from buildbot.schedulers.basic import SingleBranchScheduler
4
+from buildbot.changes import filter
5
+from buildbot.config import BuilderConfig
6
+from buildbot.process.factory import BuildFactory
7
+from buildbot.steps.shell import ShellCommand
8
+from buildbot.status import html
9
+from buildbot.status.web import authz, auth
10
+
11
+PORT_WEB = 80           # Buildbot webserver port
12
+PORT_GITHUB = 8011      # Buildbot github hook port
13
+PORT_MASTER = 9989      # Port where buildbot master listen buildworkers
14
+TEST_USER = 'buildbot'  # Credential to authenticate build triggers
15
+TEST_PWD = 'docker'     # Credential to authenticate build triggers
16
+BUILDER_NAME = 'docker'
17
+BUILDPASSWORD = 'pass-docker'  # Credential to authenticate buildworkers
18
+GITHUB_DOCKER = "github.com/dotcloud/docker"
19
+DOCKER_PATH = "/data/docker"
20
+BUILDER_PATH = "/data/buildbot/slave/{0}/build".format(BUILDER_NAME)
21
+DOCKER_BUILD_PATH = BUILDER_PATH + '/src/github.com/dotcloud/docker'
22
+
23
+
24
+c = BuildmasterConfig = {}
25
+
26
+c['title'] = "Docker"
27
+c['titleURL'] = "waterfall"
28
+c['buildbotURL'] = "http://0.0.0.0:{0}/".format(PORT_WEB)
29
+c['db'] = {'db_url':"sqlite:///state.sqlite"}
30
+c['slaves'] = [BuildSlave('buildworker', BUILDPASSWORD)]
31
+c['slavePortnum'] = PORT_MASTER
32
+
33
+c['schedulers'] = [ForceScheduler(name='trigger',builderNames=[BUILDER_NAME])]
34
+c['schedulers'].append(SingleBranchScheduler(name="all",
35
+    change_filter=filter.ChangeFilter(branch='master'),treeStableTimer=None,
36
+    builderNames=[BUILDER_NAME]))
37
+
38
+# Docker test command
39
+test_cmd = ("cd /tmp; rm -rf {0}; export GOPATH={0}; go get -d {1}; cd {2}; "
40
+    "go test").format(BUILDER_PATH,GITHUB_DOCKER,DOCKER_BUILD_PATH)
41
+
42
+# Builder
43
+factory = BuildFactory()
44
+factory.addStep(ShellCommand(description='Docker',logEnviron=False,
45
+    usePTY=True,command=test_cmd))
46
+c['builders'] = [BuilderConfig(name=BUILDER_NAME,slavenames=['buildworker'],
47
+    factory=factory)]
48
+
49
+# Status
50
+authz_cfg=authz.Authz(auth=auth.BasicAuth([(TEST_USER,TEST_PWD)]),
51
+    forceBuild='auth')
52
+c['status'] = [html.WebStatus(http_port=PORT_WEB, authz=authz_cfg)]
53
+c['status'].append(html.WebStatus(http_port=PORT_GITHUB,allowForce=True,
54
+    change_hook_dialects={ 'github' : True }))
0 55
new file mode 100644
... ...
@@ -0,0 +1,6 @@
0
+sqlalchemy<=0.7.9
1
+sqlalchemy-migrate>=0.7.2
2
+buildbot==0.8.7p1
3
+buildbot_slave==0.8.7p1
4
+nose==1.2.1
5
+requests==1.1.0
0 6
new file mode 100755
... ...
@@ -0,0 +1,36 @@
0
+#!/bin/bash
1
+
2
+# Setup of buildbot configuration. Package installation is being done by
3
+# Vagrantfile
4
+# Dependencies: buildbot, buildbot-slave, supervisor
5
+
6
+USER=$1
7
+CFG_PATH=$2
8
+BUILDBOT_PATH="/data/buildbot"
9
+DOCKER_PATH="/data/docker"
10
+SLAVE_NAME="buildworker"
11
+SLAVE_SOCKET="localhost:9989"
12
+BUILDBOT_PWD="pass-docker"
13
+export PATH="/bin:sbin:/usr/bin:/usr/sbin:/usr/local/bin"
14
+
15
+function run { su $USER -c "$1"; }
16
+
17
+# Exit if buildbot has already been installed
18
+[ -d "$BUILDBOT_PATH" ] && exit 0
19
+
20
+# Setup buildbot
21
+run "mkdir -p $BUILDBOT_PATH"
22
+cd $BUILDBOT_PATH
23
+run "buildbot create-master master"
24
+run "cp $CFG_PATH/master.cfg master"
25
+run "sed -i -E 's#(DOCKER_PATH = ).+#\1\"$DOCKER_PATH\"#' master/master.cfg"
26
+run "buildslave create-slave slave $SLAVE_SOCKET $SLAVE_NAME $BUILDBOT_PWD"
27
+
28
+# Allow buildbot subprocesses (docker tests) to properly run in containers,
29
+# in particular with docker -u
30
+run "sed -i 's/^umask = None/umask = 000/' slave/buildbot.tac"
31
+
32
+# Setup supervisor
33
+cp $CFG_PATH/buildbot.conf /etc/supervisor/conf.d/buildbot.conf
34
+sed -i -E "s/^chmod=0700.+/chmod=0770\nchown=root:$USER/" /etc/supervisor/supervisord.conf
35
+kill -HUP $(pgrep -f "/usr/bin/python /usr/bin/supervisord")