summaryrefslogtreecommitdiffhomepage
path: root/images/defs.bzl
blob: 61d7bbf735777ca23a08b9f3a128a2cb79c6992a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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,
)