Skip to content

Commit ac14f06

Browse files
author
Michael Maeng
committed
redo docker
1 parent 7bb680a commit ac14f06

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

python/rpdk/python/codegen.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,12 @@ def _get_plugin_information() -> Dict:
281281
@classmethod
282282
def _docker_build(cls, external_path):
283283
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
289284
command = (
290285
'/bin/bash -c "'
291286
+ " ".join(cls._update_pip_command())
292287
+ " && "
293288
+ " ".join(cls._make_pip_command(internal_path))
294-
+ '; sleep 2"'
289+
+ '"'
295290
)
296291
LOG.debug("command is '%s'", command)
297292

@@ -325,18 +320,21 @@ def _docker_build(cls, external_path):
325320

326321
docker_client = docker.from_env()
327322
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(
330329
image=image,
331330
command=command,
332-
auto_remove=True,
333331
volumes=volumes,
334-
stream=True,
335332
stdout=True,
336333
stderr=True,
337334
entrypoint="",
338335
user=localuser,
339336
)
337+
container.wait()
340338
except RequestsConnectionError as e:
341339
# it seems quite hard to reliably extract the cause from
342340
# ConnectionError. we replace it with a friendlier error message
@@ -346,13 +344,16 @@ def _docker_build(cls, external_path):
346344
)
347345
cause.__cause__ = e
348346
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:
352351
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")
356357

357358
@classmethod
358359
def _pip_build(cls, base_path):

0 commit comments

Comments
 (0)