mirror of https://github.com/docker/docker-py.git
Better error handling, itterate on json stream directly.
Signed-off-by: Aaron Cowdin <aaron.cowdin@gmail.com>
This commit is contained in:
parent
7dffc46234
commit
a164f4661b
|
@ -166,19 +166,18 @@ class ImageCollection(Collection):
|
|||
resp = self.client.api.build(**kwargs)
|
||||
if isinstance(resp, six.string_types):
|
||||
return self.get(resp)
|
||||
events = list(json_stream(resp))
|
||||
if not events:
|
||||
return BuildError('Unknown')
|
||||
for event in events:
|
||||
if 'stream' in event:
|
||||
for chunk in json_stream(resp):
|
||||
if 'error' in chunk:
|
||||
raise BuildError(chunk['error'])
|
||||
break
|
||||
if 'stream' in chunk:
|
||||
match = re.search(r'(Successfully built |sha256:)([0-9a-f]+)',
|
||||
event.get('stream', ''))
|
||||
chunk['stream'])
|
||||
if match:
|
||||
image_id = match.group(2)
|
||||
return self.get(image_id)
|
||||
|
||||
event = events[-1]
|
||||
raise BuildError(event.get('error') or event)
|
||||
return BuildError('Unknown')
|
||||
|
||||
def get(self, name):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue