From 2030f1f04f0ed40dac2f35b567f8ada96aa1a33a Mon Sep 17 00:00:00 2001 From: Patrick Mahnke-Hartmann Date: Mon, 1 Sep 2025 13:13:27 +0200 Subject: [PATCH] added args for running binary --- Dockerfile.linux | 2 +- WatcherAgent/src/config.rs | 48 -------------------------------------- WatcherAgent/src/main.rs | 10 +++----- 3 files changed, 4 insertions(+), 56 deletions(-) delete mode 100644 WatcherAgent/src/config.rs diff --git a/Dockerfile.linux b/Dockerfile.linux index 711b4ac..cb902cf 100644 --- a/Dockerfile.linux +++ b/Dockerfile.linux @@ -48,4 +48,4 @@ COPY --from=linux-builder /app/target/x86_64-unknown-linux-gnu/release/${BINARY_ HEALTHCHECK --interval=30s --timeout=3s \ cmd /usr/local/bin/${BINARY_NAME} healthcheck || exit 1 -ENTRYPOINT ["/bin/sh", "-c", "/usr/local/bin/${BINARY_NAME}"] \ No newline at end of file +ENTRYPOINT ["/bin/sh", "-c", "/usr/local/bin/${BINARY_NAME}", "--", "${SERVER_URL}"] \ No newline at end of file diff --git a/WatcherAgent/src/config.rs b/WatcherAgent/src/config.rs deleted file mode 100644 index 9f137ab..0000000 --- a/WatcherAgent/src/config.rs +++ /dev/null @@ -1,48 +0,0 @@ -use config::{Config, Environment, File}; -use serde::Deserialize; - -#[derive(Debug, Deserialize, Clone)] -pub struct Settings { - pub server: ServerSettings, - pub app: AppSettings, -} - -#[derive(Debug, Deserialize, Clone)] -pub struct AppSettings { - pub heartbeat_interval_secs: u64, - pub metrics_interval_secs: u64, - pub port: u16, -} - -#[derive(Debug, Deserialize, Clone)] -pub struct ServerSettings { - pub url: String, -} - -impl Settings { - pub fn new() -> Result { - dotenvy::dotenv().ok(); - - let builder = config::Config::builder() - .add_source(File::with_name("Settings").required(false)) - .add_source( - Environment::with_prefix("APP") - .separator("_") - .prefix_separator("_"), - ) - .add_source( - Environment::with_prefix("SERVER") - .separator("_") - .prefix_separator("_"), - ); - - let config = builder.build()?; - - // Try to deserialize and provide error message - config.try_deserialize().map_err(|e| { - eprintln!("Configuration error: {}", e); - eprintln!("Required fields: server.url, app.heartbeat_interval_secs, app.metrics_interval_secs, app.port"); - e - }) - } -} diff --git a/WatcherAgent/src/main.rs b/WatcherAgent/src/main.rs index d371b56..086c87f 100644 --- a/WatcherAgent/src/main.rs +++ b/WatcherAgent/src/main.rs @@ -2,13 +2,11 @@ /// This agent collects hardware metrics and sends them to a backend server. /// It supports CPU, GPU, RAM, disk, and network metrics. pub mod api; -pub mod config; pub mod hardware; pub mod metrics; pub mod models; -use crate::config::Settings; - +use std::env; use std::error::Error; use std::marker::Send; use std::marker::Sync; @@ -27,11 +25,9 @@ async fn flatten( #[tokio::main] async fn main() -> Result<(), Box> { - let settings = Settings::new().expect("Failed to load configuration"); + let args: Vec = env::args().collect(); - // Explicit variables for each .env / config field - let _app_port = settings.app.port; - let server_url = settings.server.url; + let server_url = &args[1]; // Registration let (server_id, ip) = match api::register_with_server(&server_url).await {