feat(example/lamp): add LAMPScore and configuration support

- Introduce `LAMPScore` struct with additional fields: `domain`, `config`, and `php_version`.
- Define default implementation for `LAMPConfig`.
- Update `Url` enum to use `Url(url::Url)` instead of `Remote(url::Url)`.
- Adjust references in `HttpServer` and `TftpServer` implementations.
- Modify `Interpret` trait implementation to use `name()` method from `LAMPScore`.
This commit is contained in:
2025-03-10 17:04:35 -04:00
parent fbc18d2fad
commit 7291db7ca3
9 changed files with 104 additions and 6 deletions

View File

@@ -26,6 +26,27 @@ impl Maestro {
}
}
// Load the inventory and inventory from environment.
// This function is able to discover the context that it is running in, such as k8s clusters, aws cloud, linux host, etc.
// When the HARMONY_TOPOLOGY environment variable is not set, it will default to install k3s
// locally (lazily, if not installed yet, when the first execution occurs) and use that as a topology
// So, by default, the inventory is a single host that the binary is running on, and the
// topology is a single node k3s
//
// By default :
// - Linux => k3s
// - macos, windows => docker compose
//
// To run more complex cases like OKDHACluster, either provide the default target in the
// harmony infrastructure as code or as an environment variable
pub fn load_from_env() -> Self {
// Load env var HARMONY_TOPOLOGY
match std::env::var("HARMONY_TOPOLOGY") {
Ok(_) => todo!(),
Err(_) => todo!(),
}
}
pub fn start(&mut self) {
info!("Starting Maestro");
}

View File

@@ -21,14 +21,14 @@ pub type IpAddress = IpAddr;
#[derive(Debug, Clone)]
pub enum Url {
LocalFolder(String),
Remote(url::Url),
Url(url::Url),
}
impl std::fmt::Display for Url {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Url::LocalFolder(path) => write!(f, "{}", path),
Url::Remote(url) => write!(f, "{}", url),
Url::Url(url) => write!(f, "{}", url),
}
}
}

View File

@@ -22,7 +22,7 @@ impl HttpServer for OPNSenseFirewall {
.await
.map_err(|e| ExecutorError::UnexpectedError(e.to_string()))?;
}
Url::Remote(_url) => todo!(),
Url::Url(_url) => todo!(),
}
Ok(())
}

View File

@@ -22,7 +22,7 @@ impl TftpServer for OPNSenseFirewall {
.await
.map_err(|e| ExecutorError::UnexpectedError(e.to_string()))?;
}
Url::Remote(url) => todo!("This url is not supported yet {url}"),
Url::Url(url) => todo!("This url is not supported yet {url}"),
}
Ok(())
}

View File

@@ -1,3 +1,5 @@
use std::path::{Path, PathBuf};
use async_trait::async_trait;
use crate::{
@@ -6,12 +8,30 @@ use crate::{
inventory::Inventory,
modules::k8s::deployment::K8sDeploymentScore,
score::Score,
topology::HAClusterTopology,
topology::{HAClusterTopology, Url},
};
#[derive(Debug, Clone)]
pub struct LAMPScore {
pub name: String,
pub domain: Url,
pub config: LAMPConfig,
pub php_version: Version,
}
#[derive(Debug, Clone)]
pub struct LAMPConfig {
pub project_root: PathBuf,
pub ssl_enabled: bool,
}
impl Default for LAMPConfig {
fn default() -> Self {
LAMPConfig {
project_root: Path::new("./src").to_path_buf(),
ssl_enabled: true,
}
}
}
impl Score for LAMPScore {
@@ -41,7 +61,7 @@ impl Interpret for LAMPInterpret {
topology: &HAClusterTopology,
) -> Result<Outcome, InterpretError> {
let deployment_score = K8sDeploymentScore {
name: self.score.name.clone(),
name: self.score.name(),
image: "local_image".to_string(),
};