Skip to content

Commit

Permalink
cli: add build-lint
Browse files Browse the repository at this point in the history
add simple lint to check that we only have one kernel in
image.

fixes: containers#216
Co-authored-by: Joseph Marrero <jmarrero@redhat.com>
Co-authored-by: Huijing Hei <hhei@redhat.com>
Co-authored-by: Yasmin de Souza <ydesouza@redhat.com>

Signed-off-by: Steven Presti <spresti@redhat.com>
  • Loading branch information
prestist committed May 7, 2024
1 parent 3b3e437 commit af127db
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! Command line tool to manage bootable ostree-based containers.

use anyhow::Ok;
use anyhow::{Context, Result};
use camino::Utf8PathBuf;
use cap_std_ext::cap_std;
Expand Down Expand Up @@ -292,6 +293,8 @@ pub(crate) enum Opt {
#[clap(subcommand)]
#[cfg(feature = "install")]
Install(InstallOpts),
/// Validate non supported files are not present.
BuildLint,
/// Execute the given command in the host mount namespace
#[cfg(feature = "install")]
#[clap(hide = true)]
Expand Down Expand Up @@ -610,6 +613,21 @@ async fn usroverlay() -> Result<()> {
.into());
}

/// Implementation of `bootc build commit`
/// async fn lint() -> Result<()> {
#[context("linting")]
fn lint() -> Result<()> {
if !ostree_ext::container_utils::is_ostree_container()? {
anyhow::bail!(
"Not in a ostree container, this command only verifies ostree containers."
);
}

let root = cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
ostree_ext::bootabletree::find_kernel_dir_fs(&root)?;
return Ok(());
}

/// Parse the provided arguments and execute.
/// Calls [`structopt::clap::Error::exit`] on failure, printing the error message and aborting the program.
pub async fn run_from_iter<I>(args: I) -> Result<()>
Expand Down Expand Up @@ -656,6 +674,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
Opt::Rollback(opts) => rollback(opts).await,
Opt::Edit(opts) => edit(opts).await,
Opt::UsrOverlay => usroverlay().await,
Opt::BuildLint => lint(),
#[cfg(feature = "install")]
Opt::Install(opts) => match opts {
InstallOpts::ToDisk(opts) => crate::install::install_to_disk(opts).await,
Expand Down

0 comments on commit af127db

Please sign in to comment.