blob: 6168e4818c88518ba7b9ea6d11747b7b485b8eb7 [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
Jan Schär7c38e782025-04-29 09:23:37 +000036go_binary(
Tim Windelschmidt25e0d8f2024-12-02 23:46:24 +010037 name = "runc",
Jan Schär7c38e782025-04-29 09:23:37 +000038 embed = ["@com_github_opencontainers_runc//:runc_lib"],
39 gotags = [
40 "osusergo",
41 "netgo",
42 "seccomp",
43 ],
Jan Schär0fd36f42025-04-29 10:26:03 +000044 pure = "off",
Tim Windelschmidt25e0d8f2024-12-02 23:46:24 +010045)
46
Lorenz Brun3a99c592021-01-26 19:57:21 +010047erofs_image(
48 name = "rootfs",
Serge Bazanski140bddc2020-06-05 21:01:19 +020049 files = {
Jan Schär69b76872025-05-14 16:39:47 +000050 "/init": "//metropolis/node/minit",
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010051 "/core": "//metropolis/node/core",
Serge Bazanski140bddc2020-06-05 21:01:19 +020052
Jan Schärb86917b2025-05-14 16:31:08 +000053 # Product info
54 "/etc/product-info.json": ":product_info",
55
Jan Schär91bf1c82024-07-29 17:31:33 +020056 # CA Certificate bundle & os-release & resolv.conf & hosts
Lorenz Brun3a99c592021-01-26 19:57:21 +010057 # These should not be explicitly used by Metropolis code and are only here for compatibility with
58 # paths hardcoded by standard libraries (like Go's).
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010059 "/etc/ssl/cert.pem": "@cacerts//file",
60 "/etc/passwd": ":passwd",
61 "/etc/resolv.conf": "//osbase/net/dns:resolv.conf",
62 "/etc/hosts": "//osbase/net/dns:hosts",
Jan Schäre6c0c322025-05-12 16:14:25 +000063 "/etc/os-release": ":product_info_os_release",
Serge Bazanski140bddc2020-06-05 21:01:19 +020064
Serge Bazanski6d563ca2023-06-14 13:44:20 +020065 # Metrics exporters
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010066 "/metrics/bin/node_exporter": "@com_github_prometheus_node_exporter//:node_exporter",
Serge Bazanski6d563ca2023-06-14 13:44:20 +020067
Serge Bazanski140bddc2020-06-05 21:01:19 +020068 # Hyperkube
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010069 "/kubernetes/bin/kube": "//metropolis/node/kubernetes/hyperkube",
Serge Bazanski140bddc2020-06-05 21:01:19 +020070
71 # runsc/gVisor
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010072 "/containerd/bin/runsc": "@dev_gvisor_gvisor//runsc",
73 "/containerd/bin/containerd-shim-runsc-v1": "@dev_gvisor_gvisor//shim",
Serge Bazanski140bddc2020-06-05 21:01:19 +020074
Jan Schär0fd36f42025-04-29 10:26:03 +000075 # runc
76 "/containerd/bin/runc": ":runc",
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010077 "/containerd/bin/containerd-shim-runc-v2": "@com_github_containerd_containerd_v2//cmd/containerd-shim-runc-v2",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020078
Serge Bazanski140bddc2020-06-05 21:01:19 +020079 # Containerd
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010080 "/containerd/bin/containerd": "@com_github_containerd_containerd_v2//cmd/containerd",
Serge Bazanski140bddc2020-06-05 21:01:19 +020081
82 # Containerd config files
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010083 "/containerd/conf/runsc.toml": "//metropolis/node/kubernetes/containerd:runsc.toml",
84 "/containerd/conf/config.toml": "//metropolis/node/kubernetes/containerd:config.toml",
Serge Bazanski140bddc2020-06-05 21:01:19 +020085
Lorenz Brun8b0431a2020-07-13 16:56:36 +020086 # Containerd preseed bundles
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010087 "/containerd/preseed/k8s.io/preseedtest.tar": "//metropolis/test/e2e/preseedtest:preseedtest_tarball",
88 "/containerd/preseed/k8s.io/pause.tar": "//metropolis/node/kubernetes/pause:pause_tarball",
Lorenz Brun8b0431a2020-07-13 16:56:36 +020089
Lorenz Brun70f65b22020-07-08 17:02:47 +020090 # Delve
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010091 "/dlv": "@com_github_go_delve_delve//cmd/dlv:dlv",
Jan Schär0fd36f42025-04-29 10:26:03 +000092
93 # file system tools
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010094 "/bin/mkfs.xfs": "@xfsprogs//:mkfs",
Jan Schär0fd36f42025-04-29 10:26:03 +000095
96 # time
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010097 "/time/chrony": "@chrony//:chrony",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020098 },
Serge Bazanskia3938142022-04-04 17:04:47 +020099 fsspecs = [
100 ":erofs-layout.fsspec",
Tim Windelschmidtc2290c22024-08-15 19:56:00 +0200101 "//osbase/build:earlydev.fsspec",
Tim Windelschmidt65bf3112024-04-08 21:32:14 +0200102 "//third_party:firmware",
Serge Bazanskia3938142022-04-04 17:04:47 +0200103 ],
Lorenz Brun3a99c592021-01-26 19:57:21 +0100104 symlinks = {
Tim Windelschmidtad4d9542025-03-24 20:20:13 +0100105 "/etc/machine-id": "/ephemeral/machine-id",
Lorenz Brun3a99c592021-01-26 19:57:21 +0100106 },
Serge Bazanski731d00a2020-02-03 19:08:07 +0100107)
108
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100109verity_image(
110 name = "verity_rootfs",
Jan Schär2add1cb2025-07-14 09:26:18 +0000111 salt = ":product_info",
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100112 source = ":rootfs",
113)
114
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200115efi_unified_kernel_image(
116 name = "kernel_efi",
Tim Windelschmidt4ebbc5f2025-07-16 16:04:35 +0200117 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 +0200118 initrd = ["//third_party:ucode"],
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200119 kernel = "//third_party/linux",
Jan Schäre6c0c322025-05-12 16:14:25 +0000120 os_release = ":product_info_os_release",
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100121 verity = ":verity_rootfs",
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200122)
123
Jan Schär5fdca562025-04-14 11:33:29 +0000124oci_os_image(
125 name = "oci_image",
126 srcs = {
127 "system": ":verity_rootfs",
128 "kernel.efi": ":kernel_efi",
129 },
Jan Schär07e69052025-05-12 16:34:15 +0000130 product_info = ":product_info",
Jan Schär5fdca562025-04-14 11:33:29 +0000131 visibility = ["//visibility:public"],
132)
133
Jan Schär3b0c8dd2025-06-23 10:32:07 +0000134oci_os_image(
135 name = "oci_image_uncompressed",
136 srcs = {
137 "system": ":verity_rootfs",
138 "kernel.efi": ":kernel_efi",
139 },
140 compression_level = 0,
141 product_info = ":product_info",
142 visibility = ["//metropolis/test/launch:__pkg__"],
143)
144
Jan Schärd4309bb2025-07-18 10:13:22 +0200145oci_index(
146 name = "oci_multiarch",
147 src = ":oci_image",
148 platforms = [
149 "//build/platforms:linux_x86_64",
150 "//build/platforms:linux_aarch64",
151 ],
152)
153
Jan Schäre6c0c322025-05-12 16:14:25 +0000154product_info(
155 name = "product_info",
156 components = [
157 "linux",
158 "kubernetes",
159 ],
Serge Bazanski662b5b32020-12-21 13:49:00 +0100160 os_id = "metropolis-node",
161 os_name = "Metropolis Node",
Jan Schäre6c0c322025-05-12 16:14:25 +0000162 out_os_release = ":product_info_os_release",
Jan Schärd4309bb2025-07-18 10:13:22 +0200163 platform_os = "uefi",
Serge Bazanski30494c12023-11-28 16:27:24 +0100164 stamp_var = "STABLE_MONOGON_metropolis_version",
Jan Schärb86917b2025-05-14 16:31:08 +0000165 visibility = [":__subpackages__"],
Lorenz Brun878f5f92020-05-12 16:15:39 +0200166)
Serge Bazanski1f789542024-05-22 14:01:50 +0200167
168go_test(
169 name = "node_test",
Jan Schär39f4f5c2024-10-29 09:41:50 +0100170 srcs = [
171 "labels_test.go",
172 "validation_test.go",
173 ],
Serge Bazanski1f789542024-05-22 14:01:50 +0200174 embed = [":node"],
Serge Bazanskidd2b80f2024-09-24 13:06:27 +0000175 deps = ["@io_k8s_apimachinery//pkg/util/validation"],
Serge Bazanski1f789542024-05-22 14:01:50 +0200176)