Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Dec 6, 2023
1 parent 13610e1 commit 836a04b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion distroless/private/home.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def home(name, dirs, **kwargs):
Args:
name: name of the target
dirs: an array of dicts
dirs: array of home directory dicts.
**kwargs: other named arguments to that is passed to tar. see [common rule attributes](https://bazel.build/reference/be/common-definitions#common-attributes).
"""
mtree = []
Expand Down
18 changes: 12 additions & 6 deletions distroless/private/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

BSDTAR_TOOLCHAIN = "@aspect_bazel_lib//lib:tar_toolchain_type"

def _mtree_line(file, type, content = None, uid = "0", gid = "0", time = "1672560000", mode = "0755"):
def _mtree_line(dest, type, content = None, uid = "0", gid = "0", time = "1672560000", mode = "0755"):
# mtree expects paths to start with ./ so normalize paths that starts with
# `/` or relative path (without / and ./)
if not dest.startswith("."):
if not dest.startswith("/"):
dest = "/" + dest
dest = "." + dest
spec = [
file,
dest,
"uid=" + uid,
"gid=" + gid,
"time=" + time,
Expand All @@ -21,21 +27,21 @@ def _add_parents(path, uid = "0", gid = "0", time = "1672560000", mode = "0755")
segments.pop()
for i in range(0, len(segments)):
parent = "/".join(segments[:i + 1])
if not parent or parent == ".":
if not parent:
continue
lines.append(
_mtree_line(parent.lstrip("/"), "dir", uid = uid, gid = gid, time = time, mode = mode),
_mtree_line(parent, "dir", uid = uid, gid = gid, time = time, mode = mode),
)
return lines

def _add_file_with_parents(path, file):
lines = _add_parents(path)
lines.append(_mtree_line(path.lstrip("/"), "file", content = file.path))
lines.append(_mtree_line(path, "file", content = file.path))
return lines

def _add_directory_with_parents(path, **kwargs):
lines = _add_parents(path)
lines.append(_mtree_line(path.lstrip("/"), "dir", **kwargs))
lines.append(_mtree_line(path, "dir", **kwargs))
return lines

def _build_tar(ctx, mtree, output, inputs = [], compression = "gzip", mnemonic = "Tar"):
Expand Down
2 changes: 1 addition & 1 deletion docs/rules.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/cacerts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ assert_tar_listing(
./etc/ssl time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl/certs time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl/certs/ca-certificates.crt nlink=0 time=1672560000.0 mode=755 gid=0 uid=0 type=file size=200313 cksum=3175436394 sha1digest=01b4ff230afaeeda5cddaf9a002cec9bc9a6d1b4
./etc/usr time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./usr time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./usr/share time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./usr/share/doc time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./usr/share/doc/ca-certificates time=1672560000.0 mode=755 gid=0 uid=0 type=dir
Expand Down
4 changes: 2 additions & 2 deletions examples/home/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ home(
name = "home",
dirs = [
{
"home": "./root",
"home": "/root",
"uid": 0,
"gid": 0,
},
{
"home": "./home/nonroot",
"home": "/home/nonroot",
"uid": 666,
"gid": 666,
},
Expand Down

0 comments on commit 836a04b

Please sign in to comment.