Skip to content

Commit 4bdd3c7

Browse files
committed
install: Make stateroot configurable
This commit makes it so that the `bootc install` stateroot will be configurable (it defaults to `default`). For now this is a hidden CLI option until we decide whether we want to commit to this API. In the future we also want to make the stateroot of `bootc switch` be configurable (bootc-dev#617) so that users can install an image to a new stateroot while they already have an existing stateroot Also removed the constant `STATEROOT_DEFAULT`, we're now simply taking it from the `ostree_ext` crate
1 parent a2c47e5 commit 4bdd3c7

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

lib/src/install.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ use crate::store::Storage;
5151
use crate::task::Task;
5252
use crate::utils::sigpolicy_from_opts;
5353

54-
/// The default "stateroot" or "osname"; see https://github.com/ostreedev/ostree/issues/2794
55-
const STATEROOT_DEFAULT: &str = "default";
5654
/// The toplevel boot directory
5755
const BOOT: &str = "boot";
5856
/// Directory for transient runtime state
@@ -171,6 +169,10 @@ pub(crate) struct InstallConfigOpts {
171169
#[clap(long, hide = true)]
172170
#[serde(default)]
173171
pub(crate) skip_bound_images: bool,
172+
173+
/// The stateroot name to use. Defaults to `default`.
174+
#[clap(long)]
175+
pub(crate) stateroot: Option<String>,
174176
}
175177

176178
#[derive(Debug, Clone, clap::Parser, Serialize, Deserialize, PartialEq, Eq)]
@@ -567,8 +569,12 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result
567569
// Another implementation: https://github.com/coreos/coreos-assembler/blob/3cd3307904593b3a131b81567b13a4d0b6fe7c90/src/create_disk.sh#L295
568570
crate::lsm::ensure_dir_labeled(rootfs_dir, "", Some("/".into()), 0o755.into(), sepolicy)?;
569571

570-
// TODO: make configurable?
571-
let stateroot = STATEROOT_DEFAULT;
572+
let stateroot = state
573+
.config_opts
574+
.stateroot
575+
.as_deref()
576+
.unwrap_or(ostree_ext::container::deploy::STATEROOT_DEFAULT);
577+
572578
Task::new_and_run(
573579
"Initializing ostree layout",
574580
"ostree",
@@ -638,7 +644,11 @@ async fn install_container(
638644
) -> Result<(ostree::Deployment, InstallAleph)> {
639645
let sepolicy = state.load_policy()?;
640646
let sepolicy = sepolicy.as_ref();
641-
let stateroot = STATEROOT_DEFAULT;
647+
let stateroot = state
648+
.config_opts
649+
.stateroot
650+
.as_deref()
651+
.unwrap_or(ostree_ext::container::deploy::STATEROOT_DEFAULT);
642652

643653
let container_rootfs = &Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
644654

@@ -1099,7 +1109,9 @@ pub(crate) fn setup_sys_mount(fstype: &str, fspath: &str) -> Result<()> {
10991109
Task::new(format!("Mounting {fstype} {fspath}"), "mount")
11001110
.args(["-t", fstype, fstype, fspath])
11011111
.quiet()
1102-
.run()
1112+
.run()?;
1113+
1114+
Ok(())
11031115
}
11041116

11051117
/// Verify that we can load the manifest of the target image

tests-integration/src/install.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,32 @@ pub(crate) const BASE_ARGS: &[&str] = &[
2323
"label=disable",
2424
];
2525

26+
// ostree_ext::container::deploy::STATEROOT_DEFAULT
27+
const DEFAULT_STATEROOT: &str = "default";
28+
29+
// arbitary
30+
const NON_DEFAULT_STATEROOT: &str = "foo";
31+
2632
// Clear out and delete any ostree roots
2733
fn reset_root(sh: &Shell) -> Result<()> {
2834
// TODO fix https://github.com/containers/bootc/pull/137
29-
if !Path::new("/ostree/deploy/default").exists() {
30-
return Ok(());
35+
36+
for stateroot in [DEFAULT_STATEROOT, NON_DEFAULT_STATEROOT] {
37+
if !Path::new(&format!("/ostree/deploy/{stateroot}")).exists() {
38+
continue;
39+
}
40+
41+
if Path::new(&format!("/ostree/deploy/{stateroot}/deploy")).exists() {
42+
cmd!(
43+
sh,
44+
// env var hack needed because cmd! doesn't interpolate inside single quotes
45+
"sudo STATEROOT={stateroot} /bin/sh -c 'chattr -i /ostree/deploy/$STATEROOT/deploy/*'"
46+
)
47+
.run()?;
48+
}
49+
50+
cmd!(sh, "sudo rm /ostree/deploy/{stateroot} -rf").run()?;
3151
}
32-
cmd!(
33-
sh,
34-
"sudo /bin/sh -c 'chattr -i /ostree/deploy/default/deploy/*'"
35-
)
36-
.run()?;
37-
cmd!(sh, "sudo rm /ostree/deploy/default -rf").run()?;
3852
Ok(())
3953
}
4054

@@ -136,6 +150,14 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
136150
crate::selinux::verify_selinux_recurse(root, &mut path, false)?;
137151
Ok(())
138152
}),
153+
Trial::test("Install to non-default stateroot", move || {
154+
let sh = &xshell::Shell::new()?;
155+
reset_root(sh)?;
156+
cmd!(sh, "sudo {BASE_ARGS...} {target_args...} {image} bootc install to-existing-root --stateroot {NON_DEFAULT_STATEROOT} --acknowledge-destructive {generic_inst_args...}").run()?;
157+
generic_post_install_verification()?;
158+
assert!(Utf8Path::new(&format!("/ostree/deploy/{NON_DEFAULT_STATEROOT}")).try_exists()?);
159+
Ok(())
160+
}),
139161
Trial::test("without an install config", move || {
140162
let sh = &xshell::Shell::new()?;
141163
reset_root(sh)?;

0 commit comments

Comments
 (0)