Skip to content

Commit 2a0dbe1

Browse files
committed
Handle bootc backend in origin file
Signed-off-by: John Eckersberg <[email protected]>
1 parent 37b35d5 commit 2a0dbe1

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

lib/src/cli.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,16 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
504504
let target = ostree_container::OstreeImageReference { sigverify, imgref };
505505
let target = ImageReference::from(target);
506506

507+
let backend = opts.backend.unwrap_or_default();
508+
507509
// If we're doing an in-place mutation, we shortcut most of the rest of the work here
508510
if opts.mutate_in_place {
509511
let deployid = {
510512
// Clone to pass into helper thread
511513
let target = target.clone();
512514
let root = cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
513515
tokio::task::spawn_blocking(move || {
514-
crate::deploy::switch_origin_inplace(&root, &target)
516+
crate::deploy::switch_origin_inplace(&root, &target, backend)
515517
})
516518
.await??
517519
};
@@ -530,7 +532,7 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
530532
let new_spec = {
531533
let mut new_spec = host.spec.clone();
532534
new_spec.image = Some(target.clone());
533-
new_spec.backend = opts.backend.unwrap_or_default();
535+
new_spec.backend = backend;
534536
new_spec
535537
};
536538

lib/src/deploy.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,17 @@ async fn deploy(
357357
}
358358

359359
#[context("Generating origin")]
360-
fn origin_from_imageref(imgref: &ImageReference) -> Result<glib::KeyFile> {
360+
fn origin_from_imageref(imgref: &ImageReference, backend: Backend) -> Result<glib::KeyFile> {
361361
let origin = glib::KeyFile::new();
362362
let imgref = OstreeImageReference::from(imgref.clone());
363363
origin.set_string(
364364
"origin",
365365
ostree_container::deploy::ORIGIN_CONTAINER,
366366
imgref.to_string().as_str(),
367367
);
368+
if backend == Backend::Container {
369+
origin.set_string("bootc", "backend", "container");
370+
}
368371
Ok(origin)
369372
}
370373

@@ -377,7 +380,7 @@ pub(crate) async fn stage(
377380
spec: &RequiredHostSpec<'_>,
378381
) -> Result<()> {
379382
let merge_deployment = sysroot.merge_deployment(Some(stateroot));
380-
let origin = origin_from_imageref(spec.image)?;
383+
let origin = origin_from_imageref(spec.image, image.backend)?;
381384
crate::deploy::deploy(
382385
sysroot,
383386
merge_deployment.as_ref(),
@@ -478,9 +481,13 @@ fn find_newest_deployment_name(deploysdir: &Dir) -> Result<String> {
478481
}
479482

480483
// Implementation of `bootc switch --in-place`
481-
pub(crate) fn switch_origin_inplace(root: &Dir, imgref: &ImageReference) -> Result<String> {
484+
pub(crate) fn switch_origin_inplace(
485+
root: &Dir,
486+
imgref: &ImageReference,
487+
backend: Backend,
488+
) -> Result<String> {
482489
// First, just create the new origin file
483-
let origin = origin_from_imageref(imgref)?;
490+
let origin = origin_from_imageref(imgref, backend)?;
484491
let serialized_origin = origin.to_data();
485492

486493
// Now, we can't rely on being officially booted (e.g. with the `ostree=` karg)
@@ -540,7 +547,7 @@ fn test_switch_inplace() -> Result<()> {
540547
signature: None,
541548
};
542549
{
543-
let origin = origin_from_imageref(&orig_imgref)?;
550+
let origin = origin_from_imageref(&orig_imgref, Backend::OstreeContainer)?;
544551
deploydir.atomic_write(
545552
format!("{target_deployment}.origin"),
546553
origin.to_data().as_bytes(),
@@ -553,7 +560,7 @@ fn test_switch_inplace() -> Result<()> {
553560
signature: None,
554561
};
555562

556-
let replaced = switch_origin_inplace(&td, &target_imgref).unwrap();
563+
let replaced = switch_origin_inplace(&td, &target_imgref, Backend::OstreeContainer).unwrap();
557564
assert_eq!(replaced, target_deployment);
558565
Ok(())
559566
}

0 commit comments

Comments
 (0)