metropolis/node: show build commit on startup

Previously it was not possible to identify the running version,
with this change the build commit and tree state gets stamped into the binary
and printed on boot.

Change-Id: I3916e3d40dc87f28a58eb74c6450218550fb3214
Reviewed-on: https://review.monogon.dev/c/monogon/+/1978
Tested-by: Jenkins CI
Reviewed-by: Serge Bazanski <serge@monogon.tech>
diff --git a/metropolis/node/BUILD.bazel b/metropolis/node/BUILD.bazel
index 578664b..a62d8aa 100644
--- a/metropolis/node/BUILD.bazel
+++ b/metropolis/node/BUILD.bazel
@@ -12,12 +12,18 @@
         "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/main.go b/metropolis/node/core/main.go
index a3b7f0a..cd9bec0 100644
--- a/metropolis/node/core/main.go
+++ b/metropolis/node/core/main.go
@@ -110,6 +110,7 @@
 	}
 
 	logger.Info("Starting Metropolis node init")
+	logger.Infof("Version: %s", node.Version)
 
 	haveTPM := true
 	if err := tpm.Initialize(logger); err != nil {
diff --git a/metropolis/node/version.go b/metropolis/node/version.go
new file mode 100644
index 0000000..1e20369
--- /dev/null
+++ b/metropolis/node/version.go
@@ -0,0 +1,28 @@
+// 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)
+)