Skip to content

Commit

Permalink
Handle bootc backend in origin file
Browse files Browse the repository at this point in the history
Signed-off-by: John Eckersberg <[email protected]>
  • Loading branch information
jeckersb committed Jul 2, 2024
1 parent 331a0b5 commit b12e6b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,16 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
let target = ostree_container::OstreeImageReference { sigverify, imgref };
let target = ImageReference::from(target);

let backend = opts.backend.unwrap_or_default();

// If we're doing an in-place mutation, we shortcut most of the rest of the work here
if opts.mutate_in_place {
let deployid = {
// Clone to pass into helper thread
let target = target.clone();
let root = cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
tokio::task::spawn_blocking(move || {
crate::deploy::switch_origin_inplace(&root, &target)
crate::deploy::switch_origin_inplace(&root, &target, backend)
})
.await??
};
Expand All @@ -643,7 +645,7 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
let new_spec = {
let mut new_spec = host.spec.clone();
new_spec.image = Some(target.clone());
new_spec.backend = opts.backend.unwrap_or_default();
new_spec.backend = backend;
new_spec
};

Expand Down
19 changes: 13 additions & 6 deletions lib/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,17 @@ async fn deploy(
}

#[context("Generating origin")]
fn origin_from_imageref(imgref: &ImageReference) -> Result<glib::KeyFile> {
fn origin_from_imageref(imgref: &ImageReference, backend: Backend) -> Result<glib::KeyFile> {
let origin = glib::KeyFile::new();
let imgref = OstreeImageReference::from(imgref.clone());
origin.set_string(
"origin",
ostree_container::deploy::ORIGIN_CONTAINER,
imgref.to_string().as_str(),
);
if backend == Backend::Container {
origin.set_string("bootc", "backend", "container");
}
Ok(origin)
}

Expand All @@ -379,7 +382,7 @@ pub(crate) async fn stage(
opts: Option<ostree::SysrootDeployTreeOpts<'_>>,
) -> Result<()> {
let merge_deployment = sysroot.merge_deployment(Some(stateroot));
let origin = origin_from_imageref(spec.image)?;
let origin = origin_from_imageref(spec.image, image.backend)?;
crate::deploy::deploy(
sysroot,
merge_deployment.as_ref(),
Expand Down Expand Up @@ -479,9 +482,13 @@ fn find_newest_deployment_name(deploysdir: &Dir) -> Result<String> {
}

// Implementation of `bootc switch --in-place`
pub(crate) fn switch_origin_inplace(root: &Dir, imgref: &ImageReference) -> Result<String> {
pub(crate) fn switch_origin_inplace(
root: &Dir,
imgref: &ImageReference,
backend: Backend,
) -> Result<String> {
// First, just create the new origin file
let origin = origin_from_imageref(imgref)?;
let origin = origin_from_imageref(imgref, backend)?;
let serialized_origin = origin.to_data();

// Now, we can't rely on being officially booted (e.g. with the `ostree=` karg)
Expand Down Expand Up @@ -541,7 +548,7 @@ fn test_switch_inplace() -> Result<()> {
signature: None,
};
{
let origin = origin_from_imageref(&orig_imgref)?;
let origin = origin_from_imageref(&orig_imgref, Backend::OstreeContainer)?;
deploydir.atomic_write(
format!("{target_deployment}.origin"),
origin.to_data().as_bytes(),
Expand All @@ -554,7 +561,7 @@ fn test_switch_inplace() -> Result<()> {
signature: None,
};

let replaced = switch_origin_inplace(&td, &target_imgref).unwrap();
let replaced = switch_origin_inplace(&td, &target_imgref, Backend::OstreeContainer).unwrap();
assert_eq!(replaced, target_deployment);
Ok(())
}
Expand Down

0 comments on commit b12e6b1

Please sign in to comment.