Skip to content

Commit

Permalink
refactor: set mtime to 0 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn authored Dec 8, 2023
1 parent 3b7a3de commit 813ac09
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion distroless/private/group.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def group(name, groups, **kwargs):
stamp = 0,
template = [
"#mtree",
"etc/group uid=0 gid=0 mode=0644 time=0 type=file content={content}",
"etc/group uid=0 gid=0 mode=0644 time=0.0 type=file content={content}",
"",
],
substitutions = {
Expand Down
9 changes: 7 additions & 2 deletions distroless/private/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

BSDTAR_TOOLCHAIN = "@aspect_bazel_lib//lib:tar_toolchain_type"

def _mtree_line(dest, type, content = None, uid = "0", gid = "0", time = "1672560000", mode = "0755"):
DEFAULT_GID = "0"
DEFAULT_UID = "0"
DEFAULT_TIME = "0.0"
DEFAULT_MODE = "0755"

def _mtree_line(dest, type, content = None, uid = DEFAULT_UID, gid = DEFAULT_GID, time = DEFAULT_TIME, mode = DEFAULT_MODE):
# mtree expects paths to start with ./ so normalize paths that starts with
# `/` or relative path (without / and ./)
if not dest.startswith("."):
Expand All @@ -21,7 +26,7 @@ def _mtree_line(dest, type, content = None, uid = "0", gid = "0", time = "167256
spec.append("content=" + content)
return " ".join(spec)

def _add_parents(path, uid = "0", gid = "0", time = "1672560000", mode = "0755"):
def _add_parents(path, uid = DEFAULT_UID, gid = DEFAULT_GID, time = DEFAULT_TIME, mode = DEFAULT_MODE):
lines = []
segments = path.split("/")
segments.pop()
Expand Down
18 changes: 9 additions & 9 deletions examples/cacerts/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ assert_tar_listing(
actual = "cacerts",
expected = """\
#mtree
./etc time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./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
./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
./usr/share/doc/ca-certificates/copyright nlink=0 time=1672560000.0 mode=755 gid=0 uid=0 type=file size=18940 cksum=3142022593 sha1digest=4c49e10ddbcfc0f36816df7f9cb503d665621017
./etc time=0.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl time=0.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl/certs time=0.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl/certs/ca-certificates.crt nlink=0 time=0.0 mode=755 gid=0 uid=0 type=file size=200313 cksum=3175436394 sha1digest=01b4ff230afaeeda5cddaf9a002cec9bc9a6d1b4
./usr time=0.0 mode=755 gid=0 uid=0 type=dir
./usr/share time=0.0 mode=755 gid=0 uid=0 type=dir
./usr/share/doc time=0.0 mode=755 gid=0 uid=0 type=dir
./usr/share/doc/ca-certificates time=0.0 mode=755 gid=0 uid=0 type=dir
./usr/share/doc/ca-certificates/copyright nlink=0 time=0.0 mode=755 gid=0 uid=0 type=file size=18940 cksum=3142022593 sha1digest=4c49e10ddbcfc0f36816df7f9cb503d665621017
""",
)
6 changes: 3 additions & 3 deletions examples/home/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ assert_tar_listing(
actual = "home",
expected = """\
#mtree
./home time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./home/nonroot time=1672560000.0 mode=755 gid=666 uid=666 type=dir
./root time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./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
""",
)
10 changes: 5 additions & 5 deletions examples/java_keystore/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ assert_tar_listing(
actual = "java_keystore",
expected = """\
#mtree
./etc time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./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/java time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl/certs/java/cacerts nlink=0 time=1672560000.0 mode=755 gid=0 uid=0 type=file size=5349 cksum=3752477219 sha1digest=015078faa5537fcabb6c7e73fe2dedf8241b106d
./etc time=0.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl time=0.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl/certs time=0.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl/certs/java time=0.0 mode=755 gid=0 uid=0 type=dir
./etc/ssl/certs/java/cacerts nlink=0 time=0.0 mode=755 gid=0 uid=0 type=file size=5349 cksum=3752477219 sha1digest=015078faa5537fcabb6c7e73fe2dedf8241b106d
""",
)

0 comments on commit 813ac09

Please sign in to comment.