treewide: add product info to OCI OS images

Add the product info to the OCI OS image config.

Change-Id: I70c572f2698c8d8bb0edc0ba969d8c6b37ae4c00
Reviewed-on: https://review.monogon.dev/c/monogon/+/4193
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
Tested-by: Jenkins CI
diff --git a/osbase/build/mkoci/def.bzl b/osbase/build/mkoci/def.bzl
index f7f491d..8b688a7 100644
--- a/osbase/build/mkoci/def.bzl
+++ b/osbase/build/mkoci/def.bzl
@@ -1,6 +1,10 @@
 def _oci_os_image_impl(ctx):
     inputs = []
     arguments = []
+
+    inputs.append(ctx.file.product_info)
+    arguments += ["-product_info", ctx.file.product_info.path]
+
     for name, label in ctx.attr.srcs.items():
         files = label[DefaultInfo].files.to_list()
         if len(files) != 1:
@@ -42,6 +46,13 @@
         Build an OS image OCI artifact.
     """,
     attrs = {
+        "product_info": attr.label(
+            doc = """
+                Product info of the OS in JSON format.
+            """,
+            mandatory = True,
+            allow_single_file = True,
+        ),
         "srcs": attr.string_keyed_label_dict(
             doc = """
                 Payloads to include in the OCI artifact.
diff --git a/osbase/build/mkoci/main.go b/osbase/build/mkoci/main.go
index 16dd268..1fb2254 100644
--- a/osbase/build/mkoci/main.go
+++ b/osbase/build/mkoci/main.go
@@ -28,6 +28,7 @@
 var payloadNameRegexp = regexp.MustCompile(`^[0-9A-Za-z-](?:[0-9A-Za-z._-]{0,78}[0-9A-Za-z_-])?$`)
 
 var (
+	productInfoPath  = flag.String("product_info", "", "Path to the product info JSON file")
 	payloadName      = flag.String("payload_name", "", "Payload name for the next payload_file flag")
 	compressionLevel = flag.Int("compression_level", int(zstd.SpeedDefault), "Compression level")
 	outPath          = flag.String("out", "", "Output OCI Image Layout directory path")
@@ -201,9 +202,19 @@
 	})
 	flag.Parse()
 
+	rawProductInfo, err := os.ReadFile(*productInfoPath)
+	if err != nil {
+		log.Fatalf("Failed to read product info file: %v", err)
+	}
+	var productInfo osimage.ProductInfo
+	err = json.Unmarshal(rawProductInfo, &productInfo)
+	if err != nil {
+		log.Fatal(err)
+	}
+
 	// Create blobs directory.
 	blobsPath := filepath.Join(*outPath, "blobs", "sha256")
-	err := os.MkdirAll(blobsPath, 0755)
+	err = os.MkdirAll(blobsPath, 0755)
 	if err != nil {
 		log.Fatal(err)
 	}
@@ -223,6 +234,7 @@
 	// Write the OS image config.
 	imageConfig := osimage.Config{
 		FormatVersion: osimage.ConfigVersion,
+		ProductInfo:   productInfo,
 		Payloads:      payloadInfos,
 	}
 	imageConfigBytes, err := json.MarshalIndent(imageConfig, "", "\t")