undocker/rules.bzl

45 lines
1.1 KiB
Python
Raw Normal View History

2021-05-24 00:11:58 +03:00
load("@rules_pkg//:pkg.bzl", "pkg_tar")
2021-05-24 00:11:58 +03:00
_undocker_cli = attr.label(
doc = "undocker cli; private and may not be overridden",
cfg = "host",
default = Label("//src/undocker:undocker"),
allow_single_file = True,
executable = True,
)
_input_container = attr.label(
doc = "Input container tarball",
mandatory = True,
allow_single_file = [".tar"],
)
2021-05-24 00:11:58 +03:00
def _rootfs_impl(ctx):
2021-05-24 00:11:58 +03:00
out = ctx.outputs.out
if out == None:
out = ctx.actions.declare_file(ctx.attr.name + ".tar")
2021-05-24 00:11:58 +03:00
ctx.actions.run(
2021-05-24 00:11:58 +03:00
outputs = [out],
2021-05-24 00:11:58 +03:00
inputs = ctx.files.src,
2021-05-24 00:11:58 +03:00
executable = ctx.executable._undocker,
2021-05-24 00:11:58 +03:00
arguments = [
2021-05-24 00:11:58 +03:00
ctx.files.src[0].path,
out.path,
2021-05-24 00:11:58 +03:00
],
2021-05-24 00:11:58 +03:00
mnemonic = "RootFS",
2021-05-24 00:11:58 +03:00
)
2021-05-24 00:11:58 +03:00
return DefaultInfo(
2021-05-24 00:11:58 +03:00
files = depset([out]),
runfiles = ctx.runfiles(files = ctx.files.src),
2021-05-24 00:11:58 +03:00
)
2021-05-24 00:11:58 +03:00
rootfs = rule(
2021-05-24 00:11:58 +03:00
_rootfs_impl,
2021-05-24 00:11:58 +03:00
doc = "Generate a rootfs from a docker container image",
attrs = {
2021-05-24 00:11:58 +03:00
"src": _input_container,
2021-05-24 00:11:58 +03:00
"_undocker": _undocker_cli,
2021-05-24 00:11:58 +03:00
"out": attr.output(),
2021-05-24 00:11:58 +03:00
},
)