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:
parent
fbc18d2fad
commit
7291db7ca3
15
Cargo.lock
generated
15
Cargo.lock
generated
@ -815,6 +815,21 @@ dependencies = [
|
|||||||
"url",
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "example-lamp"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"cidr",
|
||||||
|
"env_logger",
|
||||||
|
"harmony",
|
||||||
|
"harmony_macros",
|
||||||
|
"harmony_tui",
|
||||||
|
"harmony_types",
|
||||||
|
"log",
|
||||||
|
"tokio",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "example-nanodc"
|
name = "example-nanodc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|||||||
18
examples/lamp/Cargo.toml
Normal file
18
examples/lamp/Cargo.toml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
[package]
|
||||||
|
name = "example-lamp"
|
||||||
|
edition = "2024"
|
||||||
|
version.workspace = true
|
||||||
|
readme.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
harmony = { path = "../../harmony" }
|
||||||
|
harmony_tui = { path = "../../harmony_tui" }
|
||||||
|
harmony_types = { path = "../../harmony_types" }
|
||||||
|
cidr = { workspace = true }
|
||||||
|
tokio = { workspace = true }
|
||||||
|
harmony_macros = { path = "../../harmony_macros" }
|
||||||
|
log = { workspace = true }
|
||||||
|
env_logger = { workspace = true }
|
||||||
|
url = { workspace = true }
|
||||||
3
examples/lamp/php/index.php
Normal file
3
examples/lamp/php/index.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
print_r("Hello this is from PHP")
|
||||||
|
?>
|
||||||
21
examples/lamp/src/main.rs
Normal file
21
examples/lamp/src/main.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
use harmony::{
|
||||||
|
data::Version,
|
||||||
|
maestro::Maestro,
|
||||||
|
modules::lamp::{LAMPConfig, LAMPScore},
|
||||||
|
topology::Url,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let lamp_stack = LAMPScore {
|
||||||
|
name: "harmony-lamp-demo".to_string(),
|
||||||
|
domain: Url::Url(url::Url::parse("https://lampdemo.harmony.nationtech.io").unwrap()),
|
||||||
|
php_version: Version::from("8.4.4").unwrap(),
|
||||||
|
config: LAMPConfig {
|
||||||
|
project_root: "./php".into(),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Maestro::load_from_env().interpret(Box::new(lamp_stack)).await.unwrap();
|
||||||
|
}
|
||||||
@ -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) {
|
pub fn start(&mut self) {
|
||||||
info!("Starting Maestro");
|
info!("Starting Maestro");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,14 +21,14 @@ pub type IpAddress = IpAddr;
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Url {
|
pub enum Url {
|
||||||
LocalFolder(String),
|
LocalFolder(String),
|
||||||
Remote(url::Url),
|
Url(url::Url),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Url {
|
impl std::fmt::Display for Url {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Url::LocalFolder(path) => write!(f, "{}", path),
|
Url::LocalFolder(path) => write!(f, "{}", path),
|
||||||
Url::Remote(url) => write!(f, "{}", url),
|
Url::Url(url) => write!(f, "{}", url),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ impl HttpServer for OPNSenseFirewall {
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| ExecutorError::UnexpectedError(e.to_string()))?;
|
.map_err(|e| ExecutorError::UnexpectedError(e.to_string()))?;
|
||||||
}
|
}
|
||||||
Url::Remote(_url) => todo!(),
|
Url::Url(_url) => todo!(),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ impl TftpServer for OPNSenseFirewall {
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| ExecutorError::UnexpectedError(e.to_string()))?;
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -6,12 +8,30 @@ use crate::{
|
|||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
modules::k8s::deployment::K8sDeploymentScore,
|
modules::k8s::deployment::K8sDeploymentScore,
|
||||||
score::Score,
|
score::Score,
|
||||||
topology::HAClusterTopology,
|
topology::{HAClusterTopology, Url},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct LAMPScore {
|
pub struct LAMPScore {
|
||||||
pub name: String,
|
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 {
|
impl Score for LAMPScore {
|
||||||
@ -41,7 +61,7 @@ impl Interpret for LAMPInterpret {
|
|||||||
topology: &HAClusterTopology,
|
topology: &HAClusterTopology,
|
||||||
) -> Result<Outcome, InterpretError> {
|
) -> Result<Outcome, InterpretError> {
|
||||||
let deployment_score = K8sDeploymentScore {
|
let deployment_score = K8sDeploymentScore {
|
||||||
name: self.score.name.clone(),
|
name: self.score.name(),
|
||||||
image: "local_image".to_string(),
|
image: "local_image".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user