Skip to content

Commit e3cc97a

Browse files
prestistjmarreroHuijingHei
committed
cli: add build-lint
add simple lint to check that we only have one kernel in image. fixes: #216 Co-authored-by: Joseph Marrero <[email protected]> Co-authored-by: Huijing Hei <[email protected]>
1 parent b809bcf commit e3cc97a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/src/cli.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! Command line tool to manage bootable ostree-based containers.
44
5+
use anyhow::Ok;
56
use anyhow::{Context, Result};
67
use camino::Utf8PathBuf;
78
use cap_std_ext::cap_std;
@@ -12,9 +13,12 @@ use ostree_container::store::PrepareResult;
1213
use ostree_ext::container as ostree_container;
1314
use ostree_ext::keyfileext::KeyFileExt;
1415
use ostree_ext::ostree;
16+
use tracing::debug;
17+
use tracing::field::debug;
1518
use std::ffi::OsString;
1619
use std::io::Seek;
1720
use std::os::unix::process::CommandExt;
21+
use std::path;
1822
use std::process::Command;
1923

2024
use crate::deploy::RequiredHostSpec;
@@ -213,6 +217,8 @@ pub(crate) enum Opt {
213217
#[clap(subcommand)]
214218
#[cfg(feature = "install")]
215219
Install(InstallOpts),
220+
/// Validate non supported files are not present.
221+
BuildLint,
216222
/// Execute the given command in the host mount namespace
217223
#[cfg(feature = "install")]
218224
#[clap(hide = true)]
@@ -511,6 +517,21 @@ async fn usroverlay() -> Result<()> {
511517
.into());
512518
}
513519

520+
/// Implementation of `bootc build commit`
521+
/// async fn lint() -> Result<()> {
522+
#[context("linting")]
523+
fn lint() -> Result<()> {
524+
if !ostree_ext::container_utils::is_ostree_container()? {
525+
anyhow::bail!(
526+
"Not in a ostree container, this command only verifies ostree containers."
527+
);
528+
}
529+
530+
let root = cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
531+
ostree_ext::bootabletree::find_kernel_dir_fs(&root)?;
532+
return Ok(());
533+
}
534+
514535
/// Parse the provided arguments and execute.
515536
/// Calls [`structopt::clap::Error::exit`] on failure, printing the error message and aborting the program.
516537
pub async fn run_from_iter<I>(args: I) -> Result<()>
@@ -528,6 +549,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
528549
Opt::Switch(opts) => switch(opts).await,
529550
Opt::Edit(opts) => edit(opts).await,
530551
Opt::UsrOverlay => usroverlay().await,
552+
Opt::BuildLint => lint(),
531553
#[cfg(feature = "install")]
532554
Opt::Install(opts) => match opts {
533555
InstallOpts::ToDisk(opts) => crate::install::install_to_disk(opts).await,

0 commit comments

Comments
 (0)