feat: add discovery
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-11-24 17:12:15 +01:00
parent c4434fd841
commit ee323e99e8
20 changed files with 1482 additions and 117 deletions

View File

@@ -2,27 +2,29 @@ use std::net::SocketAddr;
use clap::{Parser, Subcommand};
use crate::{agent, api, state::SharedState};
use crate::{agent, server};
pub async fn execute() -> anyhow::Result<()> {
let state = SharedState::new().await?;
let cli = Command::parse();
match cli.command.expect("to have a subcommand") {
Commands::Serve { host } => {
Commands::Serve {
host,
grpc_host,
config,
} => {
tracing::info!("Starting service");
notmad::Mad::builder()
.add(api::Api::new(&state, host))
.run()
.await?;
server::execute(host, grpc_host, config).await?;
}
Commands::Agent { commands } => match commands {
AgentCommands::Start { host } => {
AgentCommands::Start {} => {
tracing::info!("starting agent");
agent::execute(host).await?;
agent::execute().await?;
tracing::info!("shut down agent");
}
AgentCommands::Setup { force, discovery } => {
agent::setup_config(discovery, force).await?;
tracing::info!("wrote default agent config");
}
},
}
@@ -41,6 +43,12 @@ enum Commands {
Serve {
#[arg(env = "SERVICE_HOST", long, default_value = "127.0.0.1:3000")]
host: SocketAddr,
#[arg(env = "SERVICE_GRPC_HOST", long, default_value = "127.0.0.1:7900")]
grpc_host: SocketAddr,
#[clap(flatten)]
config: server::config::ServerConfig,
},
Agent {
#[command(subcommand)]
@@ -50,8 +58,12 @@ enum Commands {
#[derive(Subcommand)]
enum AgentCommands {
Start {
#[arg(env = "SERVICE_HOST", long = "service-host")]
host: String,
Start {},
Setup {
#[arg(long, default_value = "false")]
force: bool,
#[arg(env = "DISCOVERY_HOST", long = "discovery")]
discovery: String,
},
}