diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 253074521..39d633e30 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -618,6 +618,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 = { @@ -625,7 +627,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?? }; @@ -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 }; diff --git a/lib/src/deploy.rs b/lib/src/deploy.rs index f97f5b516..8aa271542 100644 --- a/lib/src/deploy.rs +++ b/lib/src/deploy.rs @@ -358,7 +358,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( @@ -366,6 +366,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) } @@ -379,7 +382,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(), @@ -479,9 +482,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) @@ -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(), @@ -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(()) }