Skip to content

Commit b12e6b1

Browse files
committed
Handle bootc backend in origin file
Signed-off-by: John Eckersberg <[email protected]>
1 parent 331a0b5 commit b12e6b1

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
@@ -618,14 +618,16 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
618618
let target = ostree_container::OstreeImageReference { sigverify, imgref };
619619
let target = ImageReference::from(target);
620620

621+
let backend = opts.backend.unwrap_or_default();
622+
621623
// If we're doing an in-place mutation, we shortcut most of the rest of the work here
622624
if opts.mutate_in_place {
623625
let deployid = {
624626
// Clone to pass into helper thread
625627
let target = target.clone();
626628
let root = cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
627629
tokio::task::spawn_blocking(move || {
628-
crate::deploy::switch_origin_inplace(&root, &target)
630+
crate::deploy::switch_origin_inplace(&root, &target, backend)
629631
})
630632
.await??
631633
};
@@ -643,7 +645,7 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
643645
let new_spec = {
644646
let mut new_spec = host.spec.clone();
645647
new_spec.image = Some(target.clone());
646-
new_spec.backend = opts.backend.unwrap_or_default();
648+
new_spec.backend = backend;
647649
new_spec
648650
};
649651

lib/src/deploy.rs

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

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

@@ -379,7 +382,7 @@ pub(crate) async fn stage(
379382
opts: Option<ostree::SysrootDeployTreeOpts<'_>>,
380383
) -> Result<()> {
381384
let merge_deployment = sysroot.merge_deployment(Some(stateroot));
382-
let origin = origin_from_imageref(spec.image)?;
385+
let origin = origin_from_imageref(spec.image, image.backend)?;
383386
crate::deploy::deploy(
384387
sysroot,
385388
merge_deployment.as_ref(),
@@ -479,9 +482,13 @@ fn find_newest_deployment_name(deploysdir: &Dir) -> Result<String> {
479482
}
480483

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

487494
// Now, we can't rely on being officially booted (e.g. with the `ostree=` karg)
@@ -541,7 +548,7 @@ fn test_switch_inplace() -> Result<()> {
541548
signature: None,
542549
};
543550
{
544-
let origin = origin_from_imageref(&orig_imgref)?;
551+
let origin = origin_from_imageref(&orig_imgref, Backend::OstreeContainer)?;
545552
deploydir.atomic_write(
546553
format!("{target_deployment}.origin"),
547554
origin.to_data().as_bytes(),
@@ -554,7 +561,7 @@ fn test_switch_inplace() -> Result<()> {
554561
signature: None,
555562
};
556563

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

0 commit comments

Comments
 (0)