| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- use anyhow::Result;
- use clap::Parser;
- mod before_serve;
- mod cli;
- mod config;
- mod docker;
- mod doctor;
- mod exec;
- mod health;
- mod host_keys;
- mod ssh;
- mod tmux;
- use crate::cli::{Cli, Commands};
- use crate::config::{Cluster, Config, resolve_cluster_for_recipe, select_cluster_by_name};
- use crate::ssh::fetch_host_key;
- #[tokio::main]
- async fn main() -> Result<()> {
- tracing_subscriber::fmt::init();
- let cli = Cli::parse();
- let raw_config = tokio::fs::read_to_string(&cli.config).await?;
- let config: Config = toml::from_str(&raw_config)?;
- let dry_run = cli.dry_run;
- match cli.command {
- Commands::Serve {
- recipe,
- cluster,
- keep,
- skip_before_serve,
- } => {
- docker::serve(&config, &recipe, &cluster, keep, skip_before_serve, dry_run).await?;
- }
- Commands::Logs {
- recipe: recipe_name,
- follow,
- } => {
- let (cluster, _recipe) = resolve_cluster_for_recipe(&config, &recipe_name).await?;
- docker::show_logs(&config, &cluster, &recipe_name, follow, dry_run).await?;
- }
- Commands::Stop {
- recipe: recipe_name,
- } => {
- let (cluster, _recipe) = resolve_cluster_for_recipe(&config, &recipe_name).await?;
- docker::stop_cluster(&config, &cluster, &recipe_name, dry_run).await?;
- }
- Commands::Health {
- cluster: cluster_name,
- fingerprint,
- } => {
- if fingerprint {
- let clusters_to_check: Vec<Cluster> = match &cluster_name {
- Some(name) => vec![select_cluster_by_name(&config, name)?],
- None => config.clusters.clone(),
- };
- for cluster in &clusters_to_check {
- println!("\n=== Кластер: {} ===", cluster.name);
- for node in &cluster.nodes {
- match fetch_host_key(&config, node).await {
- Ok(fp) => {
- println!("{} ({}) -> host_key = \"{}\"", node.name, node.ssh_ip, fp)
- }
- Err(e) => println!("{} ({}) -> error: {}", node.name, node.ssh_ip, e),
- }
- }
- }
- } else {
- match cluster_name {
- Some(ref name) => {
- let cluster = select_cluster_by_name(&config, name)?;
- docker::health_check(&config, &cluster, dry_run).await?;
- }
- None => {
- for cluster in &config.clusters {
- docker::health_check(&config, cluster, dry_run).await?;
- }
- }
- }
- }
- }
- Commands::Doctor {
- recipe,
- cluster,
- repair,
- } => {
- doctor::doctor(&config, &recipe, &cluster, repair, dry_run).await?;
- }
- Commands::Tmux(tmux_cmd) => {
- crate::tmux::handle_tmux(&config, tmux_cmd, dry_run).await?;
- }
- Commands::InitHostKeys { cluster } => {
- host_keys::init_host_keys(&config, cluster.as_deref(), &cli.config).await?;
- }
- Commands::Exec {
- cluster,
- recipe,
- node,
- command,
- } => {
- let (cluster, _recipe) =
- exec::resolve_target(&config, cluster.as_deref(), recipe.as_deref()).await?;
- // Join the trailing args into a single command line.
- let cmd_str = command.join(" ");
- exec::run(&config, &cluster, node.as_deref(), &cmd_str, dry_run).await?;
- }
- }
- Ok(())
- }
|