From 2a0dbe1bd309eceda7b68d448ea70cb79ce407de 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 e8a640cd2..1e997e609 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -504,6 +504,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 = { @@ -511,7 +513,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?? }; @@ -530,7 +532,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 a7a96c560..d732cabc5 100644 --- a/lib/src/deploy.rs +++ b/lib/src/deploy.rs @@ -357,7 +357,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( @@ -365,6 +365,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) } @@ -377,7 +380,7 @@ pub(crate) async fn stage( spec: &RequiredHostSpec<'_>, ) -> 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(), @@ -478,9 +481,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) @@ -540,7 +547,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(), @@ -553,7 +560,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(()) }