Compare commits

...

5 commits

6 changed files with 95 additions and 12 deletions

View file

@ -47,12 +47,13 @@ semver = { version = "1.0.18", features = ["serde"] }
toml = "0.7.6" toml = "0.7.6"
tokio = { version = "1.32.0", features = ["sync", "time"] } tokio = { version = "1.32.0", features = ["sync", "time"] }
clap = { version = "4.4.6", features = ["derive"] } clap = { version = "4.4.6", features = ["derive"] }
actix-rt = "2.7.0"
[build-dependencies] [build-dependencies]
serde_json = "1" serde_json = "1"
sqlx = { version = "0.6.1", features = [ "runtime-actix-rustls", "postgres", "time", "offline"] } sqlx = { version = "0.6.1", features = [ "runtime-actix-rustls", "postgres", "time", "offline"] }
[dev-dependencies] [dev-dependencies]
actix-rt = "2.7.0" #actix-rt = "2.7.0"
base64 = "0.13.0" base64 = "0.13.0"
mktemp = "0.5.1" mktemp = "0.5.1"

63
src/api/v1/meta.rs Normal file
View file

@ -0,0 +1,63 @@
use actix_web::{web, HttpResponse, Responder};
use serde::{Deserialize, Serialize};
use crate::{GIT_COMMIT_HASH, VERSION};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BuildDetails {
pub version: &'static str,
pub git_commit_hash: &'static str,
}
pub mod routes {
pub struct Meta {
pub build_details: &'static str,
pub health: &'static str,
}
impl Meta {
pub const fn new() -> Self {
Self {
build_details: "/api/v1/meta/build",
health: "/api/v1/meta/health",
}
}
}
}
pub const META: routes::Meta = routes::Meta::new();
/// emmits build details of the bninary
#[actix_web_codegen_const_routes::get(path = "META.build_details")]
async fn build_details() -> impl Responder {
let build = BuildDetails {
version: VERSION,
git_commit_hash: GIT_COMMIT_HASH,
};
HttpResponse::Ok().json(build)
}
pub fn services(cfg: &mut web::ServiceConfig) {
cfg.service(build_details);
}
#[cfg(test)]
mod tests {
use actix_web::{http::StatusCode, test, App};
use super::services;
#[actix_rt::test]
async fn build_details_works() {
let app = test::init_service(App::new().configure(services)).await;
let resp = test::call_service(
&app,
test::TestRequest::get()
.uri(super::META.build_details)
.to_request(),
)
.await;
assert_eq!(resp.status(), StatusCode::OK);
}
}

View file

@ -2,8 +2,10 @@
// //
// SPDX-License-Identifier: AGPL-3.0-or-later // SPDX-License-Identifier: AGPL-3.0-or-later
pub mod meta;
pub mod webhooks; pub mod webhooks;
pub fn services(cfg: &mut actix_web::web::ServiceConfig) { pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
webhooks::services(cfg); webhooks::services(cfg);
meta::services(cfg);
} }

View file

@ -131,7 +131,7 @@ impl MinAppContext for CliCtx {
&self.results &self.results
} }
fn port_(&self) -> u32 { fn port_(&self) -> u32 {
29130 80
} }
} }

View file

@ -90,6 +90,21 @@ async fn main() -> std::io::Result<()> {
} }
Command::Test { path } => { Command::Test { path } => {
let ctx: Arc<dyn MinAppContext> = Arc::new(CliCtx::new()); let ctx: Arc<dyn MinAppContext> = Arc::new(CliCtx::new());
let serv = basic_server(ctx.clone()).await;
loop {
log::info!("Waiting for server to start...");
let res = reqwest::get(&format!(
"http://localhost:29130{}",
api::v1::meta::META.build_details
))
.await;
if res.is_ok() {
log::info!("Waiting server started");
break;
}
tokio::time::sleep(std::time::Duration::new(2, 0)).await;
}
crate::runner::suite::SuiteRunnerState::run_proxy(ctx.as_ref()); crate::runner::suite::SuiteRunnerState::run_proxy(ctx.as_ref());
let (suite_results, init_containers) = let (suite_results, init_containers) =
@ -104,6 +119,7 @@ async fn main() -> std::io::Result<()> {
std::fs::write(results_file, serde_json::to_string(&content).unwrap()).unwrap(); std::fs::write(results_file, serde_json::to_string(&content).unwrap()).unwrap();
crate::runner::suite::SuiteRunnerState::stop_proxy(ctx.as_ref()); crate::runner::suite::SuiteRunnerState::stop_proxy(ctx.as_ref());
serv.stop(true).await;
Ok(()) Ok(())
} }
} }
@ -128,14 +144,14 @@ async fn run_daemon() -> std::io::Result<()> {
Ok(()) Ok(())
} }
async fn basic(ctx2: AppMinCtx) -> std::io::Result<()> { async fn basic_server(ctx: Arc<dyn MinAppContext>) -> actix_web::dev::ServerHandle {
let ip = "0.0.0.0:29130"; let ctx = AppMinCtx::new(ctx);
info!("Starting server on: http://{}", ip); info!("Starting server on: http://0.0.0.0:29130");
HttpServer::new(move || { let serv = HttpServer::new(move || {
App::new() App::new()
.wrap(TracingLogger::default()) .wrap(TracingLogger::default())
.wrap(actix_middleware::Compress::default()) .wrap(actix_middleware::Compress::default())
.app_data(ctx2.clone()) .app_data(ctx.clone())
.app_data(get_json_err()) .app_data(get_json_err())
.wrap( .wrap(
actix_middleware::DefaultHeaders::new() actix_middleware::DefaultHeaders::new()
@ -146,11 +162,12 @@ async fn basic(ctx2: AppMinCtx) -> std::io::Result<()> {
)) ))
.configure(services) .configure(services)
}) })
.bind(ip) .bind("0.0.0.0:29130")
.unwrap() .unwrap()
.run() .run();
.await?; let handle = serv.handle();
Ok(()) tokio::spawn(serv);
handle
} }
async fn daemon(ctx: AppFullCtx, ctx2: AppMinCtx) -> std::io::Result<()> { async fn daemon(ctx: AppFullCtx, ctx2: AppMinCtx) -> std::io::Result<()> {

View file

@ -68,7 +68,7 @@ impl SuiteRunnerState {
&format!("ftest_backend:{default}"), &format!("ftest_backend:{default}"),
"forgeflux/ftest-nginx-proxy", "forgeflux/ftest-nginx-proxy",
]; ];
let mut child = std::process::Command::new("docker_") let mut child = std::process::Command::new("docker")
.args(&args) .args(&args)
.spawn() .spawn()
.expect("unable to obtain docker_ version"); .expect("unable to obtain docker_ version");