From 3458dd2fad1176665262d9ccbd1e17a8d083450c Mon Sep 17 00:00:00 2001 From: Ben Firshman Date: Wed, 18 Dec 2013 16:12:53 +0000 Subject: [PATCH] Print build output --- plum/service.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/plum/service.py b/plum/service.py index d8e7f235d..8a862bc14 100644 --- a/plum/service.py +++ b/plum/service.py @@ -4,6 +4,11 @@ import re log = logging.getLogger(__name__) + +class BuildError(Exception): + pass + + class Service(object): def __init__(self, name, client=None, links=[], **options): if not re.match('^[a-zA-Z0-9_]+$', name): @@ -50,7 +55,6 @@ class Service(object): raise def start_container(self, container=None, **override_options): - container_options = self._get_container_options(override_options) if container is None: container = self.create_container(**override_options) port_bindings = {} @@ -61,7 +65,7 @@ class Service(object): port_bindings[int(internal_port)] = int(external_port) else: port_bindings[int(port)] = None - log.info("Starting %s..." % container_options['name']) + log.info("Starting %s..." % container['Id']) self.client.start( container['Id'], links=self._get_links(), @@ -108,11 +112,29 @@ class Service(object): container_options['ports'] = [unicode(p).split(':')[0] for p in container_options['ports']] if 'build' in self.options: - log.info('Building %s from %s...' % (self.name, self.options['build'])) - container_options['image'] = self.client.build(self.options['build'])[0] + container_options['image'] = self.build() return container_options + def build(self): + log.info('Building %s from %s...' % (self.name, self.options['build'])) + + build_output = self.client.build(self.options['build'], stream=True) + + image_id = None + + for line in build_output: + if line: + match = re.search(r'Successfully built ([0-9a-f]+)', line) + if match: + image_id = match.group(1) + print line + + if image_id is None: + raise BuildError() + + return image_id + def make_name(prefix, number): return '%s_%s' % (prefix, number) @@ -130,6 +152,10 @@ def parse_name(name): def get_container_name(container): + # inspect + if 'Name' in container: + return container['Name'] + # ps for name in container['Names']: if len(name.split('/')) == 2: return name[1:]