From c95f83f21f75386737fcb4cfea94ccb82b03ccec Mon Sep 17 00:00:00 2001 From: John Eckersberg Date: Wed, 5 Jun 2024 16:19:07 -0400 Subject: [PATCH] Handle bootc backend in origin file Signed-off-by: John Eckersberg --- lib/src/cli.rs | 6 ++++-- lib/src/deploy.rs | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index cc257af7b..7ba3c88e9 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -517,6 +517,8 @@ 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 = { @@ -524,7 +526,7 @@ async fn switch(opts: SwitchOpts) -> Result<()> { 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?? }; @@ -543,7 +545,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 }; diff --git a/lib/src/deploy.rs b/lib/src/deploy.rs index fe17162eb..1c4abad65 100644 --- a/lib/src/deploy.rs +++ b/lib/src/deploy.rs @@ -359,7 +359,7 @@ async fn deploy( } #[context("Generating origin")] -fn origin_from_imageref(imgref: &ImageReference) -> Result { +fn origin_from_imageref(imgref: &ImageReference, backend: Backend) -> Result { let origin = glib::KeyFile::new(); let imgref = OstreeImageReference::from(imgref.clone()); origin.set_string( @@ -367,6 +367,9 @@ fn origin_from_imageref(imgref: &ImageReference) -> Result { ostree_container::deploy::ORIGIN_CONTAINER, imgref.to_string().as_str(), ); + if backend == Backend::Container { + origin.set_string("bootc", "backend", "container"); + } Ok(origin) } @@ -380,7 +383,7 @@ pub(crate) async fn stage( opts: Option>, ) -> 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(), @@ -482,9 +485,13 @@ fn find_newest_deployment_name(deploysdir: &Dir) -> Result { } // Implementation of `bootc switch --in-place` -pub(crate) fn switch_origin_inplace(root: &Dir, imgref: &ImageReference) -> Result { +pub(crate) fn switch_origin_inplace( + root: &Dir, + imgref: &ImageReference, + backend: Backend, +) -> Result { // 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) @@ -544,7 +551,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(), @@ -557,7 +564,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(()) }