refact: Make RustWebappScore generic, it is now Application score and takes an application and list of features to attach to the application #81
| @ -4,7 +4,7 @@ use harmony::{ | ||||
|     inventory::Inventory, | ||||
|     maestro::Maestro, | ||||
|     modules::application::{ | ||||
|         RustWebFramework, RustWebapp, RustWebappScore, features::ContinuousDelivery, | ||||
|         ApplicationScore, RustWebFramework, RustWebapp, features::ContinuousDelivery, | ||||
|     }, | ||||
|     topology::{K8sAnywhereTopology, Url}, | ||||
| }; | ||||
| @ -12,18 +12,20 @@ use harmony::{ | ||||
| #[tokio::main] | ||||
| async fn main() { | ||||
|     env_logger::init(); | ||||
|     let application = RustWebapp { | ||||
|     let application = Arc::new(RustWebapp { | ||||
|         name: "harmony-example-rust-webapp".to_string(), | ||||
|         domain: Url::Url(url::Url::parse("https://rustapp.harmony.example.com").unwrap()), | ||||
|         project_root: PathBuf::from("./examples/rust/webapp"), | ||||
|         framework: Some(RustWebFramework::Leptos), | ||||
|     }; | ||||
|     // TODO RustWebappScore should simply take a RustWebApp as config
 | ||||
|     let app = RustWebappScore { | ||||
|         name: "Example Rust Webapp".to_string(), | ||||
|         domain: Url::Url(url::Url::parse("https://rustapp.harmony.example.com").unwrap()), | ||||
|         features: vec![Box::new(ContinuousDelivery { | ||||
|             application: Arc::new(application.clone()), | ||||
|         })], | ||||
|     }); | ||||
| 
 | ||||
|     let app = ApplicationScore { | ||||
|         features: vec![ | ||||
|             Box::new(ContinuousDelivery { | ||||
|                 application: application.clone(), | ||||
|             }), | ||||
|             // TODO add monitoring, backups, multisite ha, etc
 | ||||
|         ], | ||||
|         application, | ||||
|     }; | ||||
| 
 | ||||
|  | ||||
| @ -13,7 +13,7 @@ reqwest = { version = "0.11", features = ["blocking", "json"] } | ||||
| russh = "0.45.0" | ||||
| rust-ipmi = "0.1.1" | ||||
| semver = "1.0.23" | ||||
| serde = { version = "1.0.209", features = ["derive"] } | ||||
| serde = { version = "1.0.209", features = ["derive", "rc"] } | ||||
| serde_json = "1.0.127" | ||||
| tokio.workspace = true | ||||
| derive-new.workspace = true | ||||
|  | ||||
| @ -153,6 +153,11 @@ impl< | ||||
|             "TODO reverse helm chart packaging and docker image build. I put helm package first for faster iterations" | ||||
|         ); | ||||
| 
 | ||||
|         // TODO Write CI/CD workflow files
 | ||||
|         // we can autotedect the CI type using the remote url (default to github action for github
 | ||||
|         // url, etc..)
 | ||||
|         // Or ask for it when unknown
 | ||||
| 
 | ||||
|         let helm_chart = self.application.build_push_helm_package(&image).await?; | ||||
|         info!("Pushed new helm chart {helm_chart}"); | ||||
| 
 | ||||
|  | ||||
| @ -23,13 +23,13 @@ pub trait Application: std::fmt::Debug + Send + Sync { | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub struct ApplicationInterpret<T: Topology + std::fmt::Debug> { | ||||
| pub struct ApplicationInterpret<A: Application, T: Topology + std::fmt::Debug> { | ||||
|     features: Vec<Box<dyn ApplicationFeature<T>>>, | ||||
|     application: Arc<Box<dyn Application>>, | ||||
|     application: Arc<A>, | ||||
| } | ||||
| 
 | ||||
| #[async_trait] | ||||
| impl<T: Topology + std::fmt::Debug> Interpret<T> for ApplicationInterpret<T> { | ||||
| impl<A: Application, T: Topology + std::fmt::Debug> Interpret<T> for ApplicationInterpret<A, T> { | ||||
|     async fn execute( | ||||
|         &self, | ||||
|         _inventory: &Inventory, | ||||
|  | ||||
| @ -19,23 +19,30 @@ use crate::{ | ||||
| use super::{Application, ApplicationFeature, ApplicationInterpret, HelmPackage, OCICompliant}; | ||||
| 
 | ||||
| #[derive(Debug, Serialize, Clone)] | ||||
| pub struct RustWebappScore<T: Topology + Clone + Serialize> { | ||||
|     pub name: String, | ||||
|     pub domain: Url, | ||||
| pub struct ApplicationScore<A: Application + Serialize, T: Topology + Clone + Serialize> | ||||
| where | ||||
|     Arc<A>: Serialize + Clone, | ||||
| { | ||||
|     pub features: Vec<Box<dyn ApplicationFeature<T>>>, | ||||
|     pub application: RustWebapp, | ||||
|     pub application: Arc<A>, | ||||
| } | ||||
| 
 | ||||
| impl<T: Topology + std::fmt::Debug + Clone + Serialize + 'static> Score<T> for RustWebappScore<T> { | ||||
| impl< | ||||
|     A: Application + Serialize + Clone + 'static, | ||||
|     T: Topology + std::fmt::Debug + Clone + Serialize + 'static, | ||||
| > Score<T> for ApplicationScore<A, T> | ||||
| where | ||||
|     Arc<A>: Serialize, | ||||
| { | ||||
|     fn create_interpret(&self) -> Box<dyn crate::interpret::Interpret<T>> { | ||||
|         Box::new(ApplicationInterpret { | ||||
|             features: self.features.clone(), | ||||
|             application: Arc::new(Box::new(self.application.clone())), | ||||
|             application: self.application.clone(), | ||||
|         }) | ||||
|     } | ||||
| 
 | ||||
|     fn name(&self) -> String { | ||||
|         format!("{}-RustWebapp", self.name) | ||||
|         format!("Application: {}", self.application.name()) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -47,6 +54,7 @@ pub enum RustWebFramework { | ||||
| #[derive(Debug, Clone, Serialize)] | ||||
| pub struct RustWebapp { | ||||
|     pub name: String, | ||||
|     pub domain: Url, | ||||
|     /// The path to the root of the Rust project to be containerized.
 | ||||
|     pub project_root: PathBuf, | ||||
|     pub framework: Option<RustWebFramework>, | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user