Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install: Factor out helper to create aleph version #917

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,32 @@ impl FromStr for MountSpec {
}
}

impl InstallAleph {
#[context("Creating aleph data")]
pub(crate) fn new(
src_imageref: &ostree_container::OstreeImageReference,
imgstate: &ostree_container::store::LayeredImageState,
selinux_state: &SELinuxFinalState,
) -> Result<Self> {
let uname = rustix::system::uname();
let labels = crate::status::labels_of_config(&imgstate.configuration);
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 r = InstallAleph {
image: src_imageref.imgref.name.clone(),
version: imgstate.version().as_ref().map(|s| s.to_string()),
timestamp,
kernel: uname.release().to_str()?.to_string(),
selinux: selinux_state.to_aleph().to_string(),
};
Ok(r)
}
}

impl SourceInfo {
// Inspect container information and convert it to an ostree image reference
// that pulls from containers-storage.
Expand Down Expand Up @@ -842,23 +868,7 @@ async fn install_container(
osconfig::inject_root_ssh_authorized_keys(&root, sepolicy, contents)?;
}

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

let labels = crate::status::labels_of_config(&imgstate.configuration);
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: imgstate.version().as_ref().map(|s| s.to_string()),
timestamp,
kernel: uname.release().to_str()?.to_string(),
selinux: state.selinux_state.to_aleph().to_string(),
};

let aleph = InstallAleph::new(&src_imageref, &imgstate, &state.selinux_state)?;
Ok((deployment, aleph))
}

Expand Down