Skip to content

Commit c95f83f

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

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

520+
let backend = opts.backend.unwrap_or_default();
521+
520522
// If we're doing an in-place mutation, we shortcut most of the rest of the work here
521523
if opts.mutate_in_place {
522524
let deployid = {
523525
// Clone to pass into helper thread
524526
let target = target.clone();
525527
let root = cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
526528
tokio::task::spawn_blocking(move || {
527-
crate::deploy::switch_origin_inplace(&root, &target)
529+
crate::deploy::switch_origin_inplace(&root, &target, backend)
528530
})
529531
.await??
530532
};
@@ -543,7 +545,7 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
543545
let new_spec = {
544546
let mut new_spec = host.spec.clone();
545547
new_spec.image = Some(target.clone());
546-
new_spec.backend = opts.backend.unwrap_or_default();
548+
new_spec.backend = backend;
547549
new_spec
548550
};
549551

lib/src/deploy.rs

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

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

@@ -380,7 +383,7 @@ pub(crate) async fn stage(
380383
opts: Option<ostree::SysrootDeployTreeOpts<'_>>,
381384
) -> Result<()> {
382385
let merge_deployment = sysroot.merge_deployment(Some(stateroot));
383-
let origin = origin_from_imageref(spec.image)?;
386+
let origin = origin_from_imageref(spec.image, image.backend)?;
384387
crate::deploy::deploy(
385388
sysroot,
386389
merge_deployment.as_ref(),
@@ -482,9 +485,13 @@ fn find_newest_deployment_name(deploysdir: &Dir) -> Result<String> {
482485
}
483486

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

490497
// Now, we can't rely on being officially booted (e.g. with the `ostree=` karg)
@@ -544,7 +551,7 @@ fn test_switch_inplace() -> Result<()> {
544551
signature: None,
545552
};
546553
{
547-
let origin = origin_from_imageref(&orig_imgref)?;
554+
let origin = origin_from_imageref(&orig_imgref, Backend::OstreeContainer)?;
548555
deploydir.atomic_write(
549556
format!("{target_deployment}.origin"),
550557
origin.to_data().as_bytes(),
@@ -557,7 +564,7 @@ fn test_switch_inplace() -> Result<()> {
557564
signature: None,
558565
};
559566

560-
let replaced = switch_origin_inplace(&td, &target_imgref).unwrap();
567+
let replaced = switch_origin_inplace(&td, &target_imgref, Backend::OstreeContainer).unwrap();
561568
assert_eq!(replaced, target_deployment);
562569
Ok(())
563570
}

0 commit comments

Comments
 (0)