feat: fix cuddle_releaser
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2024-03-30 21:03:37 +01:00
parent f4e7ced9d8
commit a6dab9a178
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
3 changed files with 54 additions and 50 deletions

View File

@ -13,7 +13,7 @@ pub struct CuddleVars {
pub service: String,
pub registry: String,
pub clusters: CuddleClusters,
pub clusters: Option<CuddleClusters>,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
@ -116,7 +116,7 @@ scripts:
vars: CuddleVars {
service: "infrastructure-example".into(),
registry: "kasperhermansen".into(),
clusters: CuddleClusters(clusters),
clusters: Some(CuddleClusters(clusters)),
},
deployment: Some(crate::cuddle_file::CuddleDeployment {
registry: "git@git.front.kjuulh.io:kjuulh/clank-cluster".into(),

View File

@ -1,3 +1,5 @@
use std::fmt::Display;
use async_trait::async_trait;
use eyre::Context;
@ -23,11 +25,11 @@ pub enum CuddleEnv {
Dev,
}
impl ToString for CuddleEnv {
fn to_string(&self) -> String {
impl Display for CuddleEnv {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CuddleEnv::Prod => "prod".into(),
CuddleEnv::Dev => "dev".into(),
CuddleEnv::Prod => f.write_str("prod"),
CuddleEnv::Dev => f.write_str("dev"),
}
}
}
@ -83,55 +85,57 @@ impl CuddleReleaser {
None => return Ok(()),
};
let cluster = match self.cuddle_file.vars.clusters.0.get(chosen_cluster) {
Some(c) => c,
None => eyre::bail!("no cluster found for: {}", chosen_cluster),
};
if let Some(clusters) = &self.cuddle_file.vars.clusters {
let cluster = match clusters.0.get(chosen_cluster) {
Some(c) => c,
None => eyre::bail!("no cluster found for: {}", chosen_cluster),
};
let options = CuddleReleaserOptions {
cluster: chosen_cluster.clone(),
namespace: cluster.namespace.clone(),
app: self.cuddle_file.vars.service.clone(),
upstream: self
.cuddle_file
.deployment
.as_ref()
.unwrap()
.registry
.clone(),
};
let options = CuddleReleaserOptions {
cluster: chosen_cluster.clone(),
namespace: cluster.namespace.clone(),
app: self.cuddle_file.vars.service.clone(),
upstream: self
.cuddle_file
.deployment
.as_ref()
.unwrap()
.registry
.clone(),
};
let cuddle_releaser_image = "docker.io/kasperhermansen/cuddle-releaser:main-1706726858";
let cuddle_releaser_image = "docker.io/kasperhermansen/cuddle-releaser:main-1706726858";
let folder = client.host().directory(&self.folder);
let folder = client.host().directory(&self.folder);
let ssh_sock = std::env::var("SSH_AUTH_SOCK").context("SSH_AUTH_SOCK not set")?;
let ssh_sock = std::env::var("SSH_AUTH_SOCK").context("SSH_AUTH_SOCK not set")?;
let cuddle_releaser = client
.container()
.from(cuddle_releaser_image)
.with_env_variable("RUST_LOG", "trace")
.with_directory("/mnt/templates", folder)
.with_unix_socket(
ssh_sock.clone(),
client.host().unix_socket(ssh_sock.clone()),
);
let cuddle_releaser = client
.container()
.from(cuddle_releaser_image)
.with_env_variable("RUST_LOG", "trace")
.with_directory("/mnt/templates", folder)
.with_unix_socket(
ssh_sock.clone(),
client.host().unix_socket(ssh_sock.clone()),
);
let time = chrono::Local::now();
let time = chrono::Local::now();
cuddle_releaser
.with_exec(vec!["echo", &time.to_rfc3339()])
.with_exec(vec![
"cuddle-releaser",
"release",
&format!("--upstream={}", options.upstream),
&format!("--folder={}", "/mnt/templates/k8s"),
&format!("--cluster={}", options.cluster),
&format!("--namespace={}", options.namespace),
&format!("--app={}", options.app),
])
.sync()
.await?;
cuddle_releaser
.with_exec(vec!["echo", &time.to_rfc3339()])
.with_exec(vec![
"cuddle-releaser",
"release",
&format!("--upstream={}", options.upstream),
&format!("--folder={}", "/mnt/templates/k8s"),
&format!("--cluster={}", options.cluster),
&format!("--namespace={}", options.namespace),
&format!("--app={}", options.app),
])
.sync()
.await?;
}
Ok(())
}

View File

@ -1,9 +1,9 @@
use std::{path::PathBuf};
use std::path::PathBuf;
use async_trait::async_trait;
use dagger_rust::source::RustSource;
use dagger_sdk::Container;
use futures::{StreamExt};
use futures::StreamExt;
use crate::{
cli,