treewide: replace stampsrcs with embed
A rules_go maintainer suggested using embed instead of stampsrcs:
https://github.com/bazel-contrib/rules_go/issues/3507
For Kubernetes, this means we need to patch the version libraries.
Instead of creating a separate file for each variable, I put them all in
one file, which is parsed in an init function. This init function needs
to run before all other init functions, which access the variables.
Another benefit of this change is that versions are stamped in all
binaries which include Kubernetes client libraries, not just hyperkube.
Change-Id: Ib1157d3686fc35e0c4191d2fc8e165862a1973c7
Reviewed-on: https://review.monogon.dev/c/monogon/+/4208
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/metropolis/installer/BUILD.bazel b/metropolis/installer/BUILD.bazel
index 0fb1659..d995777 100644
--- a/metropolis/installer/BUILD.bazel
+++ b/metropolis/installer/BUILD.bazel
@@ -7,14 +7,11 @@
name = "installer_lib",
srcs = ["main.go"],
embedsrcs = [
+ "//build:copyright_line.txt", #keep
"//metropolis/node/abloader", #keep
],
importpath = "source.monogon.dev/metropolis/installer",
- stampsrcs = ["//build:stabler_status"],
visibility = ["//visibility:private"],
- x_defs = {
- "copyrightLine": "{STABLER_MONOGON_copyright}",
- },
deps = [
"//osbase/blockdev",
"//osbase/bringup",
diff --git a/metropolis/installer/main.go b/metropolis/installer/main.go
index 3d2df41..baf9cc8 100644
--- a/metropolis/installer/main.go
+++ b/metropolis/installer/main.go
@@ -32,7 +32,7 @@
//go:embed metropolis/node/abloader/abloader_bin.efi
var abloader []byte
-// Filled at linking time.
+//go:embed build/copyright_line.txt
var copyrightLine string
const mib = 1024 * 1024
diff --git a/metropolis/node/core/tconsole/BUILD.bazel b/metropolis/node/core/tconsole/BUILD.bazel
index 2cae5df..f67e9b9 100644
--- a/metropolis/node/core/tconsole/BUILD.bazel
+++ b/metropolis/node/core/tconsole/BUILD.bazel
@@ -10,12 +10,11 @@
"statusbar.go",
"tconsole.go",
],
+ embedsrcs = [
+ "//build:copyright_line.txt", #keep
+ ],
importpath = "source.monogon.dev/metropolis/node/core/tconsole",
- stampsrcs = ["//build:stabler_status"],
visibility = ["//visibility:public"],
- x_defs = {
- "copyrightLine": "{STABLER_MONOGON_copyright}",
- },
deps = [
"//metropolis/node/core/network",
"//metropolis/node/core/roleserve",
diff --git a/metropolis/node/core/tconsole/page_status.go b/metropolis/node/core/tconsole/page_status.go
index 8b08b23..7a139ac 100644
--- a/metropolis/node/core/tconsole/page_status.go
+++ b/metropolis/node/core/tconsole/page_status.go
@@ -4,6 +4,7 @@
package tconsole
import (
+ _ "embed"
"fmt"
"strings"
@@ -13,7 +14,7 @@
"source.monogon.dev/version"
)
-// Filled at linking time.
+//go:embed build/copyright_line.txt
var copyrightLine string
// pageStatusData encompasses all data to be shown within the status page.
diff --git a/metropolis/node/kubernetes/hyperkube/BUILD.bazel b/metropolis/node/kubernetes/hyperkube/BUILD.bazel
index 3930eb8..e87e738 100644
--- a/metropolis/node/kubernetes/hyperkube/BUILD.bazel
+++ b/metropolis/node/kubernetes/hyperkube/BUILD.bazel
@@ -17,24 +17,8 @@
],
)
-stamp_pkgs = [
- "k8s.io/component-base/version",
- "k8s.io/client-go/pkg/version",
-]
-
-stamp_vars = [
- "gitMajor",
- "gitMinor",
- "gitVersion",
- "gitCommit",
- "gitTreeState",
- "buildDate",
-]
-
go_binary(
name = "hyperkube",
embed = [":hyperkube_lib"],
- stampsrcs = ["//build:stabler_status"],
visibility = ["//metropolis/node:__pkg__"],
- x_defs = {"%s.%s" % (pkg, var): "{STABLER_KUBERNETES_%s}" % var for pkg in stamp_pkgs for var in stamp_vars},
)