blob: d568e377e9b1567b7ef08809f2434ea2cc08fc4f [file] [log] [blame]
Jan Schär7c38e782025-04-29 09:23:37 +00001load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
Jan Schäre6c0c322025-05-12 16:14:25 +00002load("//osbase/build/genproductinfo:defs.bzl", "product_info")
Tim Windelschmidtbed76d92025-02-18 03:04:14 +01003load("//osbase/build/mkerofs:def.bzl", "erofs_image")
Jan Schär5fdca562025-04-14 11:33:29 +00004load("//osbase/build/mkoci:def.bzl", "oci_os_image")
Jan Schärd4309bb2025-07-18 10:13:22 +02005load("//osbase/build/mkoci/index:def.bzl", "oci_index")
Tim Windelschmidtbed76d92025-02-18 03:04:14 +01006load("//osbase/build/mkpayload:def.bzl", "efi_unified_kernel_image")
7load("//osbase/build/mkverity:def.bzl", "verity_image")
Serge Bazanski77cb6c52020-12-19 00:09:22 +01008
9go_library(
Lorenz Brund13c1c62022-03-30 19:58:58 +020010 name = "node",
Lorenz Brune306d782021-09-01 13:01:06 +020011 srcs = [
12 "ids.go",
Serge Bazanski1f789542024-05-22 14:01:50 +020013 "labels.go",
Lorenz Brun0e291a12023-06-01 12:22:45 +020014 "net_ips.go",
Serge Bazanski93d593b2023-03-28 16:43:47 +020015 "net_protocols.go",
Lorenz Brun4bde9312025-08-06 05:04:11 +020016 "net_status.go",
Lorenz Brune306d782021-09-01 13:01:06 +020017 "ports.go",
Jan Schär39f4f5c2024-10-29 09:41:50 +010018 "validation.go",
Lorenz Brune306d782021-09-01 13:01:06 +020019 ],
Serge Bazanski31370b02021-01-07 16:31:14 +010020 importpath = "source.monogon.dev/metropolis/node",
Tim Windelschmidt03000772023-07-03 02:19:28 +020021 visibility = [
22 "//metropolis:__subpackages__",
23 "@io_k8s_kubernetes//pkg/registry:__subpackages__",
24 ],
Timon Stampfli91bcf462024-12-15 16:57:05 +010025 deps = ["//metropolis/proto/common"],
Serge Bazanski77cb6c52020-12-19 00:09:22 +010026)
Serge Bazanski140bddc2020-06-05 21:01:19 +020027
Lorenz Brun313816f2020-12-22 16:52:26 +010028# debug_build checks if we're building in debug mode and enables various debug features for the image.
Lorenz Brun70f65b22020-07-08 17:02:47 +020029config_setting(
30 name = "debug_build",
31 values = {
32 "compilation_mode": "dbg",
33 },
34)
35
Lorenz Brun2ecccae2024-11-27 22:03:35 +010036exports_files([
37 "passwd",
38])
39
Jan Schär7c38e782025-04-29 09:23:37 +000040go_binary(
Tim Windelschmidt25e0d8f2024-12-02 23:46:24 +010041 name = "runc",
Jan Schär7c38e782025-04-29 09:23:37 +000042 embed = ["@com_github_opencontainers_runc//:runc_lib"],
43 gotags = [
44 "osusergo",
45 "netgo",
46 "seccomp",
47 ],
Jan Schär0fd36f42025-04-29 10:26:03 +000048 pure = "off",
Tim Windelschmidt25e0d8f2024-12-02 23:46:24 +010049)
50
Lorenz Brun3a99c592021-01-26 19:57:21 +010051erofs_image(
52 name = "rootfs",
Serge Bazanski140bddc2020-06-05 21:01:19 +020053 files = {
Jan Schär69b76872025-05-14 16:39:47 +000054 "/init": "//metropolis/node/minit",
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010055 "/core": "//metropolis/node/core",
Serge Bazanski140bddc2020-06-05 21:01:19 +020056
Jan Schärb86917b2025-05-14 16:31:08 +000057 # Product info
58 "/etc/product-info.json": ":product_info",
59
Jan Schär91bf1c82024-07-29 17:31:33 +020060 # CA Certificate bundle & os-release & resolv.conf & hosts
Lorenz Brun3a99c592021-01-26 19:57:21 +010061 # These should not be explicitly used by Metropolis code and are only here for compatibility with
62 # paths hardcoded by standard libraries (like Go's).
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010063 "/etc/ssl/cert.pem": "@cacerts//file",
64 "/etc/passwd": ":passwd",
65 "/etc/resolv.conf": "//osbase/net/dns:resolv.conf",
66 "/etc/hosts": "//osbase/net/dns:hosts",
Jan Schäre6c0c322025-05-12 16:14:25 +000067 "/etc/os-release": ":product_info_os_release",
Serge Bazanski140bddc2020-06-05 21:01:19 +020068
Serge Bazanski6d563ca2023-06-14 13:44:20 +020069 # Metrics exporters
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010070 "/metrics/bin/node_exporter": "@com_github_prometheus_node_exporter//:node_exporter",
Serge Bazanski6d563ca2023-06-14 13:44:20 +020071
Serge Bazanski140bddc2020-06-05 21:01:19 +020072 # Hyperkube
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010073 "/kubernetes/bin/kube": "//metropolis/node/kubernetes/hyperkube",
Serge Bazanski140bddc2020-06-05 21:01:19 +020074
75 # runsc/gVisor
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010076 "/containerd/bin/runsc": "@dev_gvisor_gvisor//runsc",
77 "/containerd/bin/containerd-shim-runsc-v1": "@dev_gvisor_gvisor//shim",
Serge Bazanski140bddc2020-06-05 21:01:19 +020078
Jan Schär0fd36f42025-04-29 10:26:03 +000079 # runc
80 "/containerd/bin/runc": ":runc",
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010081 "/containerd/bin/containerd-shim-runc-v2": "@com_github_containerd_containerd_v2//cmd/containerd-shim-runc-v2",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020082
Serge Bazanski140bddc2020-06-05 21:01:19 +020083 # Containerd
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010084 "/containerd/bin/containerd": "@com_github_containerd_containerd_v2//cmd/containerd",
Serge Bazanski140bddc2020-06-05 21:01:19 +020085
86 # Containerd config files
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010087 "/containerd/conf/runsc.toml": "//metropolis/node/kubernetes/containerd:runsc.toml",
88 "/containerd/conf/config.toml": "//metropolis/node/kubernetes/containerd:config.toml",
Serge Bazanski140bddc2020-06-05 21:01:19 +020089
Lorenz Brun8b0431a2020-07-13 16:56:36 +020090 # Containerd preseed bundles
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010091 "/containerd/preseed/k8s.io/preseedtest.tar": "//metropolis/test/e2e/preseedtest:preseedtest_tarball",
92 "/containerd/preseed/k8s.io/pause.tar": "//metropolis/node/kubernetes/pause:pause_tarball",
Lorenz Brun8b0431a2020-07-13 16:56:36 +020093
Lorenz Brun70f65b22020-07-08 17:02:47 +020094 # Delve
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010095 "/dlv": "@com_github_go_delve_delve//cmd/dlv:dlv",
Jan Schär0fd36f42025-04-29 10:26:03 +000096
97 # file system tools
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010098 "/bin/mkfs.xfs": "@xfsprogs//:mkfs",
Jan Schär0fd36f42025-04-29 10:26:03 +000099
100 # time
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +0100101 "/time/chrony": "@chrony//:chrony",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +0200102 },
Serge Bazanskia3938142022-04-04 17:04:47 +0200103 fsspecs = [
104 ":erofs-layout.fsspec",
Tim Windelschmidtc2290c22024-08-15 19:56:00 +0200105 "//osbase/build:earlydev.fsspec",
Tim Windelschmidt65bf3112024-04-08 21:32:14 +0200106 "//third_party:firmware",
Serge Bazanskia3938142022-04-04 17:04:47 +0200107 ],
Lorenz Brun3a99c592021-01-26 19:57:21 +0100108 symlinks = {
Tim Windelschmidtad4d9542025-03-24 20:20:13 +0100109 "/etc/machine-id": "/ephemeral/machine-id",
Lorenz Brun3a99c592021-01-26 19:57:21 +0100110 },
Serge Bazanski731d00a2020-02-03 19:08:07 +0100111)
112
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100113verity_image(
114 name = "verity_rootfs",
Jan Schär2add1cb2025-07-14 09:26:18 +0000115 salt = ":product_info",
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100116 source = ":rootfs",
117)
118
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200119efi_unified_kernel_image(
120 name = "kernel_efi",
Tim Windelschmidt4ebbc5f2025-07-16 16:04:35 +0200121 cmdline = "console=ttyS0,115200 console=ttyS1,115200 console=ttyAMA0 quiet rootfstype=erofs init=/init loadpin.exclude=kexec-image,kexec-initramfs kernel.unknown_nmi_panic=1",
Tim Windelschmidt65bf3112024-04-08 21:32:14 +0200122 initrd = ["//third_party:ucode"],
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200123 kernel = "//third_party/linux",
Jan Schäre6c0c322025-05-12 16:14:25 +0000124 os_release = ":product_info_os_release",
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100125 verity = ":verity_rootfs",
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200126)
127
Jan Schär5fdca562025-04-14 11:33:29 +0000128oci_os_image(
129 name = "oci_image",
130 srcs = {
131 "system": ":verity_rootfs",
132 "kernel.efi": ":kernel_efi",
133 },
Jan Schär07e69052025-05-12 16:34:15 +0000134 product_info = ":product_info",
Jan Schär5fdca562025-04-14 11:33:29 +0000135 visibility = ["//visibility:public"],
136)
137
Jan Schär3b0c8dd2025-06-23 10:32:07 +0000138oci_os_image(
139 name = "oci_image_uncompressed",
140 srcs = {
141 "system": ":verity_rootfs",
142 "kernel.efi": ":kernel_efi",
143 },
144 compression_level = 0,
145 product_info = ":product_info",
146 visibility = ["//metropolis/test/launch:__pkg__"],
147)
148
Jan Schärd4309bb2025-07-18 10:13:22 +0200149oci_index(
150 name = "oci_multiarch",
151 src = ":oci_image",
152 platforms = [
153 "//build/platforms:linux_x86_64",
154 "//build/platforms:linux_aarch64",
155 ],
156)
157
Jan Schäre6c0c322025-05-12 16:14:25 +0000158product_info(
159 name = "product_info",
160 components = [
161 "linux",
162 "kubernetes",
163 ],
Serge Bazanski662b5b32020-12-21 13:49:00 +0100164 os_id = "metropolis-node",
165 os_name = "Metropolis Node",
Jan Schäre6c0c322025-05-12 16:14:25 +0000166 out_os_release = ":product_info_os_release",
Jan Schärd4309bb2025-07-18 10:13:22 +0200167 platform_os = "uefi",
Serge Bazanski30494c12023-11-28 16:27:24 +0100168 stamp_var = "STABLE_MONOGON_metropolis_version",
Jan Schärb86917b2025-05-14 16:31:08 +0000169 visibility = [":__subpackages__"],
Lorenz Brun878f5f92020-05-12 16:15:39 +0200170)
Serge Bazanski1f789542024-05-22 14:01:50 +0200171
172go_test(
173 name = "node_test",
Jan Schär39f4f5c2024-10-29 09:41:50 +0100174 srcs = [
175 "labels_test.go",
176 "validation_test.go",
177 ],
Serge Bazanski1f789542024-05-22 14:01:50 +0200178 embed = [":node"],
Serge Bazanskidd2b80f2024-09-24 13:06:27 +0000179 deps = ["@io_k8s_apimachinery//pkg/util/validation"],
Serge Bazanski1f789542024-05-22 14:01:50 +0200180)