summaryrefslogtreecommitdiffhomepage
path: root/images/defs.bzl
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2020-10-15 17:19:21 -0700
committergVisor bot <gvisor-bot@google.com>2020-10-15 17:21:24 -0700
commit0a7e32bd17fb3f4aae8fdea427283cda49fe002f (patch)
treeab9367eb9cd6c226ca4857b8217de21552c294ee /images/defs.bzl
parent0d54b41e550b452bb990cca55f642169502b82f2 (diff)
Add easier-to-use docker_image target.
PiperOrigin-RevId: 337415009
Diffstat (limited to 'images/defs.bzl')
-rw-r--r--images/defs.bzl31
1 files changed, 31 insertions, 0 deletions
diff --git a/images/defs.bzl b/images/defs.bzl
new file mode 100644
index 000000000..61d7bbf73
--- /dev/null
+++ b/images/defs.bzl
@@ -0,0 +1,31 @@
+"""Helpers for Docker image generation."""
+
+def _docker_image_impl(ctx):
+ importer = ctx.actions.declare_file(ctx.label.name)
+ importer_content = [
+ "#!/bin/bash",
+ "set -euo pipefail",
+ "exec docker import " + " ".join([
+ "-c '%s'" % attr
+ for attr in ctx.attr.statements
+ ]) + " " + " ".join([
+ "'%s'" % f.path
+ for f in ctx.files.data
+ ]) + " $1",
+ "",
+ ]
+ ctx.actions.write(importer, "\n".join(importer_content), is_executable = True)
+ return [DefaultInfo(
+ runfiles = ctx.runfiles(ctx.files.data),
+ executable = importer,
+ )]
+
+docker_image = rule(
+ implementation = _docker_image_impl,
+ doc = "Tool to load a Docker image; takes a single parameter (image name).",
+ attrs = {
+ "statements": attr.string_list(doc = "Extra Dockerfile directives."),
+ "data": attr.label_list(doc = "All image data."),
+ },
+ executable = True,
+)