Skip to content

Commit

Permalink
add dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Tardy committed Jun 27, 2016
1 parent b6f0342 commit 09844c3
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 27 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -14,7 +14,6 @@ sandbox
wheelhouse
dist
slave/
master.cfg
buildbot.tac
cfg.yml
run.sh
Expand Down
4 changes: 1 addition & 3 deletions .travis.yml
Expand Up @@ -9,11 +9,9 @@ install:
- pip install -r example/requirements.txt
- pip install --pre buildbot_pkg
- pip install --pre buildbot==0.9.0b9
- pip install --pre buildbot-slave==0.9.0b9
- pip install --pre buildbot-worker==0.9.0b9
- pip install -e .
- pip install mock

script: trial buildbot_travis/tests
after_failure: "cat _trial_temp/test.log"


12 changes: 12 additions & 0 deletions Dockerfile
@@ -0,0 +1,12 @@
FROM buildbot/buildbot-master:master
COPY example /usr/src/buildbot_travis/example

RUN \
apk add --no-cache py-cffi py-requests docker-py@testing && \
pip install 'txrequests' 'pyjade' 'txgithub' 'ldap3' 'docker-py>=1.4' && \
pip install /usr/src/buildbot_travis/example/*.whl && \
rm -r /root/.cache

WORKDIR /var/lib/buildbot
VOLUME /var/lib/buildbot
CMD ["/usr/src/buildbot_travis/example/start_buildbot.sh"]
4 changes: 2 additions & 2 deletions MANIFEST.in
@@ -1,2 +1,2 @@
include *.rst *.txt
recursive-include buildbot_travis/status/templates/ *.html
include buildbot_travis/VERSION
recursive-include buildbot_travis/static *
19 changes: 15 additions & 4 deletions buildbot_travis/configurator.py
@@ -1,6 +1,7 @@
import urlparse
import os
import uuid
import traceback

from buildbot.config import error as config_error

Expand Down Expand Up @@ -90,9 +91,14 @@ def fromDict(self, y):
config_error(
"'stages' values must be strings ; stage %s is incorrect: %s" % (s, type(s)))

PORT = int(os.environ.get('PORT', 8020))
PORT = int(os.environ.get('PORT', 8010))
self.config['buildbotURL'] = os.environ.get(
'buildbotURL', "http://localhost:%d/" % (PORT, ))

db_url = os.environ.get('BUILDBOT_DB_URL')
if db_url is not None:
self.config.setdefault('db', {'db_url': db_url})

# minimalistic config to activate new web UI
self.config['www'] = dict(port=PORT,
change_hook_dialects=self.change_hook_dialects,
Expand All @@ -113,7 +119,11 @@ def configAssertContains(self, cfg, names):
def execCustomCode(self, code, required_variables):
l = {}
# execute the code with empty global, and a given local context (that we return)
exec code in {}, l
try:
exec code in {}, l
except Exception:
config_error("custom code generated an exception {}:".format(traceback.format_exc()))
raise
for n in required_variables:
if n not in l:
config_error("custom code does not generate variable {}: {} {}".format(n, code, l))
Expand Down Expand Up @@ -214,8 +224,9 @@ def createWorkerConfigLocalWorker(self, config, name):
return worker.LocalWorker(name)

def createWorkerConfigDockerWorker(self, config, name):
return worker.DockerLatentWorker(name, uuid.uuid4(),
docker_host=config['docker_host'])
return worker.DockerLatentWorker(name, str(uuid.uuid4()),
docker_host=config['docker_host'], image=config['image'],
followStartupLogs=True)

def createWorkerConfig(self):
self.config.setdefault('workers', [])
Expand Down
3 changes: 2 additions & 1 deletion buildbot_travis/tests/test_configurator.py
Expand Up @@ -214,4 +214,5 @@ def test_worker_dockerworker(self):
}
self.c.createWorkerConfig()
self.assertIsInstance(self.c.config['workers'][0], worker.DockerLatentWorker)
self.assertEqual(self.c.config['workers'][0].name, 'foo')
self.assertEqual(self.c.config['workers'][0].name, 'foo_1')
self.assertEqual(len(self.c.config['workers']), 10)
2 changes: 1 addition & 1 deletion buildbot_travis/tests/test_integration.py
Expand Up @@ -77,7 +77,7 @@ def test_travis(self):
self.assertEqual(build['steps'][0]['name'], 'git-buildbot_travis')
self.assertEqual(build['steps'][1]['state_string'], 'triggered ' +
", ".join(["buildbot_travis-job"] * 6))
self.assertIn({u'url': u'http://localhost:8020/#builders/1/builds/3',
self.assertIn({u'url': u'http://localhost:8010/#builders/1/builds/3',
u'name': u'success: buildbot_travis-job #3'},
build['steps'][1]['urls'])
self.assertEqual(build['steps'][1]['logs'][0]['contents']['content'], travis_yml)
Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions example/db.env
@@ -0,0 +1,4 @@
# database parameters are shared between containers
POSTGRES_PASSWORD=change_me
POSTGRES_USER=buildbot
POSTGRES_DB=buildbot
25 changes: 25 additions & 0 deletions example/docker-compose.yml
@@ -0,0 +1,25 @@
version: '2'
services:
postgres:
env_file: db.env
image: "postgres:9.4"
volumes:
- /var/lib/buildbot_db:/var/lib/postgresql/data
expose:
- 5432

buildbot:
# switch between local build and dockerhub image
# build: ../
image: "buildbot/buildbot_travis"
env_file: db.env
ports:
- "8010:8010"
# for external non-docker workers, uncomment the following line
- "9989:9989"
expose:
- 9989
depends_on:
- postgres
volumes:
- /var/lib/buildbot_travis/:/var/lib/buildbot/
16 changes: 1 addition & 15 deletions example/master.cfg
@@ -1,17 +1,3 @@
from buildbot_travis import TravisConfigurator
from buildbot.plugins import buildslave

useDocker=False # by default
debug=False
c = BuildmasterConfig = {}
c['slavePortnum'] = 19989
c['slaves'] = [
buildslave.BuildSlave('slave', 'pass'),
]
if useDocker:
c['slaves'].extend([
buildslave.DockerLatentBuildSlave('docker%d' % (i,), 'pass', 'tcp://localhost:2375',
util.Property("image", "slave"), followStartupLogs=debug)
for i in range(10)])

TravisConfigurator(BuildmasterConfig, basedir, latentRunners=useDocker).fromDb() # or .fromYaml('cfg.yml')
TravisConfigurator(BuildmasterConfig, basedir).fromDb() # or .fromYaml('cfg.yml')
22 changes: 22 additions & 0 deletions example/start_buildbot.sh
@@ -0,0 +1,22 @@
#!/bin/sh
B=`pwd`
if [ ! -f $B/buildbot.tac ]
then
buildbot create-master --db="postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres/$POSTGRES_DB" $B
mv /usr/src/buildbot_travis/example/master.cfg $B/master.cfg
cp /usr/src/buildbot_travis/example/buildbot.tac $B

echo
echo buildbot is now setup on the docker host in /var/lib/buildbot
echo
echo You can now edit the configuration file there to sweet your needs!
echo
echo
fi
# wait for pg to start by trying to upgrade the master
for i in `seq 100`
do
buildbot upgrade-master $B && break
sleep 1
done
exec twistd -ny $B/buildbot.tac

0 comments on commit 09844c3

Please sign in to comment.