File tree Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Original file line number Diff line number Diff line change @@ -166,18 +166,18 @@ 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
+ for chunk in json_stream (resp ):
170
+ if 'error' in chunk :
171
+ raise BuildError (chunk [ 'error' ] )
172
+ break
173
+ if 'stream' in chunk :
174
+ match = re .search (r'(Successfully built |sha256:)([0-9a-f]+)' ,
175
+ chunk [ 'stream' ] )
176
+ if match :
177
+ image_id = match .group (2 )
178
+ return self .get (image_id )
179
+
180
+ return BuildError ('Unknown' )
181
181
182
182
def get (self , name ):
183
183
"""
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