From fb5ba02d6e5d28f3501e829bdeb04385f1e5db9b Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 18 Jan 2024 17:50:47 -0500 Subject: [PATCH] install: Add `print-configuration` Even when an external process is creating the disk, we want it to be able to honor the root filesystem type specified in the container. Signed-off-by: Colin Walters --- .github/workflows/ci.yml | 2 +- lib/src/cli.rs | 8 ++++++++ lib/src/install.rs | 15 ++++++++++++++- lib/src/privtests.rs | 11 ++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84b48634..4e2ebc0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,7 +106,7 @@ jobs: name: "Container testing" needs: build-fedora runs-on: ubuntu-latest - container: quay.io/fedora/fedora-coreos:testing-devel + container: quay.io/centos-bootc/fedora-bootc:eln steps: - name: Download uses: actions/download-artifact@v3 diff --git a/lib/src/cli.rs b/lib/src/cli.rs index bbdf9145..43269b61 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -118,6 +118,13 @@ pub(crate) enum InstallOpts { ToDisk(crate::install::InstallToDiskOpts), /// Install to the target filesystem ToFilesystem(crate::install::InstallToFilesystemOpts), + /// Output JSON to stdout that contains the merged installation configuration + /// as it may be relevant to calling processes using `install to-filesystem` + /// that want to honor e.g. `root-fs-type`. + /// + /// At the current time, the only output key is `root-fs-type` which is a string-valued + /// filesystem name + PrintConfiguration, } /// Options for man page generation @@ -522,6 +529,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> { Opt::Install(opts) => match opts { InstallOpts::ToDisk(opts) => crate::install::install_to_disk(opts).await, InstallOpts::ToFilesystem(opts) => crate::install::install_to_filesystem(opts).await, + InstallOpts::PrintConfiguration => crate::install::print_configuration(), }, #[cfg(feature = "install")] Opt::ExecInHostMountNamespace { args } => { diff --git a/lib/src/install.rs b/lib/src/install.rs index b79f699c..6982ef43 100644 --- a/lib/src/install.rs +++ b/lib/src/install.rs @@ -6,7 +6,7 @@ // This sub-module is the "basic" installer that handles creating basic block device // and filesystem setup. -mod baseline; +pub(crate) mod baseline; use std::io::BufWriter; use std::io::Write; @@ -429,6 +429,13 @@ impl SourceInfo { } } +pub(crate) fn print_configuration() -> Result<()> { + let mut install_config = config::load_config()?; + install_config.filter_to_external(); + let stdout = std::io::stdout().lock(); + serde_json::to_writer(stdout, &install_config).map_err(Into::into) +} + pub(crate) mod config { use super::*; @@ -447,6 +454,7 @@ pub(crate) mod config { /// Root filesystem type pub(crate) root_fs_type: Option, /// Kernel arguments, applied at installation time + #[serde(skip_serializing_if = "Option::is_none")] pub(crate) kargs: Option>, } @@ -465,6 +473,11 @@ pub(crate) mod config { .extend(other_kargs) } } + + // Remove all configuration which is handled by `install to-filesystem`. + pub(crate) fn filter_to_external(&mut self) { + self.kargs.take(); + } } #[context("Loading configuration")] diff --git a/lib/src/privtests.rs b/lib/src/privtests.rs index 310a16eb..19fd5d38 100644 --- a/lib/src/privtests.rs +++ b/lib/src/privtests.rs @@ -1,12 +1,13 @@ use std::process::Command; -use anyhow::Result; +use anyhow::{Context, Result}; use camino::Utf8Path; use fn_error_context::context; use rustix::fd::AsFd; use xshell::{cmd, Shell}; use crate::blockdev::LoopbackDevice; +use crate::install::config::InstallConfiguration; use super::cli::TestingOpts; use super::spec::Host; @@ -98,6 +99,14 @@ pub(crate) fn impl_run_container() -> Result<()> { let stderr = String::from_utf8(o.stderr)?; assert!(stderr.contains("requires root privileges")); + let config = cmd!(sh, "bootc install print-configuration").read()?; + let config: InstallConfiguration = + serde_json::from_str(&config).context("Parsing install config")?; + assert_eq!( + config.root_fs_type.unwrap(), + crate::install::baseline::Filesystem::Xfs + ); + println!("ok container integration testing"); Ok(()) }