Skip to content

Commit

Permalink
docker.bzl: Detect if local Docker image is used
Browse files Browse the repository at this point in the history
Signed-off-by: Eryk Szpotanski <[email protected]>
  • Loading branch information
eszpotanski authored and glatosinski committed Sep 9, 2024
1 parent 9408cde commit 8706b06
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion docker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,31 @@ def _impl(repository_ctx):
if not docker:
fail("Failed to find {}.".format(docker_name))

image_id = repository_ctx.attr.sha256
inspect = repository_ctx.execute([
docker,
"inspect",
"--type=image",
image_id,
])
if inspect.return_code != 0:
pull = repository_ctx.execute([
docker,
"pull",
image,
])
if pull.return_code != 0:
fail("Image {} cannot be pulled: {}".format(image, pull.stderr), pull.return_code)
image_id = image
repository_ctx.report_progress("Pulled {}.".format(repository_ctx.attr.image))
else:
repository_ctx.report_progress("Using local {}.".format(repository_ctx.attr.image))

created = repository_ctx.execute(
[
docker,
"create",
image,
image_id,
],
)
if created.return_code != 0:
Expand Down

0 comments on commit 8706b06

Please sign in to comment.