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"),
|
project_root: PathBuf::from("./examples/rust/webapp"),
|
||||||
framework: Some(RustWebFramework::Leptos),
|
framework: Some(RustWebFramework::Leptos),
|
||||||
};
|
};
|
||||||
|
// TODO RustWebappScore should simply take a RustWebApp as config
|
||||||
let app = RustWebappScore {
|
let app = RustWebappScore {
|
||||||
name: "Example Rust Webapp".to_string(),
|
name: "Example Rust Webapp".to_string(),
|
||||||
domain: Url::Url(url::Url::parse("https://rustapp.harmony.example.com").unwrap()),
|
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;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref HARMONY_CONFIG_DIR: PathBuf = directories::BaseDirs::new()
|
pub static ref HARMONY_DATA_DIR: PathBuf = directories::BaseDirs::new()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.data_dir()
|
.data_dir()
|
||||||
.join("harmony");
|
.join("harmony");
|
||||||
|
@ -6,6 +6,7 @@ use serde_json::Value;
|
|||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
config::HARMONY_DATA_DIR,
|
||||||
data::Version,
|
data::Version,
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
modules::{
|
modules::{
|
||||||
@ -58,12 +59,15 @@ impl<A: OCICompliant + HelmPackage> ContinuousDelivery<A> {
|
|||||||
error!(
|
error!(
|
||||||
"FIXME This works only with local k3d installations, which is fine only for current demo purposes. We assume usage of K8sAnywhereTopology"
|
"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 ---
|
// --- 1. Import the container image into the k3d cluster ---
|
||||||
info!(
|
info!(
|
||||||
"Importing image '{}' into k3d cluster 'harmony'",
|
"Importing image '{}' into k3d cluster 'harmony'",
|
||||||
image_name
|
image_name
|
||||||
);
|
);
|
||||||
let import_output = Command::new("k3d")
|
let import_output = Command::new(&k3d_bin_path)
|
||||||
.args(["image", "import", &image_name, "--cluster", "harmony"])
|
.args(["image", "import", &image_name, "--cluster", "harmony"])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| format!("Failed to execute k3d image import: {}", e))?;
|
.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 ---
|
// --- 2. Get the kubeconfig for the k3d cluster and write it to a temp file ---
|
||||||
info!("Retrieving kubeconfig for k3d cluster 'harmony'");
|
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"])
|
.args(["kubeconfig", "get", "harmony"])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| format!("Failed to execute k3d kubeconfig get: {}", e))?;
|
.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?;
|
let helm_chart = self.application.build_push_helm_package(&image).await?;
|
||||||
info!("Pushed new helm chart {helm_chart}");
|
info!("Pushed new helm chart {helm_chart}");
|
||||||
|
|
||||||
let image = self.application.build_push_oci_image().await?;
|
// let image = self.application.build_push_oci_image().await?;
|
||||||
info!("Pushed new docker image {image}");
|
// info!("Pushed new docker image {image}");
|
||||||
|
error!("uncomment above");
|
||||||
|
|
||||||
info!("Installing ContinuousDelivery feature");
|
info!("Installing ContinuousDelivery feature");
|
||||||
// TODO this is a temporary hack for demo purposes, the deployment target should be driven
|
// TODO this is a temporary hack for demo purposes, the deployment target should be driven
|
||||||
|
@ -378,7 +378,7 @@ image:
|
|||||||
|
|
||||||
service:
|
service:
|
||||||
type: ClusterIP
|
type: ClusterIP
|
||||||
port: 80
|
port: 3000
|
||||||
|
|
||||||
ingress:
|
ingress:
|
||||||
enabled: true
|
enabled: true
|
||||||
@ -432,7 +432,7 @@ spec:
|
|||||||
type: {{ .Values.service.type }}
|
type: {{ .Values.service.type }}
|
||||||
ports:
|
ports:
|
||||||
- port: {{ .Values.service.port }}
|
- port: {{ .Values.service.port }}
|
||||||
targetPort: http
|
targetPort: 3000
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
name: http
|
name: http
|
||||||
selector:
|
selector:
|
||||||
@ -462,7 +462,7 @@ spec:
|
|||||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||||
ports:
|
ports:
|
||||||
- name: http
|
- name: http
|
||||||
containerPort: 8080 # Assuming the rust app listens on 8080
|
containerPort: 3000
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
"#;
|
"#;
|
||||||
fs::write(templates_dir.join("deployment.yaml"), deployment_yaml)?;
|
fs::write(templates_dir.join("deployment.yaml"), deployment_yaml)?;
|
||||||
@ -499,7 +499,7 @@ spec:
|
|||||||
service:
|
service:
|
||||||
name: {{ include "chart.fullname" $ }}
|
name: {{ include "chart.fullname" $ }}
|
||||||
port:
|
port:
|
||||||
name: http
|
number: 3000
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
@ -549,25 +549,25 @@ spec:
|
|||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
// The chart name is the file stem of the .tgz file
|
// 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 chart_file_name = packaged_chart_path.file_stem().unwrap().to_str().unwrap();
|
||||||
let oci_url = format!(
|
let oci_push_url = format!("oci://{}/{}", *REGISTRY_URL, *REGISTRY_PROJECT);
|
||||||
"oci://{}/{}/{}-chart",
|
let oci_pull_url = format!("{oci_push_url}/{}-chart", self.name);
|
||||||
*REGISTRY_URL, *REGISTRY_PROJECT, self.name
|
|
||||||
);
|
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"Pushing Helm chart {} to {}",
|
"Pushing Helm chart {} to {}",
|
||||||
packaged_chart_path.to_string_lossy(),
|
packaged_chart_path.to_string_lossy(),
|
||||||
oci_url
|
oci_push_url
|
||||||
);
|
);
|
||||||
|
|
||||||
let output = process::Command::new("helm")
|
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()?;
|
.output()?;
|
||||||
|
|
||||||
self.check_output(&output, "Pushing Helm chart failed")?;
|
self.check_output(&output, "Pushing Helm chart failed")?;
|
||||||
|
|
||||||
// The final URL includes the version tag, which is part of the file name
|
// The final URL includes the version tag, which is part of the file name
|
||||||
let version = chart_file_name.rsplit_once('-').unwrap().1;
|
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 serde::Serialize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::HARMONY_CONFIG_DIR,
|
config::HARMONY_DATA_DIR,
|
||||||
data::{Id, Version},
|
data::{Id, Version},
|
||||||
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
@ -22,7 +22,7 @@ pub struct K3DInstallationScore {
|
|||||||
impl Default for K3DInstallationScore {
|
impl Default for K3DInstallationScore {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
installation_path: HARMONY_CONFIG_DIR.join("k3d"),
|
installation_path: HARMONY_DATA_DIR.join("k3d"),
|
||||||
cluster_name: "harmony".to_string(),
|
cluster_name: "harmony".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user