metropolis: use //version

This switches over the Metropolis codebase from the previous build
stamping system to the new //version library.

Change-Id: I8ecb0c3b4b19098e0026215444bae9b34060440e
Reviewed-on: https://review.monogon.dev/c/monogon/+/2333
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/metropolis/node/BUILD.bazel b/metropolis/node/BUILD.bazel
index 98fc1cf..f207107 100644
--- a/metropolis/node/BUILD.bazel
+++ b/metropolis/node/BUILD.bazel
@@ -13,18 +13,12 @@
         "net_ips.go",
         "net_protocols.go",
         "ports.go",
-        "version.go",
     ],
     importpath = "source.monogon.dev/metropolis/node",
     visibility = [
         "//metropolis:__subpackages__",
         "@io_k8s_kubernetes//pkg/registry:__subpackages__",
     ],
-    x_defs = {
-        "BuildCommit": "{STABLE_METROPOLIS_gitCommit}",
-        "BuildTreeState": "{STABLE_METROPOLIS_gitTreeState}",
-        "BuildVersion": "{STABLE_METROPOLIS_version}",
-    },
     deps = ["@com_github_vishvananda_netlink//:netlink"],
 )
 
diff --git a/metropolis/node/core/BUILD.bazel b/metropolis/node/core/BUILD.bazel
index 9043d8e..8605534 100644
--- a/metropolis/node/core/BUILD.bazel
+++ b/metropolis/node/core/BUILD.bazel
@@ -40,6 +40,8 @@
         "//metropolis/pkg/sysctl",
         "//metropolis/pkg/tpm",
         "//metropolis/proto/api",
+        "//metropolis/version",
+        "//version",
         "@com_github_cenkalti_backoff_v4//:backoff",
         "@com_github_containerd_containerd//:containerd",
         "@com_github_containerd_containerd//namespaces",
diff --git a/metropolis/node/core/main.go b/metropolis/node/core/main.go
index 583d72f..eb0e0e8 100644
--- a/metropolis/node/core/main.go
+++ b/metropolis/node/core/main.go
@@ -40,6 +40,8 @@
 	"source.monogon.dev/metropolis/pkg/logtree"
 	"source.monogon.dev/metropolis/pkg/supervisor"
 	"source.monogon.dev/metropolis/pkg/tpm"
+	mversion "source.monogon.dev/metropolis/version"
+	"source.monogon.dev/version"
 )
 
 func main() {
@@ -110,7 +112,7 @@
 	}
 
 	logger.Info("Starting Metropolis node init")
-	logger.Infof("Version: %s", node.Version)
+	logger.Infof("Version: %s", version.Semver(mversion.Version))
 
 	haveTPM := true
 	if err := tpm.Initialize(logger); err != nil {
diff --git a/metropolis/node/version.go b/metropolis/node/version.go
deleted file mode 100644
index 1e20369..0000000
--- a/metropolis/node/version.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2023 The Monogon Project Authors.
-//
-// SPDX-License-Identifier: Apache-2.0
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package node
-
-import (
-	"fmt"
-)
-
-var (
-	BuildCommit    = "<unknown>"
-	BuildTreeState = "<unknown>"
-	BuildVersion   = "<unknown>"
-	Version        = fmt.Sprintf("v%s - %s (%s)", BuildVersion, BuildCommit, BuildTreeState)
-)
diff --git a/metropolis/version/BUILD.bazel b/metropolis/version/BUILD.bazel
new file mode 100644
index 0000000..40a0991
--- /dev/null
+++ b/metropolis/version/BUILD.bazel
@@ -0,0 +1,19 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library")
+load("//version:defs.bzl", "go_version_library")
+
+go_version_library(
+    name = "version_lib",
+    importpath = "source.monogon.dev/metropolis/version",
+    product = "metropolis",
+)
+
+go_library(
+    name = "version",
+    embed = [
+        ":version_lib",  # keep
+    ],
+    importpath = "source.monogon.dev/metropolis/version",  # keep
+    visibility = [
+        "//metropolis:__subpackages__",
+    ],
+)
diff --git a/metropolis/version/gomod-generated-placeholder.go b/metropolis/version/gomod-generated-placeholder.go
new file mode 100644
index 0000000..f37d99d
--- /dev/null
+++ b/metropolis/version/gomod-generated-placeholder.go
@@ -0,0 +1 @@
+package version