Skip to content

Commit

Permalink
docker: add followStartupLogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Tardy committed Jan 14, 2015
1 parent e13c438 commit 590bc8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 12 additions & 4 deletions master/buildbot/buildslave/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class DockerLatentBuildSlave(AbstractLatentBuildSlave):
instance = None

def __init__(self, name, password, docker_host, image=None, command=None,
volumes=None, dockerfile=None, version=None, tls=None,
volumes=None, dockerfile=None, version=None, tls=None, followStartupLogs=False,
**kwargs):

if not client:
Expand All @@ -69,6 +69,7 @@ def __init__(self, name, password, docker_host, image=None, command=None,

self.volumes = []
self.binds = {}
self.followStartupLogs = followStartupLogs
for volume_string in (volumes or []):
try:
volume, bind = volume_string.split(":", 1)
Expand Down Expand Up @@ -152,12 +153,19 @@ def _thd_start_instance(self):
raise interfaces.LatentBuildSlaveFailedToSubstantiate(
'Failed to start container'
)

log.msg('Container created, Id: %s...' % instance['Id'][:6])
shortid = instance['Id'][:6]
log.msg('Container created, Id: %s...' % (shortid,))
instance['image'] = image
self.instance = instance
docker_client.start(instance['Id'], binds=self.binds)
docker_client.start(instance, binds=self.binds)
log.msg('Container started')
if self.followStartupLogs:
logs = docker_client.attach(container=instance, stdout=True, stderr=True, stream=True)
for line in logs:
log.msg("docker VM %s: %s" % (shortid, line.strip()))
if self.conn:
break
del logs
return [instance['Id'], self.image]

def stop_instance(self, fast=False):
Expand Down
4 changes: 4 additions & 0 deletions master/docs/manual/cfg-buildslaves-docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ In addition to the arguments available for any :ref:`Latent-Buildslaves`, :class
This should be a ``docker.tls.TLSConfig`` object.
See `docker-py's own documentation <http://docker-py.readthedocs.org/en/latest/tls/>`_ for more details on how to initialise this object.

``followStartupLogs``
(optional, defaults to false)
This transfers docker container's log inside master logs during slave startup (before connection). This can be useful to debug slave startup. e.g network issues, etc.

Setting up Volumes
..................

Expand Down

0 comments on commit 590bc8b

Please sign in to comment.