Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ pub(crate) enum InstallOpts {
/// Subcommands which can be executed as part of a container build.
#[derive(Debug, clap::Subcommand, PartialEq, Eq)]
pub(crate) enum ContainerOpts {
/// Output JSON to stdout containing the container image metadata.
Inspect {
/// Operate on the provided rootfs.
#[clap(long, default_value = "/")]
rootfs: Utf8PathBuf,
},
/// Perform relatively inexpensive static analysis checks as part of a container
/// build.
///
Expand Down Expand Up @@ -1345,6 +1351,14 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
}
}
Opt::Container(opts) => match opts {
ContainerOpts::Inspect { rootfs } => {
let root = &Dir::open_ambient_dir(&rootfs, cap_std::ambient_authority())?;
let kargs = crate::bootc_kargs::get_kargs_in_root(root, std::env::consts::ARCH)?;
let kargs: Vec<String> = kargs.iter_str().map(|s| s.to_owned()).collect();
let inspect = crate::spec::ContainerInspect { kargs };
serde_json::to_writer_pretty(std::io::stdout().lock(), &inspect)?;
Ok(())
}
ContainerOpts::Lint {
rootfs,
fatal_warnings,
Expand Down
8 changes: 8 additions & 0 deletions crates/lib/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ pub(crate) struct DeploymentEntry<'a> {
pub(crate) pinned: bool,
}

/// The result of a `bootc container inspect` command.
#[derive(Debug, Serialize)]
#[serde(rename_all = "kebab-case")]
pub(crate) struct ContainerInspect {
/// Kernel arguments embedded in the container image.
pub(crate) kargs: Vec<String>,
}

impl Host {
/// Create a new host
pub fn new(spec: HostSpec) -> Self {
Expand Down
15 changes: 15 additions & 0 deletions crates/tests-integration/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ pub(crate) fn test_bootc_status() -> Result<()> {
Ok(())
}

pub(crate) fn test_bootc_container_inspect() -> Result<()> {
let sh = Shell::new()?;
let inspect: serde_json::Value =
serde_json::from_str(&cmd!(sh, "bootc container inspect").read()?)?;

// check kargs processing
let kargs = inspect.get("kargs").unwrap().as_array().unwrap();
assert!(kargs.iter().any(|arg| arg == "kargsd-test=1"));
assert!(kargs.iter().any(|arg| arg == "kargsd-othertest=2"));
assert!(kargs.iter().any(|arg| arg == "testing-kargsd=3"));

Ok(())
}

pub(crate) fn test_bootc_upgrade() -> Result<()> {
for c in ["upgrade", "update"] {
let o = Command::new("bootc").arg(c).output()?;
Expand Down Expand Up @@ -120,6 +134,7 @@ pub(crate) fn run(testargs: libtest_mimic::Arguments) -> Result<()> {
new_test("install config", test_bootc_install_config),
new_test("printconfig --all", test_bootc_install_config_all),
new_test("status", test_bootc_status),
new_test("container inspect", test_bootc_container_inspect),
new_test("system-reinstall --help", test_system_reinstall_help),
];

Expand Down
2 changes: 1 addition & 1 deletion docs/src/host-v1.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
"description": "Bootloader type to determine whether system was booted via Grub or Systemd",
"oneOf": [
{
"description": "Use Grub as the booloader",
"description": "Use Grub as the bootloader",
"type": "string",
"const": "Grub"
},
Expand Down
36 changes: 36 additions & 0 deletions docs/src/man/bootc-container-inspect.8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# NAME

bootc-container-inspect - Output JSON to stdout containing the container image metadata

# SYNOPSIS

bootc container inspect

# DESCRIPTION

Output JSON to stdout containing the container image metadata

# OPTIONS

<!-- BEGIN GENERATED OPTIONS -->
**--rootfs**=*ROOTFS*

Operate on the provided rootfs

Default: /

<!-- END GENERATED OPTIONS -->

# EXAMPLES

Inspect container image metadata:

bootc container inspect

# SEE ALSO

**bootc**(8)

# VERSION

<!-- VERSION PLACEHOLDER -->
1 change: 1 addition & 0 deletions docs/src/man/bootc-container.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Operations which can be executed as part of a container build
<!-- BEGIN GENERATED SUBCOMMANDS -->
| Command | Description |
|---------|-------------|
| **bootc container inspect** | Output JSON to stdout containing the container image metadata |
| **bootc container lint** | Perform relatively inexpensive static analysis checks as part of a container build |

<!-- END GENERATED SUBCOMMANDS -->
Expand Down
6 changes: 6 additions & 0 deletions docs/src/man/bootc-install-print-configuration.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ filesystem type from the container image.
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

<!-- BEGIN GENERATED OPTIONS -->
**--all**

Print all configuration

<!-- END GENERATED OPTIONS -->

# VERSION
Expand Down