Add testcontainer for agent image with nginx

This commit is contained in:
GW_MC
2025-12-22 12:54:14 +08:00
parent 61ecd91219
commit 7db23b01df
13 changed files with 589 additions and 78 deletions

View File

@@ -1,9 +1,11 @@
pub mod agent;
pub mod db;
mod env;
pub mod types;
mod util;
use crate::{
agent::AgentConfigInfoType,
db::DBConfigInfoType,
types::{ConfigInfoType, WithContainer, WithoutContainer},
util::{
@@ -15,6 +17,7 @@ use crate::{
#[derive(Clone)]
pub struct Config {
pub database: DBConfigInfoType,
pub agent: Option<AgentConfigInfoType>,
}
// relative to the pwd
@@ -56,26 +59,29 @@ impl<'a> Drop for DetachedHandle<'a> {
}
async fn start(config: &Config) {
let db_config = &config.database;
//
// write the config files for the api server and database client
println!("Writing config files...");
write_env_files(db_config);
write_env_files(&config.database, &config.agent);
println!("Config files written to:");
println!(" - {}", to_absolute_path(API_CONFIG_PATH).display());
println!(" - {}", to_absolute_path(DB_CONFIG_PATH).display());
}
async fn stop(config: &Config) {
let db_config = &config.database;
// stop the container
println!("Stopping container...");
stop_container(db_config, "database".to_string()).await;
println!("Stopping database container...");
stop_container(&config.database, "database".to_string()).await;
if let Some(agent) = &config.agent {
println!("Stopping agent container...");
stop_container(agent, "agent".to_string()).await;
}
println!("Container stopped.");
// remove the generated config file
println!("Removing generated config file...");
remove_file_if_exists(DB_CONFIG_PATH);
remove_file_if_exists(API_CONFIG_PATH);
println!("Container stopped.");
println!("Generated config files removed.");
}
pub async fn start_attached(config: &Config) {