120 lines
3.4 KiB
Rust
120 lines
3.4 KiB
Rust
use std::{path::PathBuf, sync::Arc};
|
|
|
|
use base64::{Engine as _, engine::general_purpose};
|
|
use harmony::{
|
|
data::Id,
|
|
inventory::Inventory,
|
|
maestro::Maestro,
|
|
modules::{
|
|
application::{
|
|
ApplicationScore, RustWebFramework, RustWebapp,
|
|
features::{ContinuousDelivery, Monitoring},
|
|
},
|
|
monitoring::{
|
|
alert_channel::webhook_receiver::WebhookReceiver,
|
|
kube_prometheus::helm_prometheus_alert_score::HelmPrometheusAlertingScore,
|
|
ntfy::ntfy::NtfyScore,
|
|
},
|
|
tenant::TenantScore,
|
|
},
|
|
score::Score,
|
|
topology::{
|
|
K8sAnywhereTopology, Url,
|
|
tenant::{ResourceLimits, TenantConfig, TenantManager, TenantNetworkPolicy},
|
|
},
|
|
};
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
env_logger::init();
|
|
|
|
let tenant = TenantScore {
|
|
config: TenantConfig {
|
|
id: Id::from_string("1234".to_string()),
|
|
name: "harmonydemo-staging".to_string(),
|
|
resource_limits: ResourceLimits {
|
|
cpu_request_cores: 6.0,
|
|
cpu_limit_cores: 4.0,
|
|
memory_request_gb: 4.0,
|
|
memory_limit_gb: 4.0,
|
|
storage_total_gb: 10.0,
|
|
},
|
|
network_policy: TenantNetworkPolicy::default(),
|
|
},
|
|
};
|
|
|
|
let topology = K8sAnywhereTopology::from_env();
|
|
|
|
// topology
|
|
// .provision_tenant(&tenant.config)
|
|
// .await
|
|
// .expect("couldn't provision tenant");
|
|
|
|
let mut maestro = Maestro::initialize(Inventory::autoload(), topology)
|
|
.await
|
|
.unwrap();
|
|
|
|
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),
|
|
});
|
|
|
|
let ntfy = NtfyScore {
|
|
namespace: tenant.clone().config.name,
|
|
};
|
|
|
|
let ntfy_default_auth_username = "harmony";
|
|
let ntfy_default_auth_password = "harmony";
|
|
let ntfy_default_auth_header = format!(
|
|
"Basic {}",
|
|
general_purpose::STANDARD.encode(format!(
|
|
"{ntfy_default_auth_username}:{ntfy_default_auth_password}"
|
|
))
|
|
);
|
|
|
|
let ntfy_default_auth_param = general_purpose::STANDARD
|
|
.encode(ntfy_default_auth_header)
|
|
.rsplit("=")
|
|
.collect::<Vec<&str>>()[0]
|
|
.to_string();
|
|
|
|
let ntfy_receiver = WebhookReceiver {
|
|
name: "ntfy-webhook".to_string(),
|
|
url: Url::Url(
|
|
url::Url::parse(
|
|
format!(
|
|
"http://ntfy.{}.svc.cluster.local/rust-web-app?auth={ntfy_default_auth_param}",
|
|
tenant.clone().config.name
|
|
)
|
|
.as_str(),
|
|
)
|
|
.unwrap(),
|
|
),
|
|
};
|
|
|
|
let alerting_score = HelmPrometheusAlertingScore {
|
|
receivers: vec![Box::new(ntfy_receiver)],
|
|
rules: vec![],
|
|
service_monitors: vec![],
|
|
};
|
|
|
|
let app = ApplicationScore {
|
|
features: vec![
|
|
Box::new(ContinuousDelivery {
|
|
application: application.clone(),
|
|
}), // TODO add monitoring, backups, multisite ha, etc
|
|
],
|
|
application,
|
|
};
|
|
|
|
maestro.register_all(vec![
|
|
Box::new(tenant),
|
|
Box::new(ntfy),
|
|
Box::new(alerting_score),
|
|
Box::new(app),
|
|
]);
|
|
harmony_cli::init(maestro, None).await.unwrap();
|
|
}
|