Kaydet (Commit) bb82bcf7 authored tarafından Joffrey F's avatar Joffrey F Kaydeden (comit) GitHub

Merge pull request #1626 from datwiz/images-build-error-1625

fix #1625 where ImageCollection.build() could return with incorrect image id
...@@ -166,19 +166,20 @@ class ImageCollection(Collection): ...@@ -166,19 +166,20 @@ class ImageCollection(Collection):
if isinstance(resp, six.string_types): if isinstance(resp, six.string_types):
return self.get(resp) return self.get(resp)
last_event = None last_event = None
image_id = None
for chunk in json_stream(resp): for chunk in json_stream(resp):
if 'error' in chunk: if 'error' in chunk:
raise BuildError(chunk['error']) raise BuildError(chunk['error'])
if 'stream' in chunk: if 'stream' in chunk:
match = re.search( match = re.search(
r'(Successfully built |sha256:)([0-9a-f]+)', r'(^Successfully built |sha256:)([0-9a-f]+)$',
chunk['stream'] chunk['stream']
) )
if match: if match:
image_id = match.group(2) image_id = match.group(2)
return self.get(image_id)
last_event = chunk last_event = chunk
if image_id:
return self.get(image_id)
raise BuildError(last_event or 'Unknown') raise BuildError(last_event or 'Unknown')
def get(self, name): def get(self, name):
......
...@@ -39,6 +39,17 @@ class ImageCollectionTest(BaseIntegrationTest): ...@@ -39,6 +39,17 @@ class ImageCollectionTest(BaseIntegrationTest):
self.tmp_imgs.append(image.id) self.tmp_imgs.append(image.id)
assert client.containers.run(image) == b"hello world\n" 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): def test_list(self):
client = docker.from_env(version=TEST_API_VERSION) client = docker.from_env(version=TEST_API_VERSION)
image = client.images.pull('alpine:latest') image = client.images.pull('alpine:latest')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment