added args for running binary
This commit is contained in:
@@ -48,4 +48,4 @@ COPY --from=linux-builder /app/target/x86_64-unknown-linux-gnu/release/${BINARY_
|
|||||||
HEALTHCHECK --interval=30s --timeout=3s \
|
HEALTHCHECK --interval=30s --timeout=3s \
|
||||||
cmd /usr/local/bin/${BINARY_NAME} healthcheck || exit 1
|
cmd /usr/local/bin/${BINARY_NAME} healthcheck || exit 1
|
||||||
|
|
||||||
ENTRYPOINT ["/bin/sh", "-c", "/usr/local/bin/${BINARY_NAME}"]
|
ENTRYPOINT ["/bin/sh", "-c", "/usr/local/bin/${BINARY_NAME}", "--", "${SERVER_URL}"]
|
@@ -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<Self, config::ConfigError> {
|
|
||||||
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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@@ -2,13 +2,11 @@
|
|||||||
/// This agent collects hardware metrics and sends them to a backend server.
|
/// This agent collects hardware metrics and sends them to a backend server.
|
||||||
/// It supports CPU, GPU, RAM, disk, and network metrics.
|
/// It supports CPU, GPU, RAM, disk, and network metrics.
|
||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod config;
|
|
||||||
pub mod hardware;
|
pub mod hardware;
|
||||||
pub mod metrics;
|
pub mod metrics;
|
||||||
pub mod models;
|
pub mod models;
|
||||||
|
|
||||||
use crate::config::Settings;
|
use std::env;
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::marker::Send;
|
use std::marker::Send;
|
||||||
use std::marker::Sync;
|
use std::marker::Sync;
|
||||||
@@ -27,11 +25,9 @@ async fn flatten<T>(
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||||
let settings = Settings::new().expect("Failed to load configuration");
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
// Explicit variables for each .env / config field
|
let server_url = &args[1];
|
||||||
let _app_port = settings.app.port;
|
|
||||||
let server_url = settings.server.url;
|
|
||||||
|
|
||||||
// Registration
|
// Registration
|
||||||
let (server_id, ip) = match api::register_with_server(&server_url).await {
|
let (server_id, ip) = match api::register_with_server(&server_url).await {
|
||||||
|
Reference in New Issue
Block a user