From b4e157f9caa4844bd8859c2955f6d91753d0f492 Mon Sep 17 00:00:00 2001 From: Oluwatobi Bamidele Date: Tue, 26 Nov 2024 18:27:36 +0100 Subject: [PATCH] chore: display swarm version --- app/src/Dashboard.svelte | 22 +++++++++---- app/src/helpers/swarm.ts | 3 ++ app/src/store.ts | 2 ++ src/bin/super/cmd.rs | 2 +- src/bin/super/lightning_bots.rs | 58 +++++++++++++++++++++------------ src/bin/super/mod.rs | 7 ++-- src/dock.rs | 36 ++++++++++++++++---- 7 files changed, 93 insertions(+), 37 deletions(-) diff --git a/app/src/Dashboard.svelte b/app/src/Dashboard.svelte index 0778b9b9..c865c91d 100644 --- a/app/src/Dashboard.svelte +++ b/app/src/Dashboard.svelte @@ -7,6 +7,7 @@ selectedNode, nodes_exited, current_swarm_user, + swarmVersion, } from "./store"; import { Loading, @@ -139,10 +140,14 @@
- Sphinx Stack +
+ Sphinx Stack + +

{$swarmVersion}

+
{#if !$stack.ready} {/if} @@ -220,6 +225,7 @@ .logo-wrap { display: flex; align-items: center; + gap: 2.5rem; } .head_section { @@ -230,7 +236,6 @@ .logo-wrap .logo { width: 70px; padding: 12px; - margin-left: 2.5rem; } .body { display: flex; @@ -239,10 +244,10 @@ .lefty { height: 100%; border-right: 1px solid #101317; + padding: 1rem; } .stack-title { color: white; - margin-left: 0.5rem; font-size: 1.2rem; width: 18rem; } @@ -270,4 +275,9 @@ font-weight: 500; cursor: pointer; } + + .swarm_version { + font-size: 0.9rem; + font-family: "Barlow"; + } diff --git a/app/src/helpers/swarm.ts b/app/src/helpers/swarm.ts index 4965185b..fb8a6db4 100644 --- a/app/src/helpers/swarm.ts +++ b/app/src/helpers/swarm.ts @@ -1,6 +1,7 @@ import type { Writable } from "svelte/store"; import { get_all_image_actual_version, get_image_tags } from "../api/swarm"; import type { Stack, Node } from "../nodes"; +import { swarmVersion } from "../store"; export async function getImageVersion( stack: Writable, @@ -15,6 +16,8 @@ export async function getImageVersion( version_object[image_version.name] = image_version.version; } + swarmVersion.set(version_object["swarm"]); + stack.update((stack) => { for (let i = 0; i < stack.nodes.length; i++) { const new_version = version_object[stack.nodes[i].name]; diff --git a/app/src/store.ts b/app/src/store.ts index c736dc25..5845aa7b 100644 --- a/app/src/store.ts +++ b/app/src/store.ts @@ -26,6 +26,8 @@ export const users = writable(initialUsers); export const current_swarm_user = writable(); +export const swarmVersion = writable(""); + export const tribes = writable({ page: 1, total: 0, diff --git a/src/bin/super/cmd.rs b/src/bin/super/cmd.rs index 46300af2..6c485ffe 100644 --- a/src/bin/super/cmd.rs +++ b/src/bin/super/cmd.rs @@ -102,7 +102,7 @@ pub enum SwarmCmd { ChangeChildSwarmPassword(ChangeUserPasswordBySuperAdminRequest), GetLightningBotsDetails, ChangeLightningBotLabel(ChangeLightningBotLabel), - CreateInvoiceForLightningBot(CreateInvoiceLightningBotReq) + CreateInvoiceForLightningBot(CreateInvoiceLightningBotReq), } #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/src/bin/super/lightning_bots.rs b/src/bin/super/lightning_bots.rs index f6e6a7f9..248aa876 100644 --- a/src/bin/super/lightning_bots.rs +++ b/src/bin/super/lightning_bots.rs @@ -1,6 +1,7 @@ use crate::{ cmd::{ - ChangeLightningBotLabel, LightningBotAccountRes, LightningBotBalanceRes, SuperSwarmResponse, CreateInvoiceLightningBotReq,LightningBotCreateInvoiceReq + ChangeLightningBotLabel, CreateInvoiceLightningBotReq, LightningBotAccountRes, + LightningBotBalanceRes, LightningBotCreateInvoiceReq, SuperSwarmResponse, }, state::{LightningBotsDetails, Super}, }; @@ -199,15 +200,21 @@ pub async fn change_lightning_bot_label( } } -pub async fn create_invoice_lightning_bot(state: &Super,info: CreateInvoiceLightningBotReq)-> SuperSwarmResponse { +pub async fn create_invoice_lightning_bot( + state: &Super, + info: CreateInvoiceLightningBotReq, +) -> SuperSwarmResponse { // find bot - let bot_option = state.lightning_bots.iter().find(|lightning_bot | lightning_bot.url == info.id); + let bot_option = state + .lightning_bots + .iter() + .find(|lightning_bot| lightning_bot.url == info.id); if bot_option.is_none() { return SuperSwarmResponse { success: false, message: "bot does not exist".to_string(), - data: None - } + data: None, + }; } let bot = bot_option.unwrap(); @@ -216,33 +223,39 @@ pub async fn create_invoice_lightning_bot(state: &Super,info: CreateInvoiceLight let invoice_res = match create_invoice_request(&bot.url, &bot.token, info.amt_msat).await { Ok(res) => res, Err(err) => { - log::error!("Error making request to create invoice: {}", err.to_string()); + log::error!( + "Error making request to create invoice: {}", + err.to_string() + ); return SuperSwarmResponse { success: false, message: err.to_string(), - data: None - } + data: None, + }; } }; if invoice_res.status() != StatusCode::OK { - log::error!("Did not get status created OK for creating invoice: {}", invoice_res.status()); + log::error!( + "Did not get status created OK for creating invoice: {}", + invoice_res.status() + ); return SuperSwarmResponse { success: false, - message:format!("Got unexpected status response {}", invoice_res.status()), - data: None - } + message: format!("Got unexpected status response {}", invoice_res.status()), + data: None, + }; } - let invoice_details:Value = match invoice_res.json().await { + let invoice_details: Value = match invoice_res.json().await { Ok(value) => value, Err(err) => { log::error!("Error converting response to value: {}", err.to_string()); return SuperSwarmResponse { success: false, message: format!("Error converting response to value: {}", err.to_string()), - data: None - } + data: None, + }; } }; @@ -250,18 +263,21 @@ pub async fn create_invoice_lightning_bot(state: &Super,info: CreateInvoiceLight SuperSwarmResponse { success: true, message: "invoice created".to_string(), - data: Some(invoice_details) + data: Some(invoice_details), } } async fn create_invoice_request(url: &str, token: &str, amt_msat: u64) -> Result { let client = make_reqwest_client(); - let body = LightningBotCreateInvoiceReq { - amt_msat: amt_msat - }; + let body = LightningBotCreateInvoiceReq { amt_msat: amt_msat }; - let res = client.post(format!("https://{}/invoice", url)).header("x-admin-token", token).json(&body).send().await?; + let res = client + .post(format!("https://{}/invoice", url)) + .header("x-admin-token", token) + .json(&body) + .send() + .await?; - Ok (res) + Ok(res) } diff --git a/src/bin/super/mod.rs b/src/bin/super/mod.rs index 542cb082..4fb8aa4a 100644 --- a/src/bin/super/mod.rs +++ b/src/bin/super/mod.rs @@ -11,7 +11,9 @@ mod util; use cmd::{AddSwarmResponse, SuperSwarmResponse}; use cmd::{Cmd, SwarmCmd}; -use lightning_bots::{change_lightning_bot_label, get_lightning_bots_details, create_invoice_lightning_bot}; +use lightning_bots::{ + change_lightning_bot_label, create_invoice_lightning_bot, get_lightning_bots_details, +}; use sphinx_swarm::utils::getenv; use state::RemoteStack; use state::Super; @@ -413,8 +415,7 @@ pub async fn super_handle( Some(serde_json::to_string(&res)?) } SwarmCmd::CreateInvoiceForLightningBot(info) => { - let res: SuperSwarmResponse = - create_invoice_lightning_bot(&state, info).await; + let res: SuperSwarmResponse = create_invoice_lightning_bot(&state, info).await; Some(serde_json::to_string(&res)?) } }, diff --git a/src/dock.rs b/src/dock.rs index 89bcc82c..0927579b 100644 --- a/src/dock.rs +++ b/src/dock.rs @@ -565,6 +565,13 @@ pub struct ImageVersion { pub version: String, } +#[derive(Serialize, Deserialize, Debug)] +pub struct ParsedNode { + pub name: String, + pub org: String, + pub host: String, +} + // get image digest pub async fn get_image_digest(image_name: &str) -> Result { let docker = Docker::connect_with_local_defaults()?; @@ -595,12 +602,31 @@ pub async fn get_image_digest(image_name: &str) -> Result) -> Result { let docker = Docker::connect_with_local_defaults()?; - let mut images_version: Vec = Vec::new(); + let mut parsed_node: Vec = vec![ParsedNode { + name: "swarm".to_string(), + host: "sphinx-swarm".to_string(), + org: "".to_string(), + }]; for node in nodes.iter() { let node_name = node.name(); let host = domain(&node_name); - let image_id = get_image_id(&docker, &host).await; + + let node_image = find_img(&node_name, nodes)?; + let org = node_image.repo().org; + + parsed_node.push(ParsedNode { + name: node_name, + org: org, + host: host, + }) + } + + let mut images_version: Vec = Vec::new(); + + for node in parsed_node.iter() { + let node_name = node.name.clone(); + let image_id = get_image_id(&docker, &node.host).await; if image_id.is_empty() { images_version.push(ImageVersion { name: node_name, @@ -624,10 +650,8 @@ pub async fn get_image_actual_version(nodes: &Vec) -> Result