fix: Continuous delivery now works with rust example to deploy on local k3d, ingress and everything
All checks were successful
Run Check Script / check (pull_request) Successful in -3s
All checks were successful
Run Check Script / check (pull_request) Successful in -3s
This commit is contained in:
parent
539b8299ae
commit
d317c0ba76
@ -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()),
|
||||
|
@ -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");
|
||||
|
@ -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<A: OCICompliant + HelmPackage> ContinuousDelivery<A> {
|
||||
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<A: OCICompliant + HelmPackage> ContinuousDelivery<A> {
|
||||
|
||||
// --- 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
|
||||
|
@ -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<String, Box<dyn std::error::Error>> {
|
||||
// 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))
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user