From 800e13c75d6a746d97e642d3657db71e2f1ba051 Mon Sep 17 00:00:00 2001 From: Steven Presti Date: Thu, 21 Mar 2024 10:37:04 -0400 Subject: [PATCH] cli: add build-lint add simple lint to check that we only have one kernel in image. fixes: #216 Co-authored-by: Joseph Marrero Co-authored-by: Huijing Hei Co-authored-by: Yasmin de Souza --- lib/src/cli.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 05f1b2b7b..8fcc90c6a 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -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; @@ -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)] @@ -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(args: I) -> Result<()> @@ -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,