Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make rules_distroless generate no diff #19

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions distroless/private/group.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ load("@aspect_bazel_lib//lib:tar.bzl", "tar")
load("@aspect_bazel_lib//lib:utils.bzl", "propagate_common_rule_attributes")
load("@bazel_skylib//rules:write_file.bzl", "write_file")

def _get_attr(o, k, d):
if k in o:
return o[k]
if hasattr(o, k):
return getattr(o, k)
return d

def group(name, groups, **kwargs):
"""
Create a group file from array of dicts.
Expand All @@ -23,12 +30,12 @@ def group(name, groups, **kwargs):
# See https://www.ibm.com/docs/en/aix/7.2?topic=files-etcgroup-file#group_security__a3179518__title__1
":".join([
entry["name"],
"!", # not used. Group administrators are provided instead of group passwords.
_get_attr(entry, "password", "!"), # not used. Group administrators are provided instead of group passwords.
str(entry["gid"]),
",".join(entry["users"]),
])
for entry in groups
],
] + [""],
out = "%s.content" % name,
**common_kwargs
)
Expand Down
2 changes: 1 addition & 1 deletion distroless/private/os_release.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def os_release(name, content, path = "/usr/lib/os-release", **kwargs):
content = [
"{}={}".format(key, value)
for (key, value) in content.items()
],
] + [""],
out = "%s.content" % name,
**common_kwargs
)
Expand Down
2 changes: 1 addition & 1 deletion distroless/private/passwd.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def passwd(name, passwds, mode = "644", **kwargs):
entry["shell"],
])
for entry in passwds
],
] + [""],
out = "%s.content" % name,
**common_kwargs
)
Expand Down
2 changes: 1 addition & 1 deletion examples/flatten/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ assert_tar_listing(
actual = "flatten",
expected = """\
#mtree
./etc/passwd nlink=0 time=0.0 mode=644 gid=0 uid=0 type=file size=33 cksum=3891093834 sha1digest=94f013494b98f8ed618ce2e670d405f818ec3915
./etc/passwd nlink=0 time=0.0 mode=644 gid=0 uid=0 type=file size=34 cksum=3470383902 sha1digest=240bc4b96dc5e13ffcc715bda7aaa9665fc1069c
./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
Expand Down
11 changes: 10 additions & 1 deletion examples/group/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ group(
"cjf",
],
),
dict(
name = "nonroot",
gid = 4656,
password = "x",
users = [
"shadow",
"cjf",
],
),
],
)

Expand All @@ -28,6 +37,6 @@ assert_tar_listing(
actual = "group",
expected = """\
#mtree
./etc/group nlink=0 time=0.0 mode=644 gid=0 uid=0 type=file size=19 cksum=290415485 sha1digest=20c70f96d7939eb77c7f07bb8c0f200d89ce33b0
./etc/group nlink=0 time=0.0 mode=644 gid=0 uid=0 type=file size=46 cksum=1308212548 sha1digest=73eab1fb5cf810c5811e9594a9180bee97011ed1
""",
)
3 changes: 2 additions & 1 deletion examples/group/group.expected.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
root:!:0:shadow,cjf
root:!:0:shadow,cjf
nonroot:x:4656:shadow,cjf
4 changes: 2 additions & 2 deletions examples/os_release/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ assert_tar_listing(
actual = "os_release",
expected = """\
#mtree
./usr/lib/os-release nlink=0 time=0.0 mode=755 gid=0 uid=0 type=file size=47 cksum=1353493935 sha1digest=ae180d07c7e29e34e1e74ee7c49f371c8cf006d5
./usr/lib/os-release nlink=0 time=0.0 mode=755 gid=0 uid=0 type=file size=48 cksum=107085711 sha1digest=956eb93b9476f9fc8f93cb450adc4f716d158500
""",
)

Expand All @@ -40,6 +40,6 @@ assert_tar_listing(
actual = "os_release_alternative_path",
expected = """\
#mtree
./etc/os-release nlink=0 time=0.0 mode=755 gid=0 uid=0 type=file size=66 cksum=187595121 sha1digest=7db059bd2ee4a8606f310fa84fb29f56f151b218
./etc/os-release nlink=0 time=0.0 mode=755 gid=0 uid=0 type=file size=67 cksum=1175356314 sha1digest=ebdde6fdd9cf9876b4b592772d85817b4b482327
""",
)
2 changes: 1 addition & 1 deletion examples/os_release/content.expected.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PRETTY_NAME=Distroless
VERSION=Debian GNU/Linux
VERSION=Debian GNU/Linux
2 changes: 1 addition & 1 deletion examples/passwd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ assert_tar_listing(
actual = "passwd",
expected = """\
#mtree
./etc/passwd nlink=0 time=0.0 mode=644 gid=0 uid=0 type=file size=35 cksum=2298809208 sha1digest=31ad675c1210fd0413dd9b2441aaaf13c18d1547
./etc/passwd nlink=0 time=0.0 mode=644 gid=0 uid=0 type=file size=36 cksum=216816702 sha1digest=a158dcecfd75d6502cdb1086eb5b0756d08fc423
""",
)
2 changes: 1 addition & 1 deletion examples/passwd/passwd.expected.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
root:!:0:0:root:/root:/usr/bin/bash
root:!:0:0:root:/root:/usr/bin/bash
Loading