add lxcconfig

main
Motiejus Jakštys 2021-05-24 00:11:58 +03:00
parent 8a5d9b636c
commit 4afc07bb65
1 changed files with 46 additions and 16 deletions

View File

@ -1,15 +1,28 @@
_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"],
)
def _rootfs_impl(ctx): def _rootfs_impl(ctx):
outf = ctx.attr.name + ".tar" out = ctx.actions.declare_file(ctx.attr.name + ".tar")
out = ctx.actions.declare_file(outf)
ctx.actions.run( ctx.actions.run(
outputs = [out], outputs = [out],
inputs = ctx.files.src, inputs = ctx.files.src,
executable = ctx.files._undocker[0], executable = ctx.files._undocker[0],
arguments = [ arguments = [
"rootfs", "rootfs",
ctx.files.src.to_list()[0].path, ctx.files.src[0].path,
outf, out.path,
], ],
mnemonic = "RootFS",
) )
return [DefaultInfo( return [DefaultInfo(
files = depset([out]), files = depset([out]),
@ -20,17 +33,34 @@ rootfs = rule(
doc = "Generate a rootfs from a docker container image", doc = "Generate a rootfs from a docker container image",
implementation = _rootfs_impl, implementation = _rootfs_impl,
attrs = { attrs = {
"src": attr.label( "src": _input_container,
doc = "Input container tarball", "_undocker": _undocker,
mandatory = True, },
allow_single_file = [".tar"], )
),
"_undocker": attr.label( def _lxcconfig_impl(ctx):
doc = "undocker cli; private and may not be overridden", out = ctx.actions.declare_file(ctx.attr.name + ".conf")
cfg = "host", ctx.actions.run(
default = Label("//src/undocker:undocker"), outputs = [out],
allow_single_file = True, inputs = ctx.files.src,
executable = True, executable = ctx.files._undocker[0],
), arguments = [
"lxcconfig",
ctx.files.src[0].path,
out.path,
],
mnemonic = "LXCConfig",
)
return [DefaultInfo(
files = depset([out]),
runfiles = ctx.runfiles(files = ctx.files.src),
)]
lxcconfig = rule(
doc = "Generate lxc config from a docker container image",
implementation = _lxcconfig_impl,
attrs = {
"src": _input_container,
"_undocker": _undocker,
}, },
) )