Skip to content

Commit c99586e

Browse files
authored
Merge pull request #272 from cgwalters/install-introspect
install: Add `print-configuration`
2 parents 1257878 + cd98c46 commit c99586e

File tree

8 files changed

+108
-13
lines changed

8 files changed

+108
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
name: "Container testing"
107107
needs: build-fedora
108108
runs-on: ubuntu-latest
109-
container: quay.io/fedora/fedora-coreos:testing-devel
109+
container: quay.io/centos-bootc/fedora-bootc:eln
110110
steps:
111111
- name: Download
112112
uses: actions/download-artifact@v3

lib/src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ pub(crate) enum InstallOpts {
118118
ToDisk(crate::install::InstallToDiskOpts),
119119
/// Install to the target filesystem
120120
ToFilesystem(crate::install::InstallToFilesystemOpts),
121+
/// Output JSON to stdout that contains the merged installation configuration
122+
/// as it may be relevant to calling processes using `install to-filesystem`
123+
/// that want to honor e.g. `root-fs-type`.
124+
///
125+
/// At the current time, the only output key is `root-fs-type` which is a string-valued
126+
/// filesystem name suitable for passing to `mkfs.$type`.
127+
PrintConfiguration,
121128
}
122129

123130
/// Options for man page generation
@@ -522,6 +529,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
522529
Opt::Install(opts) => match opts {
523530
InstallOpts::ToDisk(opts) => crate::install::install_to_disk(opts).await,
524531
InstallOpts::ToFilesystem(opts) => crate::install::install_to_filesystem(opts).await,
532+
InstallOpts::PrintConfiguration => crate::install::print_configuration(),
525533
},
526534
#[cfg(feature = "install")]
527535
Opt::ExecInHostMountNamespace { args } => {

lib/src/install.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
// This sub-module is the "basic" installer that handles creating basic block device
88
// and filesystem setup.
9-
mod baseline;
9+
pub(crate) mod baseline;
1010

1111
use std::io::BufWriter;
1212
use std::io::Write;
@@ -429,6 +429,13 @@ impl SourceInfo {
429429
}
430430
}
431431

432+
pub(crate) fn print_configuration() -> Result<()> {
433+
let mut install_config = config::load_config()?;
434+
install_config.filter_to_external();
435+
let stdout = std::io::stdout().lock();
436+
serde_json::to_writer(stdout, &install_config).map_err(Into::into)
437+
}
438+
432439
pub(crate) mod config {
433440
use super::*;
434441

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

@@ -465,6 +473,11 @@ pub(crate) mod config {
465473
.extend(other_kargs)
466474
}
467475
}
476+
477+
// Remove all configuration which is handled by `install to-filesystem`.
478+
pub(crate) fn filter_to_external(&mut self) {
479+
self.kargs.take();
480+
}
468481
}
469482

470483
#[context("Loading configuration")]

lib/src/privtests.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::process::Command;
22

3-
use anyhow::Result;
3+
use anyhow::{Context, Result};
44
use camino::Utf8Path;
55
use fn_error_context::context;
66
use rustix::fd::AsFd;
77
use xshell::{cmd, Shell};
88

99
use crate::blockdev::LoopbackDevice;
10+
use crate::install::config::InstallConfiguration;
1011

1112
use super::cli::TestingOpts;
1213
use super::spec::Host;
@@ -98,6 +99,14 @@ pub(crate) fn impl_run_container() -> Result<()> {
9899
let stderr = String::from_utf8(o.stderr)?;
99100
assert!(stderr.contains("requires root privileges"));
100101

102+
let config = cmd!(sh, "bootc install print-configuration").read()?;
103+
let config: InstallConfiguration =
104+
serde_json::from_str(&config).context("Parsing install config")?;
105+
assert_eq!(
106+
config.root_fs_type.unwrap(),
107+
crate::install::baseline::Filesystem::Xfs
108+
);
109+
101110
println!("ok container integration testing");
102111
Ok(())
103112
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# NAME
2+
3+
bootc-install-print-configuration - Output JSON to stdout that contains
4+
the merged installation configuration as it may be relevant to calling
5+
processes using \`install to-filesystem\` that want to honor e.g.
6+
\`root-fs-type\`
7+
8+
# SYNOPSIS
9+
10+
**bootc-install-print-configuration** \[**-h**\|**\--help**\]
11+
\[**-V**\|**\--version**\]
12+
13+
# DESCRIPTION
14+
15+
Output JSON to stdout that contains the merged installation
16+
configuration as it may be relevant to calling processes using \`install
17+
to-filesystem\` that want to honor e.g. \`root-fs-type\`.
18+
19+
At the current time, the only output key is \`root-fs-type\` which is a
20+
string-valued filesystem name suitable for passing to \`mkfs.\$type\`.
21+
22+
# OPTIONS
23+
24+
**-h**, **\--help**
25+
26+
: Print help (see a summary with -h)
27+
28+
**-V**, **\--version**
29+
30+
: Print version
31+
32+
# VERSION
33+
34+
v0.1.0

manpages-md/bootc-install-to-disk.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ bootc-install-to-disk - Install to the target block device
55
# SYNOPSIS
66

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

1415
# DESCRIPTION
1516

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

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

49+
**\--source-imgref**=*SOURCE_IMGREF*
50+
51+
: Install the system from an explicitly given source.
52+
53+
By default, bootc install and install-to-filesystem assumes that it runs
54+
in a podman container, and it takes the container image to install from
55+
the podmans container registry. If \--source-imgref is given, bootc uses
56+
it as the installation source, instead of the behaviour explained in the
57+
previous paragraph. See skopeo(1) for accepted formats.
58+
4859
**\--target-transport**=*TARGET_TRANSPORT* \[default: registry\]
4960

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

108+
**\--via-loopback**
109+
110+
: Instead of targeting a block device, write to a file via loopback
111+
97112
**-h**, **\--help**
98113

99114
: Print help (see a summary with -h)

manpages-md/bootc-install-to-filesystem.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ bootc-install-to-filesystem - Install to the target filesystem
66

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

1515
# DESCRIPTION
1616

@@ -54,6 +54,16 @@ be used.
5454
> However, the running system (and all files) will remain in place
5555
> until reboot
5656
57+
**\--source-imgref**=*SOURCE_IMGREF*
58+
59+
: Install the system from an explicitly given source.
60+
61+
By default, bootc install and install-to-filesystem assumes that it runs
62+
in a podman container, and it takes the container image to install from
63+
the podmans container registry. If \--source-imgref is given, bootc uses
64+
it as the installation source, instead of the behaviour explained in the
65+
previous paragraph. See skopeo(1) for accepted formats.
66+
5767
**\--target-transport**=*TARGET_TRANSPORT* \[default: registry\]
5868

5969
: The transport; e.g. oci, oci-archive. Defaults to \`registry\`

manpages-md/bootc-install.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ bootc-install-to-filesystem(8)
3535

3636
: Install to the target filesystem
3737

38+
bootc-install-print-configuration(8)
39+
40+
: Output JSON to stdout that contains the merged installation
41+
configuration as it may be relevant to calling processes using
42+
\`install to-filesystem\` that want to honor e.g. \`root-fs-type\`
43+
3844
bootc-install-help(8)
3945

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

0 commit comments

Comments
 (0)