-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathpython.bzl
More file actions
105 lines (93 loc) 路 3.47 KB
/
Copy pathpython.bzl
File metadata and controls
105 lines (93 loc) 路 3.47 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
"python3 image definitions"
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index")
load("//common:variables.bzl", "DEBUG_MODE", "OS_RELEASE", "USERS")
load("//private/util:deb.bzl", "deb")
load("//private/util:tar.bzl", "tar")
load(":version.bzl", "clean_python_version")
DISTRO_VERSION = {
"debian13": "3.13",
}
def python_alias(distro):
if native.existing_rule("python_aliases_" + distro):
return
tar(
name = "python_aliases_" + distro,
extension = "tar.gz",
symlinks = {
"/usr/bin/python": "/usr/bin/python" + DISTRO_VERSION[distro],
"/usr/bin/python3": "/usr/bin/python" + DISTRO_VERSION[distro],
},
)
def python3_image_index(distro, architectures):
"""python image index for a distro
Args:
distro: name of distribution
architectures: all architectures included in index
"""
for mode in DEBUG_MODE:
for user in USERS:
oci_image_index(
name = "python3" + mode + "_" + user + "_" + distro,
images = [
"python3" + mode + "_" + user + "_" + arch + "_" + distro
for arch in architectures
],
)
def python3_image(distro, arch, packages):
"""python3 and debug image with tests.
Args:
distro: name of distribution
arch: the target architecture
packages: list of debian packages to include
"""
python_alias(distro)
_python_version = clean_python_version(deb.version(
arch,
distro,
"python" + DISTRO_VERSION[distro] + "-minimal",
"python",
))
for mode in DEBUG_MODE:
for user in USERS:
oci_image(
name = "python3" + mode + "_" + user + "_" + arch + "_" + distro,
# Based on //cc so that C extensions work properly.
base = "//cc:cc" + mode + "_" + user + "_" + arch + "_" + distro,
entrypoint = [
"/usr/bin/python" + DISTRO_VERSION[distro],
],
# Use UTF-8 encoding for file system: match modern Linux
env = {"LANG": "C.UTF-8"},
tars = [
deb.package(arch, distro, pkg, "python")
for pkg in packages
] + [":python_aliases_%s" % distro] + ([":ldconfig_cache_" + arch] if distro == "debian13" else []),
annotations = {
"org.opencontainers.image.source": OS_RELEASE["HOME_URL"],
"com.google.distroless.python.version": _python_version,
},
)
for user in USERS:
container_structure_test(
name = "python3_" + user + "_" + arch + "_" + distro + "_test",
size = "medium",
configs = ["testdata/python3.yaml"],
image = ":python3_" + user + "_" + arch + "_" + distro,
tags = [
"manual",
arch,
],
)
# tests for version-specific things
for user in USERS:
container_structure_test(
name = "version_specific_" + user + "_" + arch + "_" + distro + "_test",
size = "medium",
configs = ["testdata/" + distro + ".yaml"],
image = ":python3_" + user + "_" + arch + "_" + distro,
tags = [
"manual",
arch,
],
)