Skip to content

Commit aaf0d7e

Browse files
committed
install: Work around bootc-image-builder using /run/osbuild/containers
xref: osbuild/bootc-image-builder#560 Basically osbuild/bib puts the host `/var/lib/containers` at `/run/osbuild/containers`. If we detect this situation, bind mount it to `/var/lib/containers` so that the container stack we invoke at install time can find logically bound images. Closes: #715 Signed-off-by: Colin Walters <[email protected]>
1 parent 1dc7dc8 commit aaf0d7e

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

lib/src/install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// This sub-module is the "basic" installer that handles creating basic block device
88
// and filesystem setup.
99
pub(crate) mod baseline;
10-
mod osbuild;
1110
pub(crate) mod config;
11+
mod osbuild;
1212
pub(crate) mod osconfig;
1313

1414
use std::io::Write;
@@ -1185,7 +1185,7 @@ async fn prepare_install(
11851185
// creating multiple.
11861186
let tempdir = cap_std_ext::cap_tempfile::TempDir::new(cap_std::ambient_authority())?;
11871187
// And continue to init global state
1188-
osbuild::adjust_for_bootc_image_builder(&tempdir)?;
1188+
osbuild::adjust_for_bootc_image_builder(&rootfs, &tempdir)?;
11891189

11901190
if !target_opts.skip_fetch_check {
11911191
verify_target_fetch(&tempdir, &target_imgref).await?;

lib/src/install/osbuild.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,33 @@ fn adjust_etc_containers(tempdir: &Dir) -> Result<()> {
4141
Ok(())
4242
}
4343

44+
/// osbuild mounts the host's /var/lib/containers at /run/osbuild/containers; mount
45+
/// it back to /var/lib/containers where the default container stack expects to find it.
46+
fn propagate_run_osbuild_containers(root: &Dir) -> Result<()> {
47+
let osbuild_run_containers = Utf8Path::new("run/osbuild/containers");
48+
// If we're not apparently running under osbuild, then we no-op.
49+
if !root.try_exists(osbuild_run_containers)? {
50+
return Ok(());
51+
}
52+
// If we do seem to have a valid container store though, use that
53+
if crate::podman::storage_exists_default(root)? {
54+
return Ok(());
55+
}
56+
let relative_storage = Utf8Path::new(crate::podman::CONTAINER_STORAGE.trim_start_matches('/'));
57+
root.create_dir_all(relative_storage)?;
58+
Task::new("Creating bind mount for run/osbuild/containers", "mount")
59+
.arg("--rbind")
60+
.args([osbuild_run_containers, relative_storage])
61+
.cwd(root)?
62+
.run()?;
63+
Ok(())
64+
}
65+
4466
/// bootc-image-builder today does a few things that we need to
4567
/// deal with.
4668
#[context("bootc-image-builder adjustments")]
47-
pub(crate) fn adjust_for_bootc_image_builder(tempdir: &Dir) -> Result<()> {
69+
pub(crate) fn adjust_for_bootc_image_builder(root: &Dir, tempdir: &Dir) -> Result<()> {
4870
adjust_etc_containers(tempdir)?;
71+
propagate_run_osbuild_containers(root)?;
4972
Ok(())
5073
}

lib/src/podman.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use anyhow::{anyhow, Result};
2+
use camino::Utf8Path;
3+
use cap_std_ext::cap_std::fs::Dir;
24
use serde::Deserialize;
35

46
use crate::install::run_in_host_mountns;
@@ -27,3 +29,21 @@ pub(crate) fn imageid_to_digest(imgid: &str) -> Result<String> {
2729
.ok_or_else(|| anyhow!("No images returned for inspect"))?;
2830
Ok(i.digest)
2931
}
32+
33+
/// Return true if there is apparently an active container store at the target path.
34+
pub(crate) fn storage_exists(root: &Dir, path: impl AsRef<Utf8Path>) -> Result<bool> {
35+
fn impl_storage_exists(root: &Dir, path: &Utf8Path) -> Result<bool> {
36+
let lock = "storage.lock";
37+
root.try_exists(path.join(lock)).map_err(Into::into)
38+
}
39+
impl_storage_exists(root, path.as_ref())
40+
}
41+
42+
/// Return true if there is apparently an active container store in the default path
43+
/// for the target root.
44+
///
45+
/// Note this does not attempt to parse the root filesystem's container storage configuration,
46+
/// this uses a hardcoded default path.
47+
pub(crate) fn storage_exists_default(root: &Dir) -> Result<bool> {
48+
storage_exists(root, CONTAINER_STORAGE.trim_start_matches('/'))
49+
}

0 commit comments

Comments
 (0)