summaryrefslogtreecommitdiffhomepage
path: root/images/defs.bzl
diff options
context:
space:
mode:
Diffstat (limited to 'images/defs.bzl')
-rw-r--r--images/defs.bzl34
1 files changed, 34 insertions, 0 deletions
diff --git a/images/defs.bzl b/images/defs.bzl
new file mode 100644
index 000000000..c1f96e312
--- /dev/null
+++ b/images/defs.bzl
@@ -0,0 +1,34 @@
+"""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",
+ "source_file='%s'" % ctx.file.data.path,
+ "if [[ ! -f \"$source_file\" ]]; then",
+ " source_file='%s'" % ctx.file.data.short_path,
+ "fi",
+ "exec docker import " + " ".join([
+ "-c '%s'" % attr
+ for attr in ctx.attr.statements
+ ]) + " \"$source_file\" $1",
+ "",
+ ]
+
+ ctx.actions.write(importer, "\n".join(importer_content), is_executable = True)
+ return [DefaultInfo(
+ runfiles = ctx.runfiles([ctx.file.data]),
+ executable = importer,
+ )]
+
+docker_image = rule(
+ implementation = _docker_image_impl,
+ doc = "Tool to import a Docker image; takes a single parameter (image name).",
+ attrs = {
+ "statements": attr.string_list(doc = "Extra Dockerfile directives."),
+ "data": attr.label(doc = "Image filesystem tarball", allow_single_file = [".tgz", ".tar.gz"]),
+ },
+ executable = True,
+)