Something went wrong. Try again.
POC : Observability infrastructure managment
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115use std::future::Future;
use serde::Deserialize;use topcoat::context::Cx;use topcoat::router::{content::Form, href, page};use topcoat::view::{View, ViewExt, view};use topcoat::Result;
use crate::cli::DeployTarget;use crate::deploy::{assert_local_images_arch, build_images_for, resolve_deploy_arch};use crate::plan;use crate::ui::app;
#[derive(Debug, Deserialize)]pub struct DeployForm { pub target: String, #[serde(default)] pub name: String, #[serde(default)] pub rebuild: Option<String>,}
impl DeployForm { fn skip_build(&self) -> bool { self.rebuild.as_deref() != Some("1") }}
#[page(POST)]pub async fn action(cx: &Cx, Form(form): Form<DeployForm>) -> Result<impl View + use<'_>> { let cfg = app(cx).config_snapshot(); let config_path = app(cx).config_path.clone(); let target = form.target.clone(); let name = form.name.clone(); let skip_build = form.skip_build();
let result = tokio::task::spawn_blocking(move || -> anyhow::Result<String> { let opts = plan::PlanOpts { config_path: config_path.clone(), refresh: false, }; let plans = match target.as_str() { "hub" => vec![plan::plan_hub(&cfg, &opts)?], "satellite" => { if name.is_empty() { anyhow::bail!("name required for target=satellite"); } vec![plan::plan_satellite(&cfg, &name, &opts)?] } "all" => plan::plan_all(&cfg, &opts)?, other => anyhow::bail!("unknown target: {other}"), }; plan::print_plans(&plans); if plans.iter().any(|p| p.needs_images()) { let dt = match target.as_str() { "satellite" => DeployTarget::Satellite, "hub" => DeployTarget::Hub, _ => DeployTarget::All, }; let arch = resolve_deploy_arch(&cfg, dt, (!name.is_empty()).then_some(name.as_str()))?; if skip_build { assert_local_images_arch(arch)?; } else { build_images_for(arch)?; } } plan::apply_plans(&plans, false, &config_path)?; Ok(format!("Deploy finished ({target})")) }) .await .map_err(|e| topcoat::Error::msg(e.to_string()))?;
match result { Ok(msg) => Ok(view! { <section class="page-hero"> <p class="crumb"> <a href=(href!(super::home))>"Overview"</a> <span class="sep">"/"</span> <span>"Deploy"</span> </p> <h1>"Deploy complete"</h1> <p class="lede">"Full details are also in the terminal running sope ui."</p> </section> <div class="panel"> <div class="ok-box">(msg.clone())</div> <div class="actions"> <a class="btn" href=(href!(super::home))>"Back to overview"</a> <a class="btn-secondary btn" href=(href!(super::hub::page))>"Hub status"</a> </div> </div> } .boxed()), Err(e) => Ok(view! { <section class="page-hero"> <p class="crumb"> <a href=(href!(super::home))>"Overview"</a> <span class="sep">"/"</span> <span>"Deploy"</span> </p> <h1>"Deploy failed"</h1> <p class="lede">"Fix the error below, then retry."</p> </section> <div class="panel"> <div class="err"> <pre class="log">(format!("{e:#}"))</pre> </div> <div class="actions"> <a class="btn" href=(href!(super::home))>"Back to overview"</a> </div> </div> } .boxed()), }}