Skip to content

Commit f345357

Browse files
authored
Merge pull request #1504 from cgwalters/install-cleanup-aleph
install: Move Aleph bits to a separate module
2 parents 05030a3 + c14aec8 commit f345357

File tree

2 files changed

+66
-55
lines changed

2 files changed

+66
-55
lines changed

crates/lib/src/install.rs

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
// This sub-module is the "basic" installer that handles creating basic block device
88
// and filesystem setup.
9+
mod aleph;
910
#[cfg(feature = "install-to-disk")]
1011
pub(crate) mod baseline;
1112
pub(crate) mod completion;
@@ -23,6 +24,7 @@ use std::str::FromStr;
2324
use std::sync::Arc;
2425
use std::time::Duration;
2526

27+
use aleph::InstallAleph;
2628
use anyhow::{anyhow, ensure, Context, Result};
2729
use bootc_utils::CommandRunExt;
2830
use camino::Utf8Path;
@@ -35,11 +37,9 @@ use cap_std_ext::cap_std::fs_utf8::DirEntry as DirEntryUtf8;
3537
use cap_std_ext::cap_tempfile::TempDir;
3638
use cap_std_ext::cmdext::CapStdExtCommandExt;
3739
use cap_std_ext::prelude::CapStdExtDirExt;
38-
use chrono::prelude::*;
3940
use clap::ValueEnum;
4041
use fn_error_context::context;
4142
use ostree::gio;
42-
use ostree_ext::oci_spec;
4343
use ostree_ext::ostree;
4444
use ostree_ext::ostree_prepareroot::{ComposefsState, Tristate};
4545
use ostree_ext::prelude::Cast;
@@ -417,27 +417,6 @@ impl State {
417417
}
418418
}
419419

420-
/// Path to initially deployed version information
421-
const BOOTC_ALEPH_PATH: &str = ".bootc-aleph.json";
422-
423-
/// The "aleph" version information is injected into /root/.bootc-aleph.json
424-
/// and contains the image ID that was initially used to install. This can
425-
/// be used to trace things like the specific version of `mkfs.ext4` or
426-
/// kernel version that was used.
427-
#[derive(Debug, Serialize)]
428-
struct InstallAleph {
429-
/// Digested pull spec for installed image
430-
image: String,
431-
/// The version number
432-
version: Option<String>,
433-
/// The timestamp
434-
timestamp: Option<chrono::DateTime<Utc>>,
435-
/// The `uname -r` of the kernel doing the installation
436-
kernel: String,
437-
/// The state of SELinux at install time
438-
selinux: String,
439-
}
440-
441420
/// A mount specification is a subset of a line in `/etc/fstab`.
442421
///
443422
/// There are 3 (ASCII) whitespace separated values:
@@ -529,32 +508,6 @@ impl FromStr for MountSpec {
529508
}
530509
}
531510

532-
impl InstallAleph {
533-
#[context("Creating aleph data")]
534-
pub(crate) fn new(
535-
src_imageref: &ostree_container::OstreeImageReference,
536-
imgstate: &ostree_container::store::LayeredImageState,
537-
selinux_state: &SELinuxFinalState,
538-
) -> Result<Self> {
539-
let uname = rustix::system::uname();
540-
let labels = crate::status::labels_of_config(&imgstate.configuration);
541-
let timestamp = labels
542-
.and_then(|l| {
543-
l.get(oci_spec::image::ANNOTATION_CREATED)
544-
.map(|s| s.as_str())
545-
})
546-
.and_then(bootc_utils::try_deserialize_timestamp);
547-
let r = InstallAleph {
548-
image: src_imageref.imgref.name.clone(),
549-
version: imgstate.version().as_ref().map(|s| s.to_string()),
550-
timestamp,
551-
kernel: uname.release().to_str()?.to_string(),
552-
selinux: selinux_state.to_aleph().to_string(),
553-
};
554-
Ok(r)
555-
}
556-
}
557-
558511
impl SourceInfo {
559512
// Inspect container information and convert it to an ostree image reference
560513
// that pulls from containers-storage.
@@ -1346,12 +1299,7 @@ async fn install_with_sysroot(
13461299
// the aleph state (see below).
13471300
let (deployment, aleph) = install_container(state, rootfs, &sysroot, has_ostree).await?;
13481301
// Write the aleph data that captures the system state at the time of provisioning for aid in future debugging.
1349-
rootfs
1350-
.physical_root
1351-
.atomic_replace_with(BOOTC_ALEPH_PATH, |f| {
1352-
anyhow::Ok(aleph.to_canon_json_writer(f)?)
1353-
})
1354-
.context("Writing aleph version")?;
1302+
aleph.write_to(&rootfs.physical_root)?;
13551303

13561304
let deployment_path = sysroot.deployment_dirpath(&deployment);
13571305

crates/lib/src/install/aleph.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use anyhow::{Context as _, Result};
2+
use canon_json::CanonJsonSerialize as _;
3+
use cap_std_ext::{cap_std::fs::Dir, dirext::CapStdExtDirExt as _};
4+
use fn_error_context::context;
5+
use ostree_ext::{container as ostree_container, oci_spec};
6+
use serde::Serialize;
7+
8+
use super::SELinuxFinalState;
9+
10+
/// Path to initially deployed version information
11+
pub(crate) const BOOTC_ALEPH_PATH: &str = ".bootc-aleph.json";
12+
13+
/// The "aleph" version information is injected into /root/.bootc-aleph.json
14+
/// and contains the image ID that was initially used to install. This can
15+
/// be used to trace things like the specific version of `mkfs.ext4` or
16+
/// kernel version that was used.
17+
#[derive(Debug, Serialize)]
18+
pub(crate) struct InstallAleph {
19+
/// Digested pull spec for installed image
20+
pub(crate) image: String,
21+
/// The version number
22+
pub(crate) version: Option<String>,
23+
/// The timestamp
24+
pub(crate) timestamp: Option<chrono::DateTime<chrono::Utc>>,
25+
/// The `uname -r` of the kernel doing the installation
26+
pub(crate) kernel: String,
27+
/// The state of SELinux at install time
28+
pub(crate) selinux: String,
29+
}
30+
31+
impl InstallAleph {
32+
#[context("Creating aleph data")]
33+
pub(crate) fn new(
34+
src_imageref: &ostree_container::OstreeImageReference,
35+
imgstate: &ostree_container::store::LayeredImageState,
36+
selinux_state: &SELinuxFinalState,
37+
) -> Result<Self> {
38+
let uname = rustix::system::uname();
39+
let labels = crate::status::labels_of_config(&imgstate.configuration);
40+
let timestamp = labels
41+
.and_then(|l| {
42+
l.get(oci_spec::image::ANNOTATION_CREATED)
43+
.map(|s| s.as_str())
44+
})
45+
.and_then(bootc_utils::try_deserialize_timestamp);
46+
let r = InstallAleph {
47+
image: src_imageref.imgref.name.clone(),
48+
version: imgstate.version().as_ref().map(|s| s.to_string()),
49+
timestamp,
50+
kernel: uname.release().to_str()?.to_string(),
51+
selinux: selinux_state.to_aleph().to_string(),
52+
};
53+
Ok(r)
54+
}
55+
56+
/// Serialize to a file in the target root.
57+
pub(crate) fn write_to(&self, root: &Dir) -> Result<()> {
58+
root.atomic_replace_with(BOOTC_ALEPH_PATH, |f| {
59+
anyhow::Ok(self.to_canon_json_writer(f)?)
60+
})
61+
.context("Writing aleph version")
62+
}
63+
}

0 commit comments

Comments
 (0)