feat: CLI modes: verify, daemon and test
verify Checks ftest.toml for syntax daemon Runs ftest server cli Runs single ftest job
This commit is contained in:
parent
3f4b8d363e
commit
adaebe4e35
1 changed files with 77 additions and 10 deletions
87
src/main.rs
87
src/main.rs
|
@ -4,19 +4,22 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::{
|
||||
error::InternalError, http::StatusCode, middleware as actix_middleware, web::Data as WebData,
|
||||
web::JsonConfig, App, HttpServer,
|
||||
};
|
||||
//use clap::{Parser, Subcommand};
|
||||
use clap::{Args, Parser, Subcommand, ValueEnum};
|
||||
//use static_assets::FileMap;
|
||||
use tracing::info;
|
||||
use tracing_actix_web::TracingLogger;
|
||||
//
|
||||
//pub use crate::api::v1::ROUTES as V1_API_ROUTES;
|
||||
use ctx::Ctx;
|
||||
use ctx::CliCtx;
|
||||
use ctx::DaemonCtx;
|
||||
use ctx::MinAppContext;
|
||||
pub use settings::Settings;
|
||||
|
||||
pub const CACHE_AGE: u32 = 604800;
|
||||
|
@ -48,10 +51,19 @@ mod utils;
|
|||
//
|
||||
//#[derive(Parser)]
|
||||
//#[clap(author, version, about, long_about = None)]
|
||||
//struct Cli {
|
||||
// #[clap(subcommand)]
|
||||
// command: Commands,
|
||||
//}
|
||||
#[derive(Parser)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
command: Command,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Command {
|
||||
Daemon,
|
||||
Verify { path: PathBuf },
|
||||
Test { path: PathBuf },
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
|
@ -61,16 +73,46 @@ async fn main() -> std::io::Result<()> {
|
|||
}
|
||||
|
||||
pretty_env_logger::init();
|
||||
// let cli = Cli::parse();
|
||||
let cli = Cli::parse();
|
||||
|
||||
info!(
|
||||
"{}: {}.\nFor more information, see: {}\nBuild info:\nVersion: {} commit: {}",
|
||||
PKG_NAME, PKG_DESCRIPTION, PKG_HOMEPAGE, VERSION, GIT_COMMIT_HASH
|
||||
);
|
||||
|
||||
match cli.command {
|
||||
Command::Daemon => run_daemon().await,
|
||||
Command::Verify { path } => {
|
||||
let s = std::fs::read_to_string(path).unwrap();
|
||||
let _: complaince::target::Target = toml::from_str(&s).unwrap();
|
||||
println!("Syntax OK");
|
||||
Ok(())
|
||||
}
|
||||
Command::Test { path } => {
|
||||
let ctx: Arc<dyn MinAppContext> = Arc::new(CliCtx::new());
|
||||
|
||||
crate::runner::suite::SuiteRunnerState::run_proxy(ctx.as_ref());
|
||||
let (suite_results, init_containers) =
|
||||
crate::runner::target::run_target(ctx.as_ref(), path.clone()).await;
|
||||
let content = crate::runner::results::ArchivableResult {
|
||||
commit: "".into(),
|
||||
suites: suite_results,
|
||||
init_containers,
|
||||
};
|
||||
let results_file = path.join("resuts.json");
|
||||
println!("Writing results to: {:?}", path.canonicalize());
|
||||
std::fs::write(results_file, serde_json::to_string(&content).unwrap()).unwrap();
|
||||
|
||||
crate::runner::suite::SuiteRunnerState::stop_proxy(ctx.as_ref());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn run_daemon() -> std::io::Result<()> {
|
||||
let settings = Settings::new().unwrap();
|
||||
settings.init();
|
||||
let inner_ctx = Arc::new(Ctx::new(settings.clone()).await);
|
||||
let inner_ctx = Arc::new(DaemonCtx::new(settings.clone()).await);
|
||||
let ctx = AppFullCtx::new(inner_ctx.clone());
|
||||
let ctx2 = AppMinCtx::new(inner_ctx);
|
||||
ctx.db().migrate().await.unwrap();
|
||||
|
@ -79,14 +121,39 @@ async fn main() -> std::io::Result<()> {
|
|||
crate::runner::suite::SuiteRunnerState::run_proxy(ctx.as_ref());
|
||||
}
|
||||
|
||||
serve(ctx.clone(), ctx2).await?;
|
||||
daemon(ctx.clone(), ctx2).await?;
|
||||
if ctx.settings().docker_proxy {
|
||||
crate::runner::suite::SuiteRunnerState::stop_proxy(ctx.as_ref());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn serve(ctx: AppFullCtx, ctx2: AppMinCtx) -> std::io::Result<()> {
|
||||
async fn basic(ctx2: AppMinCtx) -> std::io::Result<()> {
|
||||
let ip = "0.0.0.0:29130";
|
||||
info!("Starting server on: http://{}", ip);
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.wrap(TracingLogger::default())
|
||||
.wrap(actix_middleware::Compress::default())
|
||||
.app_data(ctx2.clone())
|
||||
.app_data(get_json_err())
|
||||
.wrap(
|
||||
actix_middleware::DefaultHeaders::new()
|
||||
.add(("Permissions-Policy", "interest-cohort=()")),
|
||||
)
|
||||
.wrap(actix_middleware::NormalizePath::new(
|
||||
actix_middleware::TrailingSlash::Trim,
|
||||
))
|
||||
.configure(services)
|
||||
})
|
||||
.bind(ip)
|
||||
.unwrap()
|
||||
.run()
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn daemon(ctx: AppFullCtx, ctx2: AppMinCtx) -> std::io::Result<()> {
|
||||
let ip = ctx.settings().server.get_ip();
|
||||
let workers = ctx.settings().server.workers.unwrap_or_else(num_cpus::get);
|
||||
let scheduler = runner::scheduler::Scheduler::spawn(ctx.clone()).await;
|
||||
|
|
Loading…
Reference in a new issue