From cf615b8f5082008acbacc4daa06a5899d505526f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 27 Oct 2023 08:00:27 -0400 Subject: [PATCH] install: Add more image metadata to aleph Motivated by https://issues.redhat.com/browse/COS-2526 It's quite possible that the image sha will have been GCd, but the version number and timestamp inside the image (not just the file timestamp) are probably sufficient for general reference. Signed-off-by: Colin Walters --- lib/src/install.rs | 19 ++++++++++++++++++- lib/src/status.rs | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/src/install.rs b/lib/src/install.rs index fe100a35c..d210f526c 100644 --- a/lib/src/install.rs +++ b/lib/src/install.rs @@ -21,7 +21,9 @@ use camino::Utf8PathBuf; use cap_std::fs::Dir; use cap_std_ext::cap_std; use cap_std_ext::prelude::CapStdExtDirExt; +use chrono::prelude::*; use clap::ValueEnum; +use ostree_ext::oci_spec; use rustix::fs::MetadataExt; use fn_error_context::context; @@ -228,6 +230,11 @@ const BOOTC_ALEPH_PATH: &str = ".bootc-aleph.json"; struct InstallAleph { /// Digested pull spec for installed image image: String, + /// The version number + version: Option, + /// The timestamp + timestamp: Option>, + /// The `uname -r` of the kernel doing the installation kernel: String, } @@ -533,7 +540,7 @@ async fn initialize_ostree_root_from_self( let state = ostree_container::deploy::deploy(&sysroot, stateroot, &src_imageref, Some(options)).await?; let target_image = target_imgref.to_string(); - let digest = state.manifest_digest; + let digest = state.manifest_digest.as_str(); println!("Installed: {target_image}"); println!(" Digest: {digest}"); @@ -565,8 +572,18 @@ async fn initialize_ostree_root_from_self( let uname = rustix::system::uname(); + let config = state.configuration.as_ref(); + let labels = config.and_then(crate::status::labels_of_config); + let timestamp = labels + .and_then(|l| { + l.get(oci_spec::image::ANNOTATION_CREATED) + .map(|s| s.as_str()) + }) + .and_then(crate::status::try_deserialize_timestamp); let aleph = InstallAleph { image: src_imageref.imgref.name.clone(), + version: state.version().as_ref().map(|s| s.to_string()), + timestamp, kernel: uname.release().to_str()?.to_string(), }; diff --git a/lib/src/status.rs b/lib/src/status.rs index 0296daab1..a6fcf869f 100644 --- a/lib/src/status.rs +++ b/lib/src/status.rs @@ -88,7 +88,7 @@ pub(crate) struct Deployments { pub(crate) other: VecDeque, } -fn try_deserialize_timestamp(t: &str) -> Option> { +pub(crate) fn try_deserialize_timestamp(t: &str) -> Option> { match chrono::DateTime::parse_from_rfc3339(t).context("Parsing timestamp") { Ok(t) => Some(t.into()), Err(e) => {