-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
156 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"flatten" | ||
|
||
load(":tar.bzl", "tar_lib") | ||
|
||
_DOC = """Flatten multiple archives into single archive.""" | ||
|
||
def _flatten_impl(ctx): | ||
bsdtar = ctx.toolchains[tar_lib.TOOLCHAIN_TYPE] | ||
|
||
ext = tar_lib.common.compression_to_extension[ctx.attr.compression] if ctx.attr.compression else ".tar" | ||
output = ctx.actions.declare_file(ctx.attr.name + ext) | ||
|
||
args = ctx.actions.args() | ||
args.add("--create") | ||
tar_lib.common.add_compression_args(ctx.attr.compression, args) | ||
args.add("--file", output) | ||
args.add_all(ctx.files.tars, format_each = "@%s") | ||
|
||
ctx.actions.run( | ||
executable = bsdtar.tarinfo.binary, | ||
inputs = ctx.files.tars, | ||
outputs = [output], | ||
tools = bsdtar.default.files, | ||
arguments = [args], | ||
) | ||
|
||
return [ | ||
DefaultInfo(files = depset([output])), | ||
] | ||
|
||
flatten = rule( | ||
doc = _DOC, | ||
attrs = { | ||
"tars": attr.label_list( | ||
allow_files = tar_lib.common.accepted_tar_extensions, | ||
mandatory = True, | ||
allow_empty = False, | ||
doc = "List of tars to flatten", | ||
), | ||
"compression": attr.string( | ||
doc = "Compress the archive file with a supported algorithm.", | ||
values = tar_lib.common.accepted_compression_types, | ||
), | ||
}, | ||
implementation = _flatten_impl, | ||
toolchains = [tar_lib.TOOLCHAIN_TYPE], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
load("@aspect_bazel_lib//lib:tar.bzl", "tar") | ||
load("//distroless:defs.bzl", "flatten", "home", "passwd") | ||
load("//distroless/tests:asserts.bzl", "assert_tar_listing") | ||
|
||
passwd( | ||
name = "passwd", | ||
passwds = [ | ||
{ | ||
"gecos": ["root"], | ||
"gid": 0, | ||
"home": "root", | ||
"shell": "usr/bin/bash", | ||
"uid": 0, | ||
"username": "root", | ||
}, | ||
], | ||
) | ||
|
||
home( | ||
name = "home", | ||
dirs = [ | ||
{ | ||
"home": "root", | ||
"uid": 0, | ||
"gid": 0, | ||
}, | ||
{ | ||
"home": "home/nonroot", | ||
"uid": 666, | ||
"gid": 666, | ||
}, | ||
], | ||
) | ||
|
||
tar( | ||
name = "source", | ||
srcs = glob(["dir/**/*"]), | ||
compress = "xz", | ||
) | ||
|
||
flatten( | ||
name = "flatten", | ||
tars = [ | ||
":passwd", | ||
":home", | ||
":source", | ||
], | ||
) | ||
|
||
assert_tar_listing( | ||
name = "test_flatten", | ||
actual = "flatten", | ||
expected = """\ | ||
#mtree | ||
./etc/passwd nlink=0 time=0.0 mode=700 gid=0 uid=0 type=file size=33 cksum=3891093834 sha1digest=94f013494b98f8ed618ce2e670d405f818ec3915 | ||
./examples time=1672560000.0 mode=755 gid=0 uid=0 type=dir | ||
./examples/flatten time=1672560000.0 mode=755 gid=0 uid=0 type=dir | ||
./examples/flatten/dir time=1672560000.0 mode=755 gid=0 uid=0 type=dir | ||
./examples/flatten/dir/changelog nlink=0 time=1672560000.0 mode=755 gid=0 uid=0 type=file size=0 cksum=4294967295 sha1digest=da39a3ee5e6b4b0d3255bfef95601890afd80709 | ||
./examples/flatten/dir/sub time=1672560000.0 mode=755 gid=0 uid=0 type=dir | ||
./examples/flatten/dir/sub/content.txt nlink=0 time=1672560000.0 mode=755 gid=0 uid=0 type=file size=0 cksum=4294967295 sha1digest=da39a3ee5e6b4b0d3255bfef95601890afd80709 | ||
./home time=0.0 mode=755 gid=0 uid=0 type=dir | ||
./home/nonroot time=0.0 mode=755 gid=666 uid=666 type=dir | ||
./root time=0.0 mode=755 gid=0 uid=0 type=dir | ||
""", | ||
) |
Empty file.
Empty file.