Skip to content

Commit

Permalink
Merge pull request #272 from cgwalters/install-introspect
Browse files Browse the repository at this point in the history
install: Add `print-configuration`
  • Loading branch information
vrothberg authored Jan 19, 2024
2 parents 1257878 + cd98c46 commit c99586e
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 13 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
34 changes: 34 additions & 0 deletions manpages-md/bootc-install-print-configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# NAME

bootc-install-print-configuration - 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\`

# SYNOPSIS

**bootc-install-print-configuration** \[**-h**\|**\--help**\]
\[**-V**\|**\--version**\]

# DESCRIPTION

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\`.

# OPTIONS

**-h**, **\--help**

: Print help (see a summary with -h)

**-V**, **\--version**

: Print version

# VERSION

v0.1.0
25 changes: 20 additions & 5 deletions manpages-md/bootc-install-to-disk.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ bootc-install-to-disk - Install to the target block device
# SYNOPSIS

**bootc-install-to-disk** \[**\--wipe**\] \[**\--block-setup**\]
\[**\--filesystem**\] \[**\--root-size**\] \[**\--target-transport**\]
\[**\--target-imgref**\] \[**\--enforce-container-sigpolicy**\]
\[**\--target-ostree-remote**\] \[**\--skip-fetch-check**\]
\[**\--disable-selinux**\] \[**\--karg**\] \[**\--generic-image**\]
\[**-h**\|**\--help**\] \[**-V**\|**\--version**\] \<*DEVICE*\>
\[**\--filesystem**\] \[**\--root-size**\] \[**\--source-imgref**\]
\[**\--target-transport**\] \[**\--target-imgref**\]
\[**\--enforce-container-sigpolicy**\] \[**\--target-ostree-remote**\]
\[**\--skip-fetch-check**\] \[**\--disable-selinux**\] \[**\--karg**\]
\[**\--generic-image**\] \[**\--via-loopback**\] \[**-h**\|**\--help**\]
\[**-V**\|**\--version**\] \<*DEVICE*\>

# DESCRIPTION

Expand Down Expand Up @@ -45,6 +46,16 @@ unlock of filesystem to presence of the default tpm2 device.\

By default, all remaining space on the disk will be used.

**\--source-imgref**=*SOURCE_IMGREF*

: Install the system from an explicitly given source.

By default, bootc install and install-to-filesystem assumes that it runs
in a podman container, and it takes the container image to install from
the podmans container registry. If \--source-imgref is given, bootc uses
it as the installation source, instead of the behaviour explained in the
previous paragraph. See skopeo(1) for accepted formats.

**\--target-transport**=*TARGET_TRANSPORT* \[default: registry\]

: The transport; e.g. oci, oci-archive. Defaults to \`registry\`
Expand Down Expand Up @@ -94,6 +105,10 @@ disabled but where the target does have SELinux enabled.
\- All bootloader types will be installed - Changes to the system
firmware will be skipped

**\--via-loopback**

: Instead of targeting a block device, write to a file via loopback

**-h**, **\--help**

: Print help (see a summary with -h)
Expand Down
20 changes: 15 additions & 5 deletions manpages-md/bootc-install-to-filesystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ bootc-install-to-filesystem - Install to the target filesystem

**bootc-install-to-filesystem** \[**\--root-mount-spec**\]
\[**\--root-options**\] \[**\--boot-mount-spec**\] \[**\--replace**\]
\[**\--target-transport**\] \[**\--target-imgref**\]
\[**\--enforce-container-sigpolicy**\] \[**\--target-ostree-remote**\]
\[**\--skip-fetch-check**\] \[**\--disable-selinux**\] \[**\--karg**\]
\[**\--generic-image**\] \[**-h**\|**\--help**\]
\[**-V**\|**\--version**\] \<*ROOT_PATH*\>
\[**\--source-imgref**\] \[**\--target-transport**\]
\[**\--target-imgref**\] \[**\--enforce-container-sigpolicy**\]
\[**\--target-ostree-remote**\] \[**\--skip-fetch-check**\]
\[**\--disable-selinux**\] \[**\--karg**\] \[**\--generic-image**\]
\[**-h**\|**\--help**\] \[**-V**\|**\--version**\] \<*ROOT_PATH*\>

# DESCRIPTION

Expand Down Expand Up @@ -54,6 +54,16 @@ be used.
> However, the running system (and all files) will remain in place
> until reboot
**\--source-imgref**=*SOURCE_IMGREF*

: Install the system from an explicitly given source.

By default, bootc install and install-to-filesystem assumes that it runs
in a podman container, and it takes the container image to install from
the podmans container registry. If \--source-imgref is given, bootc uses
it as the installation source, instead of the behaviour explained in the
previous paragraph. See skopeo(1) for accepted formats.

**\--target-transport**=*TARGET_TRANSPORT* \[default: registry\]

: The transport; e.g. oci, oci-archive. Defaults to \`registry\`
Expand Down
6 changes: 6 additions & 0 deletions manpages-md/bootc-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ bootc-install-to-filesystem(8)

: Install to the target filesystem

bootc-install-print-configuration(8)

: 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\`

bootc-install-help(8)

: Print this message or the help of the given subcommand(s)
Expand Down

0 comments on commit c99586e

Please sign in to comment.