File tree Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Expand file tree Collapse file tree 2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -166,18 +166,21 @@ def build(self, **kwargs):
166
166
resp = self .client .api .build (** kwargs )
167
167
if isinstance (resp , six .string_types ):
168
168
return self .get (resp )
169
- events = list (json_stream (resp ))
170
- if not events :
171
- return BuildError ('Unknown' )
172
- event = events [- 1 ]
173
- if 'stream' in event :
174
- match = re .search (r'(Successfully built |sha256:)([0-9a-f]+)' ,
175
- event .get ('stream' , '' ))
176
- if match :
177
- image_id = match .group (2 )
178
- return self .get (image_id )
179
-
180
- raise BuildError (event .get ('error' ) or event )
169
+ last_event = None
170
+ for chunk in json_stream (resp ):
171
+ if 'error' in chunk :
172
+ raise BuildError (chunk ['error' ])
173
+ if 'stream' in chunk :
174
+ match = re .search (
175
+ r'(Successfully built |sha256:)([0-9a-f]+)' ,
176
+ chunk ['stream' ]
177
+ )
178
+ if match :
179
+ image_id = match .group (2 )
180
+ return self .get (image_id )
181
+ last_event = chunk
182
+
183
+ raise BuildError (last_event or 'Unknown' )
181
184
182
185
def get (self , name ):
183
186
"""
Original file line number Diff line number Diff line change @@ -28,6 +28,15 @@ def test_build_with_error(self):
28
28
assert str (cm .exception ) == ("Unknown instruction: "
29
29
"NOTADOCKERFILECOMMAND" )
30
30
31
+ def test_build_with_multiple_success (self ):
32
+ client = docker .from_env (version = TEST_API_VERSION )
33
+ image = client .images .build (tag = 'some-tag' , fileobj = io .BytesIO (
34
+ "FROM alpine\n "
35
+ "CMD echo hello world" .encode ('ascii' )
36
+ ))
37
+ self .tmp_imgs .append (image .id )
38
+ assert client .containers .run (image ) == b"hello world\n "
39
+
31
40
def test_list (self ):
32
41
client = docker .from_env (version = TEST_API_VERSION )
33
42
image = client .images .pull ('alpine:latest' )
You can’t perform that action at this time.
0 commit comments