blob: 1295f0b90b883dfc0d2da8e70633b3b37c5365f7 [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 Brune306d782021-09-01 13:01:06 +020016 "ports.go",
Jan Schär39f4f5c2024-10-29 09:41:50 +010017 "validation.go",
Lorenz Brune306d782021-09-01 13:01:06 +020018 ],
Serge Bazanski31370b02021-01-07 16:31:14 +010019 importpath = "source.monogon.dev/metropolis/node",
Tim Windelschmidt03000772023-07-03 02:19:28 +020020 visibility = [
21 "//metropolis:__subpackages__",
22 "@io_k8s_kubernetes//pkg/registry:__subpackages__",
23 ],
Timon Stampfli91bcf462024-12-15 16:57:05 +010024 deps = ["//metropolis/proto/common"],
Serge Bazanski77cb6c52020-12-19 00:09:22 +010025)
Serge Bazanski140bddc2020-06-05 21:01:19 +020026
Lorenz Brun313816f2020-12-22 16:52:26 +010027# 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 +020028config_setting(
29 name = "debug_build",
30 values = {
31 "compilation_mode": "dbg",
32 },
33)
34
Lorenz Brun2ecccae2024-11-27 22:03:35 +010035exports_files([
36 "passwd",
37])
38
Jan Schär7c38e782025-04-29 09:23:37 +000039go_binary(
Tim Windelschmidt25e0d8f2024-12-02 23:46:24 +010040 name = "runc",
Jan Schär7c38e782025-04-29 09:23:37 +000041 embed = ["@com_github_opencontainers_runc//:runc_lib"],
42 gotags = [
43 "osusergo",
44 "netgo",
45 "seccomp",
46 ],
Jan Schär0fd36f42025-04-29 10:26:03 +000047 pure = "off",
Tim Windelschmidt25e0d8f2024-12-02 23:46:24 +010048)
49
Lorenz Brun3a99c592021-01-26 19:57:21 +010050erofs_image(
51 name = "rootfs",
Serge Bazanski140bddc2020-06-05 21:01:19 +020052 files = {
Jan Schär69b76872025-05-14 16:39:47 +000053 "/init": "//metropolis/node/minit",
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010054 "/core": "//metropolis/node/core",
Serge Bazanski140bddc2020-06-05 21:01:19 +020055
Jan Schärb86917b2025-05-14 16:31:08 +000056 # Product info
57 "/etc/product-info.json": ":product_info",
58
Jan Schär91bf1c82024-07-29 17:31:33 +020059 # CA Certificate bundle & os-release & resolv.conf & hosts
Lorenz Brun3a99c592021-01-26 19:57:21 +010060 # These should not be explicitly used by Metropolis code and are only here for compatibility with
61 # paths hardcoded by standard libraries (like Go's).
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010062 "/etc/ssl/cert.pem": "@cacerts//file",
63 "/etc/passwd": ":passwd",
64 "/etc/resolv.conf": "//osbase/net/dns:resolv.conf",
65 "/etc/hosts": "//osbase/net/dns:hosts",
Jan Schäre6c0c322025-05-12 16:14:25 +000066 "/etc/os-release": ":product_info_os_release",
Serge Bazanski140bddc2020-06-05 21:01:19 +020067
Serge Bazanski6d563ca2023-06-14 13:44:20 +020068 # Metrics exporters
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010069 "/metrics/bin/node_exporter": "@com_github_prometheus_node_exporter//:node_exporter",
Serge Bazanski6d563ca2023-06-14 13:44:20 +020070
Serge Bazanski140bddc2020-06-05 21:01:19 +020071 # Hyperkube
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010072 "/kubernetes/bin/kube": "//metropolis/node/kubernetes/hyperkube",
Serge Bazanski140bddc2020-06-05 21:01:19 +020073
74 # runsc/gVisor
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010075 "/containerd/bin/runsc": "@dev_gvisor_gvisor//runsc",
76 "/containerd/bin/containerd-shim-runsc-v1": "@dev_gvisor_gvisor//shim",
Serge Bazanski140bddc2020-06-05 21:01:19 +020077
Jan Schär0fd36f42025-04-29 10:26:03 +000078 # runc
79 "/containerd/bin/runc": ":runc",
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010080 "/containerd/bin/containerd-shim-runc-v2": "@com_github_containerd_containerd_v2//cmd/containerd-shim-runc-v2",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020081
Serge Bazanski140bddc2020-06-05 21:01:19 +020082 # Containerd
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010083 "/containerd/bin/containerd": "@com_github_containerd_containerd_v2//cmd/containerd",
Serge Bazanski140bddc2020-06-05 21:01:19 +020084
85 # Containerd config files
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010086 "/containerd/conf/runsc.toml": "//metropolis/node/kubernetes/containerd:runsc.toml",
87 "/containerd/conf/config.toml": "//metropolis/node/kubernetes/containerd:config.toml",
88 "/containerd/conf/cnispec.gojson": "//metropolis/node/kubernetes/containerd:cnispec.gojson",
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
Serge Bazanski140bddc2020-06-05 21:01:19 +020094 # CNI Plugins
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010095 "/containerd/bin/cni/loopback": "@com_github_containernetworking_plugins//plugins/main/loopback",
96 "/containerd/bin/cni/ptp": "@com_github_containernetworking_plugins//plugins/main/ptp",
97 "/containerd/bin/cni/host-local": "@com_github_containernetworking_plugins//plugins/ipam/host-local",
Serge Bazanskic3ae7582020-06-08 17:15:26 +020098
Lorenz Brun70f65b22020-07-08 17:02:47 +020099 # Delve
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +0100100 "/dlv": "@com_github_go_delve_delve//cmd/dlv:dlv",
Jan Schär0fd36f42025-04-29 10:26:03 +0000101
102 # file system tools
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +0100103 "/bin/mkfs.xfs": "@xfsprogs//:mkfs",
Jan Schär0fd36f42025-04-29 10:26:03 +0000104
105 # time
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +0100106 "/time/chrony": "@chrony//:chrony",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +0200107 },
Serge Bazanskia3938142022-04-04 17:04:47 +0200108 fsspecs = [
109 ":erofs-layout.fsspec",
Tim Windelschmidtc2290c22024-08-15 19:56:00 +0200110 "//osbase/build:earlydev.fsspec",
Tim Windelschmidt65bf3112024-04-08 21:32:14 +0200111 "//third_party:firmware",
Serge Bazanskia3938142022-04-04 17:04:47 +0200112 ],
Lorenz Brun3a99c592021-01-26 19:57:21 +0100113 symlinks = {
Tim Windelschmidtad4d9542025-03-24 20:20:13 +0100114 "/etc/machine-id": "/ephemeral/machine-id",
Lorenz Brun3a99c592021-01-26 19:57:21 +0100115 },
Serge Bazanski731d00a2020-02-03 19:08:07 +0100116)
117
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100118verity_image(
119 name = "verity_rootfs",
Jan Schär2add1cb2025-07-14 09:26:18 +0000120 salt = ":product_info",
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100121 source = ":rootfs",
122)
123
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200124efi_unified_kernel_image(
125 name = "kernel_efi",
Tim Windelschmidt4ebbc5f2025-07-16 16:04:35 +0200126 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 +0200127 initrd = ["//third_party:ucode"],
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200128 kernel = "//third_party/linux",
Jan Schäre6c0c322025-05-12 16:14:25 +0000129 os_release = ":product_info_os_release",
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100130 verity = ":verity_rootfs",
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200131)
132
Jan Schär5fdca562025-04-14 11:33:29 +0000133oci_os_image(
134 name = "oci_image",
135 srcs = {
136 "system": ":verity_rootfs",
137 "kernel.efi": ":kernel_efi",
138 },
Jan Schär07e69052025-05-12 16:34:15 +0000139 product_info = ":product_info",
Jan Schär5fdca562025-04-14 11:33:29 +0000140 visibility = ["//visibility:public"],
141)
142
Jan Schär3b0c8dd2025-06-23 10:32:07 +0000143oci_os_image(
144 name = "oci_image_uncompressed",
145 srcs = {
146 "system": ":verity_rootfs",
147 "kernel.efi": ":kernel_efi",
148 },
149 compression_level = 0,
150 product_info = ":product_info",
151 visibility = ["//metropolis/test/launch:__pkg__"],
152)
153
Jan Schärd4309bb2025-07-18 10:13:22 +0200154oci_index(
155 name = "oci_multiarch",
156 src = ":oci_image",
157 platforms = [
158 "//build/platforms:linux_x86_64",
159 "//build/platforms:linux_aarch64",
160 ],
161)
162
Jan Schäre6c0c322025-05-12 16:14:25 +0000163product_info(
164 name = "product_info",
165 components = [
166 "linux",
167 "kubernetes",
168 ],
Serge Bazanski662b5b32020-12-21 13:49:00 +0100169 os_id = "metropolis-node",
170 os_name = "Metropolis Node",
Jan Schäre6c0c322025-05-12 16:14:25 +0000171 out_os_release = ":product_info_os_release",
Jan Schärd4309bb2025-07-18 10:13:22 +0200172 platform_os = "uefi",
Serge Bazanski30494c12023-11-28 16:27:24 +0100173 stamp_var = "STABLE_MONOGON_metropolis_version",
Jan Schärb86917b2025-05-14 16:31:08 +0000174 visibility = [":__subpackages__"],
Lorenz Brun878f5f92020-05-12 16:15:39 +0200175)
Serge Bazanski1f789542024-05-22 14:01:50 +0200176
177go_test(
178 name = "node_test",
Jan Schär39f4f5c2024-10-29 09:41:50 +0100179 srcs = [
180 "labels_test.go",
181 "validation_test.go",
182 ],
Serge Bazanski1f789542024-05-22 14:01:50 +0200183 embed = [":node"],
Serge Bazanskidd2b80f2024-09-24 13:06:27 +0000184 deps = ["@io_k8s_apimachinery//pkg/util/validation"],
Serge Bazanski1f789542024-05-22 14:01:50 +0200185)