From d317c0ba765a6dcea7edb497ab48144696871f6c Mon Sep 17 00:00:00 2001 From: Jean-Gabriel Gill-Couture Date: Thu, 3 Jul 2025 15:25:43 -0400 Subject: [PATCH] fix: Continuous delivery now works with rust example to deploy on local k3d, ingress and everything --- examples/rust/src/main.rs | 1 + harmony/src/domain/config.rs | 2 +- .../features/continuous_delivery.rs | 13 +++++++---- harmony/src/modules/application/rust.rs | 22 +++++++++---------- harmony/src/modules/k3d/install.rs | 4 ++-- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/examples/rust/src/main.rs b/examples/rust/src/main.rs index e56a30f..235e30c 100644 --- a/examples/rust/src/main.rs +++ b/examples/rust/src/main.rs @@ -17,6 +17,7 @@ async fn main() { 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()), diff --git a/harmony/src/domain/config.rs b/harmony/src/domain/config.rs index 7812616..20f08a2 100644 --- a/harmony/src/domain/config.rs +++ b/harmony/src/domain/config.rs @@ -2,7 +2,7 @@ use lazy_static::lazy_static; use std::path::PathBuf; lazy_static! { - pub static ref HARMONY_CONFIG_DIR: PathBuf = directories::BaseDirs::new() + pub static ref HARMONY_DATA_DIR: PathBuf = directories::BaseDirs::new() .unwrap() .data_dir() .join("harmony"); diff --git a/harmony/src/modules/application/features/continuous_delivery.rs b/harmony/src/modules/application/features/continuous_delivery.rs index 2765c0d..d9f5830 100644 --- a/harmony/src/modules/application/features/continuous_delivery.rs +++ b/harmony/src/modules/application/features/continuous_delivery.rs @@ -6,6 +6,7 @@ use serde_json::Value; use tempfile::NamedTempFile; use crate::{ + config::HARMONY_DATA_DIR, data::Version, inventory::Inventory, modules::{ @@ -58,12 +59,15 @@ impl ContinuousDelivery { error!( "FIXME This works only with local k3d installations, which is fine only for current demo purposes. We assume usage of K8sAnywhereTopology" ); + + error!("TODO hardcoded k3d bin path is wrong"); + let k3d_bin_path = (*HARMONY_DATA_DIR).join("k3d").join("k3d"); // --- 1. Import the container image into the k3d cluster --- info!( "Importing image '{}' into k3d cluster 'harmony'", image_name ); - let import_output = Command::new("k3d") + let import_output = Command::new(&k3d_bin_path) .args(["image", "import", &image_name, "--cluster", "harmony"]) .output() .map_err(|e| format!("Failed to execute k3d image import: {}", e))?; @@ -77,7 +81,7 @@ impl ContinuousDelivery { // --- 2. Get the kubeconfig for the k3d cluster and write it to a temp file --- info!("Retrieving kubeconfig for k3d cluster 'harmony'"); - let kubeconfig_output = Command::new("k3d") + let kubeconfig_output = Command::new(&k3d_bin_path) .args(["kubeconfig", "get", "harmony"]) .output() .map_err(|e| format!("Failed to execute k3d kubeconfig get: {}", e))?; @@ -149,8 +153,9 @@ impl< let helm_chart = self.application.build_push_helm_package(&image).await?; info!("Pushed new helm chart {helm_chart}"); - let image = self.application.build_push_oci_image().await?; - info!("Pushed new docker image {image}"); + // let image = self.application.build_push_oci_image().await?; + // info!("Pushed new docker image {image}"); + error!("uncomment above"); info!("Installing ContinuousDelivery feature"); // TODO this is a temporary hack for demo purposes, the deployment target should be driven diff --git a/harmony/src/modules/application/rust.rs b/harmony/src/modules/application/rust.rs index 045d7d4..4a60ac6 100644 --- a/harmony/src/modules/application/rust.rs +++ b/harmony/src/modules/application/rust.rs @@ -378,7 +378,7 @@ image: service: type: ClusterIP - port: 80 + port: 3000 ingress: enabled: true @@ -432,7 +432,7 @@ spec: type: {{ .Values.service.type }} ports: - port: {{ .Values.service.port }} - targetPort: http + targetPort: 3000 protocol: TCP name: http selector: @@ -462,7 +462,7 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http - containerPort: 8080 # Assuming the rust app listens on 8080 + containerPort: 3000 protocol: TCP "#; fs::write(templates_dir.join("deployment.yaml"), deployment_yaml)?; @@ -499,7 +499,7 @@ spec: service: name: {{ include "chart.fullname" $ }} port: - name: http + number: 3000 {{- end }} {{- end }} {{- end }} @@ -549,25 +549,25 @@ spec: ) -> Result> { // The chart name is the file stem of the .tgz file let chart_file_name = packaged_chart_path.file_stem().unwrap().to_str().unwrap(); - let oci_url = format!( - "oci://{}/{}/{}-chart", - *REGISTRY_URL, *REGISTRY_PROJECT, self.name - ); + let oci_push_url = format!("oci://{}/{}", *REGISTRY_URL, *REGISTRY_PROJECT); + let oci_pull_url = format!("{oci_push_url}/{}-chart", self.name); info!( "Pushing Helm chart {} to {}", packaged_chart_path.to_string_lossy(), - oci_url + oci_push_url ); let output = process::Command::new("helm") - .args(["push", packaged_chart_path.to_str().unwrap(), &oci_url]) + .args(["push", packaged_chart_path.to_str().unwrap(), &oci_push_url]) .output()?; self.check_output(&output, "Pushing Helm chart failed")?; // The final URL includes the version tag, which is part of the file name let version = chart_file_name.rsplit_once('-').unwrap().1; - Ok(format!("{}:{}", oci_url, version)) + debug!("pull url {oci_pull_url}"); + debug!("push url {oci_push_url}"); + Ok(format!("{}:{}", oci_pull_url, version)) } } diff --git a/harmony/src/modules/k3d/install.rs b/harmony/src/modules/k3d/install.rs index f825f2e..18b91a0 100644 --- a/harmony/src/modules/k3d/install.rs +++ b/harmony/src/modules/k3d/install.rs @@ -5,7 +5,7 @@ use log::info; use serde::Serialize; use crate::{ - config::HARMONY_CONFIG_DIR, + config::HARMONY_DATA_DIR, data::{Id, Version}, interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, inventory::Inventory, @@ -22,7 +22,7 @@ pub struct K3DInstallationScore { impl Default for K3DInstallationScore { fn default() -> Self { Self { - installation_path: HARMONY_CONFIG_DIR.join("k3d"), + installation_path: HARMONY_DATA_DIR.join("k3d"), cluster_name: "harmony".to_string(), } }