Skip to content

Commit cf615b8

Browse files
committed
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 <[email protected]>
1 parent 89136de commit cf615b8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/src/install.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ use camino::Utf8PathBuf;
2121
use cap_std::fs::Dir;
2222
use cap_std_ext::cap_std;
2323
use cap_std_ext::prelude::CapStdExtDirExt;
24+
use chrono::prelude::*;
2425
use clap::ValueEnum;
26+
use ostree_ext::oci_spec;
2527
use rustix::fs::MetadataExt;
2628

2729
use fn_error_context::context;
@@ -228,6 +230,11 @@ const BOOTC_ALEPH_PATH: &str = ".bootc-aleph.json";
228230
struct InstallAleph {
229231
/// Digested pull spec for installed image
230232
image: String,
233+
/// The version number
234+
version: Option<String>,
235+
/// The timestamp
236+
timestamp: Option<chrono::DateTime<Utc>>,
237+
/// The `uname -r` of the kernel doing the installation
231238
kernel: String,
232239
}
233240

@@ -533,7 +540,7 @@ async fn initialize_ostree_root_from_self(
533540
let state =
534541
ostree_container::deploy::deploy(&sysroot, stateroot, &src_imageref, Some(options)).await?;
535542
let target_image = target_imgref.to_string();
536-
let digest = state.manifest_digest;
543+
let digest = state.manifest_digest.as_str();
537544
println!("Installed: {target_image}");
538545
println!(" Digest: {digest}");
539546

@@ -565,8 +572,18 @@ async fn initialize_ostree_root_from_self(
565572

566573
let uname = rustix::system::uname();
567574

575+
let config = state.configuration.as_ref();
576+
let labels = config.and_then(crate::status::labels_of_config);
577+
let timestamp = labels
578+
.and_then(|l| {
579+
l.get(oci_spec::image::ANNOTATION_CREATED)
580+
.map(|s| s.as_str())
581+
})
582+
.and_then(crate::status::try_deserialize_timestamp);
568583
let aleph = InstallAleph {
569584
image: src_imageref.imgref.name.clone(),
585+
version: state.version().as_ref().map(|s| s.to_string()),
586+
timestamp,
570587
kernel: uname.release().to_str()?.to_string(),
571588
};
572589

lib/src/status.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub(crate) struct Deployments {
8888
pub(crate) other: VecDeque<ostree::Deployment>,
8989
}
9090

91-
fn try_deserialize_timestamp(t: &str) -> Option<chrono::DateTime<chrono::Utc>> {
91+
pub(crate) fn try_deserialize_timestamp(t: &str) -> Option<chrono::DateTime<chrono::Utc>> {
9292
match chrono::DateTime::parse_from_rfc3339(t).context("Parsing timestamp") {
9393
Ok(t) => Some(t.into()),
9494
Err(e) => {

0 commit comments

Comments
 (0)