summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2017-05-05 15:01:16 -0700
committerJoffrey F <joffrey@docker.com>2017-05-05 15:01:16 -0700
commite19aad860cf401b8319e04366bd065e63d2f671d (patch)
tree945a33c37e0eb9f23e09ea822bcb69b86f735482
parent0a94e5a945a7c015177c75394735a78df0c62bba (diff)
parenta164f4661bb92eb962e6954836b33f6d10b173d0 (diff)
downloaddocker-py-e19aad860cf401b8319e04366bd065e63d2f671d.tar.gz
Merge branch '1577-multi-success-message' of https://github.com/aaronthebaron/docker-py into aaronthebaron-1577-multi-success-message
-rw-r--r--docker/models/images.py24
-rw-r--r--tests/integration/models_images_test.py9
2 files changed, 21 insertions, 12 deletions
diff --git a/docker/models/images.py b/docker/models/images.py
index 3fd3dc1..55e7ced 100644
--- a/docker/models/images.py
+++ b/docker/models/images.py
@@ -166,18 +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')
- event = events[-1]
- if 'stream' in event:
- match = re.search(r'(Successfully built |sha256:)([0-9a-f]+)',
- event.get('stream', ''))
- if match:
- image_id = match.group(2)
- return self.get(image_id)
-
- raise BuildError(event.get('error') or 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]+)',
+ chunk['stream'])
+ if match:
+ image_id = match.group(2)
+ return self.get(image_id)
+
+ return BuildError('Unknown')
def get(self, name):
"""
diff --git a/tests/integration/models_images_test.py b/tests/integration/models_images_test.py
index 4f8bb26..49e06f6 100644
--- a/tests/integration/models_images_test.py
+++ b/tests/integration/models_images_test.py
@@ -28,6 +28,15 @@ class ImageCollectionTest(BaseIntegrationTest):
assert str(cm.exception) == ("Unknown instruction: "
"NOTADOCKERFILECOMMAND")
+ def test_build_with_multiple_success(self):
+ client = docker.from_env(version=TEST_API_VERSION)
+ image = client.images.build(tag='some-tag', fileobj=io.BytesIO(
+ "FROM alpine\n"
+ "CMD echo hello world".encode('ascii')
+ ))
+ self.tmp_imgs.append(image.id)
+ assert client.containers.run(image) == b"hello world\n"
+
def test_list(self):
client = docker.from_env(version=TEST_API_VERSION)
image = client.images.pull('alpine:latest')