-
-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathBUILD.bazel
More file actions
142 lines (128 loc) · 3.37 KB
/
BUILD.bazel
File metadata and controls
142 lines (128 loc) · 3.37 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
"""
NOTE:
This is the main test used in the e2e testing.
PLEASE KEEP e2e/smoke/BUILD and examples/debian_snapshot/BUILD
IN-SYNC WITH EACH OTHER, AS WELL AS THE REST OF THE TEST FILES
(test_linux_<ARCH> files and the bullseye YAML manifest)
"""
load("@bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_distroless//distroless:defs.bzl", "cacerts", "group", "passwd")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("@tar.bzl", "tar")
COMPATIBLE_WITH = select({
"@platforms//cpu:x86_64": ["@platforms//cpu:x86_64"],
"@platforms//cpu:arm64": ["@platforms//cpu:arm64"],
}) + [
"@platforms//os:linux",
]
passwd(
name = "passwd",
entries = [
{
"uid": 0,
"gid": 0,
"home": "/root",
"shell": "/bin/bash",
"username": "r00t",
},
{
"uid": 100,
"gid": 65534,
"home": "/home/_apt",
"shell": "/usr/sbin/nologin",
"username": "_apt",
},
],
)
group(
name = "group",
entries = [
{
"name": "root",
"gid": 0,
},
{
"name": "_apt",
"gid": 65534,
},
],
)
tar(
name = "sh",
mtree = [
# needed as dpkg assumes sh is installed in a typical debian installation.
"./bin/sh type=link link=/bin/bash",
],
)
cacerts(
name = "cacerts",
package = "@bullseye//ca-certificates:data",
target_compatible_with = COMPATIBLE_WITH,
)
oci_image(
name = "image",
architecture = select({
"@platforms//cpu:arm64": "arm64",
"@platforms//cpu:x86_64": "amd64",
}),
env = {
# Required to use the SSL certs from `cacerts()`
"SSL_CERT_FILE": "/etc/ssl/certs/ca-certificates.crt",
},
os = "linux",
# NOTE: this is needed because, otherwise, bazel test //... fails, even
# when container_structure_test already has target_compatible_with.
# See 136
target_compatible_with = COMPATIBLE_WITH,
tars = [
# This target contains all the installed packages.
"@bullseye//:flat",
":sh",
":passwd",
":group",
":cacerts",
],
)
platform(
name = "linux_arm64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm64",
],
)
platform(
name = "linux_amd64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)
platform_transition_filegroup(
name = "image_platform",
srcs = [":image"],
target_platform = select({
"@platforms//cpu:arm64": ":linux_arm64",
"@platforms//cpu:x86_64": ":linux_amd64",
}),
)
oci_load(
name = "tarball",
image = ":image_platform",
repo_tags = [
"distroless/test:latest",
],
# NOTE: this is needed because, otherwise, bazel test //... fails, even
# when container_structure_test already has target_compatible_with.
# See 136
target_compatible_with = COMPATIBLE_WITH,
)
container_structure_test(
name = "test",
configs = select({
"@platforms//cpu:arm64": ["test_linux_arm64.yaml"],
"@platforms//cpu:x86_64": ["test_linux_amd64.yaml"],
}),
image = ":image_platform",
target_compatible_with = COMPATIBLE_WITH,
)