mirror of https://github.com/docker/docker-py.git
Merge branch '1577-multi-success-message' of https://github.com/aaronthebaron/docker-py into aaronthebaron-1577-multi-success-message
This commit is contained in:
commit
e19aad860c
|
@ -166,18 +166,18 @@ class ImageCollection(Collection):
|
||||||
resp = self.client.api.build(**kwargs)
|
resp = self.client.api.build(**kwargs)
|
||||||
if isinstance(resp, six.string_types):
|
if isinstance(resp, six.string_types):
|
||||||
return self.get(resp)
|
return self.get(resp)
|
||||||
events = list(json_stream(resp))
|
for chunk in json_stream(resp):
|
||||||
if not events:
|
if 'error' in chunk:
|
||||||
return BuildError('Unknown')
|
raise BuildError(chunk['error'])
|
||||||
event = events[-1]
|
break
|
||||||
if 'stream' in event:
|
if 'stream' in chunk:
|
||||||
match = re.search(r'(Successfully built |sha256:)([0-9a-f]+)',
|
match = re.search(r'(Successfully built |sha256:)([0-9a-f]+)',
|
||||||
event.get('stream', ''))
|
chunk['stream'])
|
||||||
if match:
|
if match:
|
||||||
image_id = match.group(2)
|
image_id = match.group(2)
|
||||||
return self.get(image_id)
|
return self.get(image_id)
|
||||||
|
|
||||||
raise BuildError(event.get('error') or event)
|
return BuildError('Unknown')
|
||||||
|
|
||||||
def get(self, name):
|
def get(self, name):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -28,6 +28,15 @@ class ImageCollectionTest(BaseIntegrationTest):
|
||||||
assert str(cm.exception) == ("Unknown instruction: "
|
assert str(cm.exception) == ("Unknown instruction: "
|
||||||
"NOTADOCKERFILECOMMAND")
|
"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):
|
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')
|
||||||
|
|
Loading…
Reference in New Issue