Skip to content

Commit

Permalink
docker: no need to run image to copy files from it
Browse files Browse the repository at this point in the history
it is enough to create a stopped container

Signed-off-by: Øyvind Harboe <[email protected]>
  • Loading branch information
oharboe committed Aug 31, 2024
1 parent fceead0 commit d80332c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions docker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@ def _impl(repository_ctx):
if not docker:
fail("Failed to find {}.".format(docker_name))

run = repository_ctx.execute(
created = repository_ctx.execute(
[
docker,
"run",
"-td",
"--rm",
"create",
image,
],
)
if run.return_code != 0:
fail("Failed to start container: {}".format(run.stderr), run.return_code)
container_id = run.stdout.strip()
if created.return_code != 0:
fail("Failed to create stopped container: {}".format(created.stderr), created.return_code)
container_id = created.stdout.strip()
cp = repository_ctx.execute(
[
docker,
Expand All @@ -34,15 +32,15 @@ def _impl(repository_ctx):
".",
],
)
stop = repository_ctx.execute(
remove = repository_ctx.execute(
[
docker,
"stop",
"rm",
container_id,
],
)
if stop.return_code != 0:
print("Container {} has not been stopped".format(container_id)) # buildifier: disable=print
if remove.return_code != 0:
print("Container {} has not been removed".format(container_id)) # buildifier: disable=print
if cp.return_code != 0:
fail("Failed to copy image content: {}".format(cp.stderr), cp.return_code)

Expand Down

0 comments on commit d80332c

Please sign in to comment.