@@ -281,17 +281,12 @@ def _get_plugin_information() -> Dict:
281
281
@classmethod
282
282
def _docker_build (cls , external_path ):
283
283
internal_path = PurePosixPath ("/project" )
284
- # There is a logging bug in docker-py that requires a delay to get logs
285
- # in case there is an abnormal exit
286
- # https://github.com/docker/docker-py/issues/2427
287
- # https://github.com/docker/docker-py/issues/2655
288
- # https://github.com/docker/docker-py/pull/2282
289
284
command = (
290
285
'/bin/bash -c "'
291
286
+ " " .join (cls ._update_pip_command ())
292
287
+ " && "
293
288
+ " " .join (cls ._make_pip_command (internal_path ))
294
- + '; sleep 2 "'
289
+ + '"'
295
290
)
296
291
LOG .debug ("command is '%s'" , command )
297
292
@@ -325,18 +320,21 @@ def _docker_build(cls, external_path):
325
320
326
321
docker_client = docker .from_env ()
327
322
try :
328
- logs = []
329
- logs = docker_client .containers .run (
323
+ # There is a logging bug in docker-py that requires a delay to get logs
324
+ # in case there is an abnormal exit and container is removed
325
+ # https://github.com/docker/docker-py/issues/2427
326
+ # https://github.com/docker/docker-py/issues/2655
327
+ # https://github.com/docker/docker-py/pull/2282
328
+ container = docker_client .containers .run (
330
329
image = image ,
331
330
command = command ,
332
- auto_remove = True ,
333
331
volumes = volumes ,
334
- stream = True ,
335
332
stdout = True ,
336
333
stderr = True ,
337
334
entrypoint = "" ,
338
335
user = localuser ,
339
336
)
337
+ container .wait ()
340
338
except RequestsConnectionError as e :
341
339
# it seems quite hard to reliably extract the cause from
342
340
# ConnectionError. we replace it with a friendlier error message
@@ -346,13 +344,16 @@ def _docker_build(cls, external_path):
346
344
)
347
345
cause .__cause__ = e
348
346
raise DownstreamError ("Error running docker build" ) from cause
349
- except (ContainerError , ImageLoadError , APIError ) as e :
350
- for line in logs : # pragma: no cover
351
- LOG .error (line .rstrip (b"\n " ).decode ("utf-8" ))
347
+ except (ContainerError ) as e :
348
+ LOG .error (container .logs ().rstrip (b"\n " ).decode ("utf-8" ))
349
+ raise DownstreamError ("Container Error during docker build" ) from e
350
+ except (ImageLoadError , APIError ) as e :
352
351
raise DownstreamError ("Error running docker build" ) from e
353
- LOG .debug ("Build running. Output:" )
354
- for line in logs :
355
- LOG .debug (line .rstrip (b"\n " ).decode ("utf-8" ))
352
+ finally :
353
+ try :
354
+ container .remove ()
355
+ except NameError :
356
+ raise DownstreamError ("Docker Container not created" )
356
357
357
358
@classmethod
358
359
def _pip_build (cls , base_path ):
0 commit comments