diff options
author | Joffrey F <f.joffrey@gmail.com> | 2017-06-19 15:20:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-19 15:20:17 -0700 |
commit | bb82bcf7841107399ef04633b7c638380fbc9d9a (patch) | |
tree | fa4752a2efb94a592fb804282192c6b9d77251cc | |
parent | ce8a6ea442cfaff4ee33eb9343de10541db6bd77 (diff) | |
parent | 1223fc144fc9b529959ba554f1f5e45e63c50514 (diff) | |
download | docker-py-bb82bcf7841107399ef04633b7c638380fbc9d9a.tar.gz |
Merge pull request #1626 from datwiz/images-build-error-1625
fix #1625 where ImageCollection.build() could return with incorrect image id
-rw-r--r-- | docker/models/images.py | 7 | ||||
-rw-r--r-- | tests/integration/models_images_test.py | 11 |
2 files changed, 15 insertions, 3 deletions
diff --git a/docker/models/images.py b/docker/models/images.py index e3082ac..7e999b0 100644 --- a/docker/models/images.py +++ b/docker/models/images.py @@ -166,19 +166,20 @@ class ImageCollection(Collection): if isinstance(resp, six.string_types): return self.get(resp) last_event = None + image_id = None for chunk in json_stream(resp): if 'error' in chunk: raise BuildError(chunk['error']) if 'stream' in chunk: match = re.search( - r'(Successfully built |sha256:)([0-9a-f]+)', + r'(^Successfully built |sha256:)([0-9a-f]+)$', chunk['stream'] ) if match: image_id = match.group(2) - return self.get(image_id) last_event = chunk - + if image_id: + return self.get(image_id) raise BuildError(last_event or 'Unknown') def get(self, name): diff --git a/tests/integration/models_images_test.py b/tests/integration/models_images_test.py index 881df0a..8f812d9 100644 --- a/tests/integration/models_images_test.py +++ b/tests/integration/models_images_test.py @@ -39,6 +39,17 @@ class ImageCollectionTest(BaseIntegrationTest): self.tmp_imgs.append(image.id) assert client.containers.run(image) == b"hello world\n" + def test_build_with_success_build_output(self): + client = docker.from_env(version=TEST_API_VERSION) + image = client.images.build( + tag='dup-txt-tag', fileobj=io.BytesIO( + "FROM alpine\n" + "CMD echo Successfully built abcd1234".encode('ascii') + ) + ) + self.tmp_imgs.append(image.id) + assert client.containers.run(image) == b"Successfully built abcd1234\n" + def test_list(self): client = docker.from_env(version=TEST_API_VERSION) image = client.images.pull('alpine:latest') |