Skip to content

Commit

Permalink
install: Add print-configuration
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cgwalters committed Jan 18, 2024
1 parent 1257878 commit e536c9f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 suitable for passing to `mkfs.$type`.
PrintConfiguration,
}

/// Options for man page generation
Expand Down Expand Up @@ -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 } => {
Expand Down
15 changes: 14 additions & 1 deletion lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::*;

Expand All @@ -447,6 +454,7 @@ pub(crate) mod config {
/// Root filesystem type
pub(crate) root_fs_type: Option<super::baseline::Filesystem>,
/// Kernel arguments, applied at installation time
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) kargs: Option<Vec<String>>,
}

Expand All @@ -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")]
Expand Down
11 changes: 10 additions & 1 deletion lib/src/privtests.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(())
}
Expand Down

0 comments on commit e536c9f

Please sign in to comment.