blob: e69d00a54bbb6610182702a652cc5cbc96cd4bc4 [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 = [
Serge Bazanski1f789542024-05-22 14:01:50 +020012 "labels.go",
Lorenz Brun4bde9312025-08-06 05:04:11 +020013 "net_status.go",
Jan Schär39f4f5c2024-10-29 09:41:50 +010014 "validation.go",
Lorenz Brune306d782021-09-01 13:01:06 +020015 ],
Serge Bazanski31370b02021-01-07 16:31:14 +010016 importpath = "source.monogon.dev/metropolis/node",
Jan Schär0f8ce4c2025-09-04 13:27:50 +020017 visibility = ["//metropolis:__subpackages__"],
Timon Stampfli91bcf462024-12-15 16:57:05 +010018 deps = ["//metropolis/proto/common"],
Serge Bazanski77cb6c52020-12-19 00:09:22 +010019)
Serge Bazanski140bddc2020-06-05 21:01:19 +020020
Lorenz Brun313816f2020-12-22 16:52:26 +010021# 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 +020022config_setting(
23 name = "debug_build",
24 values = {
25 "compilation_mode": "dbg",
26 },
27)
28
Jan Schär7c38e782025-04-29 09:23:37 +000029go_binary(
Tim Windelschmidt25e0d8f2024-12-02 23:46:24 +010030 name = "runc",
Jan Schär7c38e782025-04-29 09:23:37 +000031 embed = ["@com_github_opencontainers_runc//:runc_lib"],
32 gotags = [
33 "osusergo",
34 "netgo",
35 "seccomp",
36 ],
Jan Schär0fd36f42025-04-29 10:26:03 +000037 pure = "off",
Tim Windelschmidt25e0d8f2024-12-02 23:46:24 +010038)
39
Lorenz Brun3a99c592021-01-26 19:57:21 +010040erofs_image(
41 name = "rootfs",
Serge Bazanski140bddc2020-06-05 21:01:19 +020042 files = {
Jan Schär69b76872025-05-14 16:39:47 +000043 "/init": "//metropolis/node/minit",
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010044 "/core": "//metropolis/node/core",
Serge Bazanski140bddc2020-06-05 21:01:19 +020045
Jan Schärb86917b2025-05-14 16:31:08 +000046 # Product info
47 "/etc/product-info.json": ":product_info",
48
Jan Schär91bf1c82024-07-29 17:31:33 +020049 # CA Certificate bundle & os-release & resolv.conf & hosts
Lorenz Brun3a99c592021-01-26 19:57:21 +010050 # These should not be explicitly used by Metropolis code and are only here for compatibility with
51 # paths hardcoded by standard libraries (like Go's).
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010052 "/etc/ssl/cert.pem": "@cacerts//file",
53 "/etc/passwd": ":passwd",
54 "/etc/resolv.conf": "//osbase/net/dns:resolv.conf",
55 "/etc/hosts": "//osbase/net/dns:hosts",
Jan Schäre6c0c322025-05-12 16:14:25 +000056 "/etc/os-release": ":product_info_os_release",
Serge Bazanski140bddc2020-06-05 21:01:19 +020057
Serge Bazanski6d563ca2023-06-14 13:44:20 +020058 # Metrics exporters
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010059 "/metrics/bin/node_exporter": "@com_github_prometheus_node_exporter//:node_exporter",
Serge Bazanski6d563ca2023-06-14 13:44:20 +020060
Serge Bazanski140bddc2020-06-05 21:01:19 +020061 # Hyperkube
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010062 "/kubernetes/bin/kube": "//metropolis/node/kubernetes/hyperkube",
Serge Bazanski140bddc2020-06-05 21:01:19 +020063
64 # runsc/gVisor
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010065 "/containerd/bin/runsc": "@dev_gvisor_gvisor//runsc",
66 "/containerd/bin/containerd-shim-runsc-v1": "@dev_gvisor_gvisor//shim",
Serge Bazanski140bddc2020-06-05 21:01:19 +020067
Jan Schär0fd36f42025-04-29 10:26:03 +000068 # runc
69 "/containerd/bin/runc": ":runc",
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010070 "/containerd/bin/containerd-shim-runc-v2": "@com_github_containerd_containerd_v2//cmd/containerd-shim-runc-v2",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020071
Serge Bazanski140bddc2020-06-05 21:01:19 +020072 # Containerd
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010073 "/containerd/bin/containerd": "@com_github_containerd_containerd_v2//cmd/containerd",
Serge Bazanski140bddc2020-06-05 21:01:19 +020074
75 # Containerd config files
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010076 "/containerd/conf/runsc.toml": "//metropolis/node/kubernetes/containerd:runsc.toml",
77 "/containerd/conf/config.toml": "//metropolis/node/kubernetes/containerd:config.toml",
Serge Bazanski140bddc2020-06-05 21:01:19 +020078
Lorenz Brun8b0431a2020-07-13 16:56:36 +020079 # Containerd preseed bundles
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010080 "/containerd/preseed/k8s.io/preseedtest.tar": "//metropolis/test/e2e/preseedtest:preseedtest_tarball",
81 "/containerd/preseed/k8s.io/pause.tar": "//metropolis/node/kubernetes/pause:pause_tarball",
Lorenz Brun8b0431a2020-07-13 16:56:36 +020082
Lorenz Brun70f65b22020-07-08 17:02:47 +020083 # Delve
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010084 "/dlv": "@com_github_go_delve_delve//cmd/dlv:dlv",
Jan Schär0fd36f42025-04-29 10:26:03 +000085
86 # file system tools
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010087 "/bin/mkfs.xfs": "@xfsprogs//:mkfs",
Jan Schär0fd36f42025-04-29 10:26:03 +000088
89 # time
Tim Windelschmidt24bf6fd2025-02-12 04:48:24 +010090 "/time/chrony": "@chrony//:chrony",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020091 },
Serge Bazanskia3938142022-04-04 17:04:47 +020092 fsspecs = [
93 ":erofs-layout.fsspec",
Tim Windelschmidtc2290c22024-08-15 19:56:00 +020094 "//osbase/build:earlydev.fsspec",
Tim Windelschmidt65bf3112024-04-08 21:32:14 +020095 "//third_party:firmware",
Serge Bazanskia3938142022-04-04 17:04:47 +020096 ],
Lorenz Brun3a99c592021-01-26 19:57:21 +010097 symlinks = {
Tim Windelschmidtad4d9542025-03-24 20:20:13 +010098 "/etc/machine-id": "/ephemeral/machine-id",
Lorenz Brun3a99c592021-01-26 19:57:21 +010099 },
Serge Bazanski731d00a2020-02-03 19:08:07 +0100100)
101
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100102verity_image(
103 name = "verity_rootfs",
Jan Schär2add1cb2025-07-14 09:26:18 +0000104 salt = ":product_info",
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100105 source = ":rootfs",
106)
107
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200108efi_unified_kernel_image(
109 name = "kernel_efi",
Tim Windelschmidt4ebbc5f2025-07-16 16:04:35 +0200110 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 +0200111 initrd = ["//third_party:ucode"],
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200112 kernel = "//third_party/linux",
Jan Schäre6c0c322025-05-12 16:14:25 +0000113 os_release = ":product_info_os_release",
Mateusz Zalega8c2c7712022-01-25 19:42:21 +0100114 verity = ":verity_rootfs",
Lorenz Brun2f9f3872021-09-29 19:48:08 +0200115)
116
Jan Schär5fdca562025-04-14 11:33:29 +0000117oci_os_image(
118 name = "oci_image",
119 srcs = {
120 "system": ":verity_rootfs",
121 "kernel.efi": ":kernel_efi",
122 },
Jan Schär07e69052025-05-12 16:34:15 +0000123 product_info = ":product_info",
Jan Schär5fdca562025-04-14 11:33:29 +0000124 visibility = ["//visibility:public"],
125)
126
Jan Schär3b0c8dd2025-06-23 10:32:07 +0000127oci_os_image(
128 name = "oci_image_uncompressed",
129 srcs = {
130 "system": ":verity_rootfs",
131 "kernel.efi": ":kernel_efi",
132 },
133 compression_level = 0,
134 product_info = ":product_info",
135 visibility = ["//metropolis/test/launch:__pkg__"],
136)
137
Jan Schärd4309bb2025-07-18 10:13:22 +0200138oci_index(
139 name = "oci_multiarch",
140 src = ":oci_image",
141 platforms = [
142 "//build/platforms:linux_x86_64",
143 "//build/platforms:linux_aarch64",
144 ],
145)
146
Jan Schäre6c0c322025-05-12 16:14:25 +0000147product_info(
148 name = "product_info",
149 components = [
150 "linux",
151 "kubernetes",
152 ],
Serge Bazanski662b5b32020-12-21 13:49:00 +0100153 os_id = "metropolis-node",
154 os_name = "Metropolis Node",
Jan Schäre6c0c322025-05-12 16:14:25 +0000155 out_os_release = ":product_info_os_release",
Jan Schärd4309bb2025-07-18 10:13:22 +0200156 platform_os = "uefi",
Serge Bazanski30494c12023-11-28 16:27:24 +0100157 stamp_var = "STABLE_MONOGON_metropolis_version",
Jan Schärb86917b2025-05-14 16:31:08 +0000158 visibility = [":__subpackages__"],
Lorenz Brun878f5f92020-05-12 16:15:39 +0200159)
Serge Bazanski1f789542024-05-22 14:01:50 +0200160
161go_test(
162 name = "node_test",
Jan Schär39f4f5c2024-10-29 09:41:50 +0100163 srcs = [
164 "labels_test.go",
165 "validation_test.go",
166 ],
Serge Bazanski1f789542024-05-22 14:01:50 +0200167 embed = [":node"],
Serge Bazanskidd2b80f2024-09-24 13:06:27 +0000168 deps = ["@io_k8s_apimachinery//pkg/util/validation"],
Serge Bazanski1f789542024-05-22 14:01:50 +0200169)