Skip to content

Commit b4cb36a

Browse files
committed
cli: Add container inspect
Prints JSON of container metadata/attributes of interest. For now this just renders out the kargs embedded in the container under the kargs.d drop-in. Future ideas for enhancements would be to include kernel version and whether or not the image uses a UKI. Closes: #1827 Signed-off-by: John Eckersberg <[email protected]>
1 parent 3f5a3c7 commit b4cb36a

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

crates/lib/src/cli.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ use crate::store::{BootedOstree, ComposefsRepository, Storage};
5252
use crate::store::{BootedStorage, BootedStorageKind};
5353
use crate::utils::sigpolicy_from_opt;
5454

55+
/// The result of a `bootc container inspect` command.
56+
#[derive(Debug, Serialize)]
57+
#[serde(rename_all = "kebab-case")]
58+
pub(crate) struct ContainerInspect {
59+
/// Kernel arguments embedded in the container image.
60+
pub(crate) kargs: Vec<String>,
61+
}
62+
5563
/// Shared progress options
5664
#[derive(Debug, Parser, PartialEq, Eq)]
5765
pub(crate) struct ProgressOptions {
@@ -295,6 +303,12 @@ pub(crate) enum InstallOpts {
295303
/// Subcommands which can be executed as part of a container build.
296304
#[derive(Debug, clap::Subcommand, PartialEq, Eq)]
297305
pub(crate) enum ContainerOpts {
306+
/// Output JSON to stdout containing the container image metadata.
307+
Inspect {
308+
/// Operate on the provided rootfs.
309+
#[clap(long, default_value = "/")]
310+
rootfs: Utf8PathBuf,
311+
},
298312
/// Perform relatively inexpensive static analysis checks as part of a container
299313
/// build.
300314
///
@@ -1345,6 +1359,14 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
13451359
}
13461360
}
13471361
Opt::Container(opts) => match opts {
1362+
ContainerOpts::Inspect { rootfs } => {
1363+
let root = &Dir::open_ambient_dir(&rootfs, cap_std::ambient_authority())?;
1364+
let kargs = crate::bootc_kargs::get_kargs_in_root(root, std::env::consts::ARCH)?;
1365+
let kargs: Vec<String> = kargs.iter_str().map(|s| s.to_owned()).collect();
1366+
let inspect = ContainerInspect { kargs };
1367+
serde_json::to_writer_pretty(std::io::stdout().lock(), &inspect)?;
1368+
Ok(())
1369+
}
13481370
ContainerOpts::Lint {
13491371
rootfs,
13501372
fatal_warnings,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std assert
2+
use tap.nu
3+
4+
tap begin "verify bootc container inspect"
5+
6+
# Run container inspect and parse the JSON output
7+
let inspect = bootc container inspect | from json
8+
9+
# Verify we get the expected kargs from the test image
10+
# These are defined in hack/test-kargs/*.toml
11+
assert ($inspect.kargs | any { |k| $k == "kargsd-test=1" }) "expected kargsd-test=1"
12+
assert ($inspect.kargs | any { |k| $k == "kargsd-othertest=2" }) "expected kargsd-othertest=2"
13+
assert ($inspect.kargs | any { |k| $k == "testing-kargsd=3" }) "expected testing-kargsd=3"
14+
15+
tap ok

0 commit comments

Comments
 (0)