blob: 4c4460897879ccafba7285fa0dd22f59c42e00b1 [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")
Tim Windelschmidtbed76d92025-02-18 03:04:14 +01005load("//osbase/build/mkpayload:def.bzl", "efi_unified_kernel_image")
6load("//osbase/build/mkverity:def.bzl", "verity_image")
Serge Bazanski77cb6c52020-12-19 00:09:22 +01007
8go_library(
Lorenz Brund13c1c62022-03-30 19:58:58 +02009 name = "node",
Lorenz Brune306d782021-09-01 13:01:06 +020010 srcs = [
11 "ids.go",
Serge Bazanski1f789542024-05-22 14:01:50 +020012 "labels.go",
Lorenz Brun0e291a12023-06-01 12:22:45 +020013 "net_ips.go",
Serge Bazanski93d593b2023-03-28 16:43:47 +020014 "net_protocols.go",
Lorenz Brune306d782021-09-01 13:01:06 +020015 "ports.go",
Jan Schär39f4f5c2024-10-29 09:41:50 +010016 "validation.go",
Lorenz Brune306d782021-09-01 13:01:06 +020017 ],
Serge Bazanski31370b02021-01-07 16:31:14 +010018 importpath = "source.monogon.dev/metropolis/node",
Tim Windelschmidt03000772023-07-03 02:19:28 +020019 visibility = [
20 "//metropolis:__subpackages__",
21 "@io_k8s_kubernetes//pkg/registry:__subpackages__",
22 ],
Timon Stampfli91bcf462024-12-15 16:57:05 +010023 deps = ["//metropolis/proto/common"],
Serge Bazanski77cb6c52020-12-19 00:09:22 +010024)
Serge Bazanski140bddc2020-06-05 21:01:19 +020025
Lorenz Brun313816f2020-12-22 16:52:26 +010026# 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 +020027config_setting(
28 name = "debug_build",
29 values = {
30 "compilation_mode": "dbg",
31 },
32)
33
Lorenz Brun2ecccae2024-11-27 22:03:35 +010034exports_files([
35 "passwd",
36])
37
Jan Schär7c38e782025-04-29 09:23:37 +000038go_binary(
Tim Windelschmidt25e0d8f2024-12-02 23:46:24 +010039 name = "runc",
Jan Schär7c38e782025-04-29 09:23:37 +000040 embed = ["@com_github_opencontainers_runc//:runc_lib"],
41 gotags = [
42 "osusergo",
43 "netgo",
44 "seccomp",
45 ],
Jan Schär0fd36f42025-04-29 10:26:03 +000046 pure = "off",
Tim Windelschmidt25e0d8f2024-12-02 23:46:24 +010047)
48
Lorenz Brun3a99c592021-01-26 19:57:21 +010049erofs_image(
50 name = "rootfs",
Serge Bazanski140bddc2020-06-05 21:01:19 +020051 files = {
Jan Schär69b76872025-05-14 16:39:47 +000052 "/init": "//metropolis/node/minit",
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010053 "/core": "//metropolis/node/core",
Serge Bazanski140bddc2020-06-05 21:01:19 +020054
Jan Schärb86917b2025-05-14 16:31:08 +000055 # Product info
56 "/etc/product-info.json": ":product_info",
57
Jan Schär91bf1c82024-07-29 17:31:33 +020058 # CA Certificate bundle & os-release & resolv.conf & hosts
Lorenz Brun3a99c592021-01-26 19:57:21 +010059 # These should not be explicitly used by Metropolis code and are only here for compatibility with
60 # paths hardcoded by standard libraries (like Go's).
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010061 "/etc/ssl/cert.pem": "@cacerts//file",
62 "/etc/passwd": ":passwd",
63 "/etc/resolv.conf": "//osbase/net/dns:resolv.conf",
64 "/etc/hosts": "//osbase/net/dns:hosts",
Jan Schäre6c0c322025-05-12 16:14:25 +000065 "/etc/os-release": ":product_info_os_release",
Serge Bazanski140bddc2020-06-05 21:01:19 +020066
Serge Bazanski6d563ca2023-06-14 13:44:20 +020067 # Metrics exporters
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010068 "/metrics/bin/node_exporter": "@com_github_prometheus_node_exporter//:node_exporter",
Serge Bazanski6d563ca2023-06-14 13:44:20 +020069
Serge Bazanski140bddc2020-06-05 21:01:19 +020070 # Hyperkube
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010071 "/kubernetes/bin/kube": "//metropolis/node/kubernetes/hyperkube",
Serge Bazanski140bddc2020-06-05 21:01:19 +020072
73 # runsc/gVisor
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010074 "/containerd/bin/runsc": "@dev_gvisor_gvisor//runsc",
75 "/containerd/bin/containerd-shim-runsc-v1": "@dev_gvisor_gvisor//shim",
Serge Bazanski140bddc2020-06-05 21:01:19 +020076
Jan Schär0fd36f42025-04-29 10:26:03 +000077 # runc
78 "/containerd/bin/runc": ":runc",
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010079 "/containerd/bin/containerd-shim-runc-v2": "@com_github_containerd_containerd_v2//cmd/containerd-shim-runc-v2",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020080
Serge Bazanski140bddc2020-06-05 21:01:19 +020081 # Containerd
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010082 "/containerd/bin/containerd": "@com_github_containerd_containerd_v2//cmd/containerd",
Serge Bazanski140bddc2020-06-05 21:01:19 +020083
84 # Containerd config files
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010085 "/containerd/conf/runsc.toml": "//metropolis/node/kubernetes/containerd:runsc.toml",
86 "/containerd/conf/config.toml": "//metropolis/node/kubernetes/containerd:config.toml",
87 "/containerd/conf/cnispec.gojson": "//metropolis/node/kubernetes/containerd:cnispec.gojson",
Serge Bazanski140bddc2020-06-05 21:01:19 +020088
Lorenz Brun8b0431a2020-07-13 16:56:36 +020089 # Containerd preseed bundles
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010090 "/containerd/preseed/k8s.io/preseedtest.tar": "//metropolis/test/e2e/preseedtest:preseedtest_tarball",
91 "/containerd/preseed/k8s.io/pause.tar": "//metropolis/node/kubernetes/pause:pause_tarball",
Lorenz Brun8b0431a2020-07-13 16:56:36 +020092
Serge Bazanski140bddc2020-06-05 21:01:19 +020093 # CNI Plugins
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010094 "/containerd/bin/cni/loopback": "@com_github_containernetworking_plugins//plugins/main/loopback",
95 "/containerd/bin/cni/ptp": "@com_github_containernetworking_plugins//plugins/main/ptp",
96 "/containerd/bin/cni/host-local": "@com_github_containernetworking_plugins//plugins/ipam/host-local",
Serge Bazanskic3ae7582020-06-08 17:15:26 +020097
Lorenz Brun70f65b22020-07-08 17:02:47 +020098 # Delve
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010099 "/dlv": "@com_github_go_delve_delve//cmd/dlv:dlv",
Jan Schär0fd36f42025-04-29 10:26:03 +0000100
101 # file system tools
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +0100102 "/bin/mkfs.xfs": "@xfsprogs//:mkfs",
Jan Schär0fd36f42025-04-29 10:26:03 +0000103
104 # time
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +0100105 "/time/chrony": "@chrony//:chrony",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +0200106 },
Serge Bazanskia3938142022-04-04 17:04:47 +0200107 fsspecs = [
108 ":erofs-layout.fsspec",
Tim Windelschmidtc2290c22024-08-15 19:56:00 +0200109 "//osbase/build:earlydev.fsspec",
Tim Windelschmidt65bf3112024-04-08 21:32:14 +0200110 "//third_party:firmware",
Serge Bazanskia3938142022-04-04 17:04:47 +0200111 ],
Lorenz Brun3a99c592021-01-26 19:57:21 +0100112 symlinks = {
Tim Windelschmidtad4d9542025-03-24 20:20:13 +0100113 "/etc/machine-id": "/ephemeral/machine-id",
Lorenz Brun3a99c592021-01-26 19:57:21 +0100114 },
Serge Bazanski731d00a2020-02-03 19:08:07 +0100115)
116
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100117verity_image(
118 name = "verity_rootfs",
Jan Schär2add1cb2025-07-14 09:26:18 +0000119 salt = ":product_info",
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100120 source = ":rootfs",
121)
122
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200123efi_unified_kernel_image(
124 name = "kernel_efi",
Tim Windelschmidt4ebbc5f2025-07-16 16:04:35 +0200125 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 +0200126 initrd = ["//third_party:ucode"],
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200127 kernel = "//third_party/linux",
Jan Schäre6c0c322025-05-12 16:14:25 +0000128 os_release = ":product_info_os_release",
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100129 verity = ":verity_rootfs",
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200130)
131
Jan Schär5fdca562025-04-14 11:33:29 +0000132oci_os_image(
133 name = "oci_image",
134 srcs = {
135 "system": ":verity_rootfs",
136 "kernel.efi": ":kernel_efi",
137 },
Jan Schär07e69052025-05-12 16:34:15 +0000138 product_info = ":product_info",
Jan Schär5fdca562025-04-14 11:33:29 +0000139 visibility = ["//visibility:public"],
140)
141
Jan Schär3b0c8dd2025-06-23 10:32:07 +0000142oci_os_image(
143 name = "oci_image_uncompressed",
144 srcs = {
145 "system": ":verity_rootfs",
146 "kernel.efi": ":kernel_efi",
147 },
148 compression_level = 0,
149 product_info = ":product_info",
150 visibility = ["//metropolis/test/launch:__pkg__"],
151)
152
Jan Schäre6c0c322025-05-12 16:14:25 +0000153product_info(
154 name = "product_info",
155 components = [
156 "linux",
157 "kubernetes",
158 ],
Serge Bazanski662b5b32020-12-21 13:49:00 +0100159 os_id = "metropolis-node",
160 os_name = "Metropolis Node",
Jan Schäre6c0c322025-05-12 16:14:25 +0000161 out_os_release = ":product_info_os_release",
Serge Bazanski30494c12023-11-28 16:27:24 +0100162 stamp_var = "STABLE_MONOGON_metropolis_version",
Jan Schärb86917b2025-05-14 16:31:08 +0000163 visibility = [":__subpackages__"],
Lorenz Brun878f5f92020-05-12 16:15:39 +0200164)
Serge Bazanski1f789542024-05-22 14:01:50 +0200165
166go_test(
167 name = "node_test",
Jan Schär39f4f5c2024-10-29 09:41:50 +0100168 srcs = [
169 "labels_test.go",
170 "validation_test.go",
171 ],
Serge Bazanski1f789542024-05-22 14:01:50 +0200172 embed = [":node"],
Serge Bazanskidd2b80f2024-09-24 13:06:27 +0000173 deps = ["@io_k8s_apimachinery//pkg/util/validation"],
Serge Bazanski1f789542024-05-22 14:01:50 +0200174)