Compare commits
5 Commits
adaebe4e35
...
8b0e05ba14
Author | SHA1 | Date |
---|---|---|
Aravinth Manivannan | 8b0e05ba14 | |
Aravinth Manivannan | d6a5853d34 | |
Aravinth Manivannan | a63979af76 | |
Aravinth Manivannan | b3a3fe8c0d | |
Aravinth Manivannan | 501f44560c |
|
@ -47,12 +47,13 @@ semver = { version = "1.0.18", features = ["serde"] }
|
|||
toml = "0.7.6"
|
||||
tokio = { version = "1.32.0", features = ["sync", "time"] }
|
||||
clap = { version = "4.4.6", features = ["derive"] }
|
||||
actix-rt = "2.7.0"
|
||||
|
||||
[build-dependencies]
|
||||
serde_json = "1"
|
||||
sqlx = { version = "0.6.1", features = [ "runtime-actix-rustls", "postgres", "time", "offline"] }
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "2.7.0"
|
||||
#actix-rt = "2.7.0"
|
||||
base64 = "0.13.0"
|
||||
mktemp = "0.5.1"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -2,8 +2,10 @@
|
|||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
pub mod meta;
|
||||
pub mod webhooks;
|
||||
|
||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
webhooks::services(cfg);
|
||||
meta::services(cfg);
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ impl MinAppContext for CliCtx {
|
|||
&self.results
|
||||
}
|
||||
fn port_(&self) -> u32 {
|
||||
29130
|
||||
80
|
||||
}
|
||||
}
|
||||
|
||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -90,6 +90,21 @@ async fn main() -> std::io::Result<()> {
|
|||
}
|
||||
Command::Test { path } => {
|
||||
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());
|
||||
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();
|
||||
|
||||
crate::runner::suite::SuiteRunnerState::stop_proxy(ctx.as_ref());
|
||||
serv.stop(true).await;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -128,14 +144,14 @@ async fn run_daemon() -> std::io::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn basic(ctx2: AppMinCtx) -> std::io::Result<()> {
|
||||
let ip = "0.0.0.0:29130";
|
||||
info!("Starting server on: http://{}", ip);
|
||||
HttpServer::new(move || {
|
||||
async fn basic_server(ctx: Arc<dyn MinAppContext>) -> actix_web::dev::ServerHandle {
|
||||
let ctx = AppMinCtx::new(ctx);
|
||||
info!("Starting server on: http://0.0.0.0:29130");
|
||||
let serv = HttpServer::new(move || {
|
||||
App::new()
|
||||
.wrap(TracingLogger::default())
|
||||
.wrap(actix_middleware::Compress::default())
|
||||
.app_data(ctx2.clone())
|
||||
.app_data(ctx.clone())
|
||||
.app_data(get_json_err())
|
||||
.wrap(
|
||||
actix_middleware::DefaultHeaders::new()
|
||||
|
@ -146,11 +162,12 @@ async fn basic(ctx2: AppMinCtx) -> std::io::Result<()> {
|
|||
))
|
||||
.configure(services)
|
||||
})
|
||||
.bind(ip)
|
||||
.bind("0.0.0.0:29130")
|
||||
.unwrap()
|
||||
.run()
|
||||
.await?;
|
||||
Ok(())
|
||||
.run();
|
||||
let handle = serv.handle();
|
||||
tokio::spawn(serv);
|
||||
handle
|
||||
}
|
||||
|
||||
async fn daemon(ctx: AppFullCtx, ctx2: AppMinCtx) -> std::io::Result<()> {
|
||||
|
|
|
@ -68,7 +68,7 @@ impl SuiteRunnerState {
|
|||
&format!("ftest_backend:{default}"),
|
||||
"forgeflux/ftest-nginx-proxy",
|
||||
];
|
||||
let mut child = std::process::Command::new("docker_")
|
||||
let mut child = std::process::Command::new("docker")
|
||||
.args(&args)
|
||||
.spawn()
|
||||
.expect("unable to obtain docker_ version");
|
||||
|
|
Loading…
Reference in New Issue