Something went wrong. Try again.
POC : Observability infrastructure managment
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164mod build_job;mod cli;mod config;mod deploy;mod help;mod plan;mod progress;mod render;mod ssh;mod status;mod ui;
#[cfg(test)]mod tests;
use anyhow::{bail, Result};use clap::Parser;use cli::{Cli, Command, DeployTarget};
fn require_name(name: Option<String>, verb: &str) -> Result<String> { name.filter(|s| !s.is_empty()) .ok_or_else(|| anyhow::anyhow!("--name is required for {verb} satellite"))}
fn main() -> Result<()> { let args: Vec<String> = std::env::args().collect(); if help::maybe_print(&args) { return Ok(()); }
let cli = Cli::parse(); let config_path = &cli.config;
match cli.command { Command::Build { arch } => { let arch = match arch { Some(a) => deploy::TargetArch::parse(&a)?, None => deploy::TargetArch::host_default(), }; deploy::build_images_for(arch)?; } Command::Render { out } => { let cfg = config::load(config_path)?; let out_dir = out.unwrap_or_else(|| std::path::PathBuf::from(".sope")); render::render_all(&cfg, &out_dir)?; println!("Wrote artefacts to {}", out_dir.display()); } Command::Plan { target, name, refresh, } => { let cfg = config::load(config_path)?; let opts = plan::PlanOpts { config_path: config_path.clone(), refresh, }; let plans = match target { DeployTarget::All => plan::plan_all(&cfg, &opts)?, DeployTarget::Hub => vec![plan::plan_hub(&cfg, &opts)?], DeployTarget::Satellite => { vec![plan::plan_satellite( &cfg, &require_name(name, "plan")?, &opts, )?] } }; if matches!(target, DeployTarget::All) { plan::prune_state(config_path, &cfg)?; } plan::print_plans(&plans); println!("state: {}", plan::state_path(config_path).display()); } Command::Deploy { target, name, skip_build, full, refresh, } => { let cfg = config::load(config_path)?; let opts = plan::PlanOpts { config_path: config_path.clone(), refresh, }; let sat_name = match target { DeployTarget::Satellite => Some(require_name(name, "deploy")?), _ => name.filter(|s| !s.is_empty()), }; let plans = match target { DeployTarget::All => plan::plan_all(&cfg, &opts)?, DeployTarget::Hub => vec![plan::plan_hub(&cfg, &opts)?], DeployTarget::Satellite => { vec![plan::plan_satellite( &cfg, sat_name.as_deref().unwrap(), &opts, )?] } }; plan::print_plans(&plans); let needs_images = full || plans.iter().any(|p| p.needs_images()); if needs_images { let arch = deploy::resolve_deploy_arch(&cfg, target, sat_name.as_deref())?; if skip_build { deploy::assert_local_images_arch(arch)?; } else { deploy::build_images_for(arch)?; } } plan::apply_plans(&plans, full, config_path)?; if matches!(target, DeployTarget::All) { plan::prune_state(config_path, &cfg)?; } } Command::Status { target, name } => { let cfg = config::load(config_path)?; match target { DeployTarget::All => { deploy::status_hub(&cfg)?; for sat in &cfg.satellites { deploy::status_satellite(&cfg, &sat.name)?; } } DeployTarget::Hub => deploy::status_hub(&cfg)?, DeployTarget::Satellite => { deploy::status_satellite(&cfg, &require_name(name, "status")?)? } } } Command::Ui { bind, port } => { let cfg = config::load(config_path)?; ui::run(config_path.clone(), cfg, &bind, port)?; } Command::Destroy { target, name, yes } => { if !yes { bail!( "irreversible — re-run with --yes (e.g. sope destroy all --yes)" ); } let cfg = config::load(config_path)?; match target { DeployTarget::All => { deploy::destroy_all(&cfg)?; let _ = std::fs::remove_file(plan::state_path(config_path)); } DeployTarget::Hub => { deploy::destroy_hub(&cfg)?; plan::forget_unit(config_path, "hub")?; } DeployTarget::Satellite => { let n = require_name(name, "destroy")?; deploy::destroy_satellite(&cfg, &n)?; plan::forget_unit(config_path, &format!("satellite:{n}"))?; } } } }
Ok(())}