-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathBUILD.bazel
122 lines (111 loc) · 2.83 KB
/
BUILD.bazel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
load("//distroless:defs.bzl", "flatten", "home", "passwd")
load("//distroless/tests:asserts.bzl", "assert_tar_listing", "assert_tar_mtree")
passwd(
name = "passwd",
entries = [
{
"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_mtree(
name = "test_flatten",
actual = "flatten",
expected = """\
#mtree
./etc time=0.0 mode=755 gid=0 uid=0 type=dir
./etc/passwd time=0.0 mode=644 gid=0 uid=0 type=file size=34
./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 time=1672560000.0 mode=755 gid=0 uid=0 type=file size=0
./examples/flatten/dir/sub time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./examples/flatten/dir/sub/content.txt time=1672560000.0 mode=755 gid=0 uid=0 type=file size=0
./home/nonroot time=0.0 mode=700 gid=666 uid=666 type=dir
./root time=0.0 mode=700 gid=0 uid=0 type=dir
""",
)
# Flatten with deduplication
tar(
name = "source1",
srcs = glob(["dir/*"]),
compress = "xz",
)
tar(
name = "source2",
srcs = glob(["dir/**/*"]),
compress = "xz",
)
tar(
name = "source3",
srcs = glob(["dir/**/*"]),
compress = "xz",
)
flatten(
name = "flatten_dedup",
deduplicate = True,
tars = [
":source2",
":source1",
":source3",
],
)
assert_tar_mtree(
name = "test_flatten_dedup_mtree",
actual = "flatten_dedup",
expected = """\
#mtree
./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 time=1672560000.0 mode=755 gid=0 uid=0 type=file size=0
./examples/flatten/dir/sub time=1672560000.0 mode=755 gid=0 uid=0 type=dir
./examples/flatten/dir/sub/content.txt time=1672560000.0 mode=755 gid=0 uid=0 type=file size=0
""",
)
assert_tar_listing(
name = "test_flatten_dedup_listing",
actual = "flatten_dedup",
expected = """\
examples/
examples/flatten/
examples/flatten/dir/
examples/flatten/dir/changelog
examples/flatten/dir/sub/
examples/flatten/dir/sub/content.txt
""",
)