use schemars::JsonSchema;
use serde::Deserialize;
use std::collections::HashMap;
use std::path::Path;
use std::time::Duration;
#[derive(Debug, Deserialize, JsonSchema)]
pub struct ArigConfig {
pub services: HashMap<String, ServiceConfig>,
}
#[derive(Debug, Clone, Default, Deserialize, JsonSchema, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ServiceType {
#[default]
Service,
Oneshot,
}
#[derive(Debug, Deserialize, JsonSchema)]
pub struct ServiceConfig {
pub command: String,
#[serde(rename = "type", default)]
pub service_type: ServiceType,
pub working_dir: Option<String>,
#[serde(default)]
pub env: HashMap<String, String>,
#[serde(default)]
pub depends_on: Vec<String>,
pub ready: Option<ReadyProbe>,
}
#[derive(Debug, Clone, Deserialize, JsonSchema)]
pub struct ReadyProbe {
pub tcp: Option<String>,
#[serde(default = "default_probe_timeout", with = "humantime_serde")]
#[schemars(with = "String")]
pub timeout: Duration,
}
fn default_probe_timeout() -> Duration {
Duration::from_secs(60)
}
impl ArigConfig {
pub fn load(path: &Path) -> anyhow::Result<Self> {
let contents = std::fs::read_to_string(path)?;
let config: ArigConfig = serde_yaml::from_str(&contents)?;
Ok(config)
}
}