feat: handle for cuddle_file
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
99bc420f71
commit
924bcf8c8c
23
Cargo.lock
generated
23
Cargo.lock
generated
@ -358,6 +358,7 @@ dependencies = [
|
|||||||
"dagger-sdk",
|
"dagger-sdk",
|
||||||
"eyre",
|
"eyre",
|
||||||
"futures",
|
"futures",
|
||||||
|
"pretty_assertions",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
@ -498,6 +499,12 @@ dependencies = [
|
|||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "diff"
|
||||||
|
version = "0.1.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
@ -1247,6 +1254,16 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pretty_assertions"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66"
|
||||||
|
dependencies = [
|
||||||
|
"diff",
|
||||||
|
"yansi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.79"
|
version = "1.0.79"
|
||||||
@ -2253,3 +2270,9 @@ dependencies = [
|
|||||||
"linux-raw-sys",
|
"linux-raw-sys",
|
||||||
"rustix",
|
"rustix",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "yansi"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
|
||||||
|
@ -27,4 +27,10 @@ chrono = {version = "0.4.37"}
|
|||||||
toml = "0.8.12"
|
toml = "0.8.12"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
pretty_assertions = "1.4.0"
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
dagger = []
|
||||||
|
integration = []
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::{collections::BTreeMap, path::PathBuf};
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -6,6 +6,33 @@ use serde::{Deserialize, Serialize};
|
|||||||
pub struct CuddleFile {
|
pub struct CuddleFile {
|
||||||
pub vars: CuddleVars,
|
pub vars: CuddleVars,
|
||||||
pub deployment: Option<CuddleDeployment>,
|
pub deployment: Option<CuddleDeployment>,
|
||||||
|
pub components: Option<CuddleComponents>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
|
pub struct CuddleComponents {
|
||||||
|
pub database: Option<CuddleDatabase>,
|
||||||
|
pub assets: Option<CuddleAssets>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
|
pub struct CuddleAssets {
|
||||||
|
pub volumes: Option<Vec<CuddleAssetInclude>>,
|
||||||
|
pub clean: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
|
pub struct CuddleAssetInclude {
|
||||||
|
pub from: PathBuf,
|
||||||
|
pub to: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum CuddleDatabase {
|
||||||
|
Enabled(bool),
|
||||||
|
Default {},
|
||||||
|
Values { migrations: PathBuf },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
@ -54,13 +81,7 @@ impl CuddleFile {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use std::collections::BTreeMap;
|
use super::*;
|
||||||
|
|
||||||
use crate::cuddle_file::{
|
|
||||||
CuddleCluster, CuddleClusters, CuddleDeploymentCluster, CuddleDeploymentEnv, CuddleVars,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::CuddleFile;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_file() {
|
fn parse_file() {
|
||||||
@ -82,6 +103,13 @@ deployment:
|
|||||||
prod:
|
prod:
|
||||||
clusters:
|
clusters:
|
||||||
- clank_prod
|
- clank_prod
|
||||||
|
components:
|
||||||
|
database: true
|
||||||
|
|
||||||
|
assets:
|
||||||
|
volumes:
|
||||||
|
- from: somewhere
|
||||||
|
to: somewhere-else
|
||||||
|
|
||||||
scripts:
|
scripts:
|
||||||
render:
|
render:
|
||||||
@ -119,11 +147,52 @@ scripts:
|
|||||||
clusters: Some(CuddleClusters(clusters)),
|
clusters: Some(CuddleClusters(clusters)),
|
||||||
},
|
},
|
||||||
deployment: Some(crate::cuddle_file::CuddleDeployment {
|
deployment: Some(crate::cuddle_file::CuddleDeployment {
|
||||||
registry: "git@git.front.kjuulh.io:kjuulh/clank-cluster".into(),
|
registry: "git@git.front.kjuulh.io:kjuulh/clank-clusters".into(),
|
||||||
env: CuddleDeploymentEnv(deployment),
|
env: CuddleDeploymentEnv(deployment),
|
||||||
}),
|
}),
|
||||||
|
components: Some(CuddleComponents {
|
||||||
|
database: Some(CuddleDatabase::Enabled(true)),
|
||||||
|
assets: Some(CuddleAssets {
|
||||||
|
volumes: Some(vec![CuddleAssetInclude {
|
||||||
|
from: "somewhere".into(),
|
||||||
|
to: "somewhere-else".into(),
|
||||||
|
}]),
|
||||||
|
clean: None,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(expected, res)
|
pretty_assertions::assert_eq!(expected, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cuddle_database_default() {
|
||||||
|
let cuddle_file = r#"
|
||||||
|
base: "git@git.front.kjuulh.io:kjuulh/cuddle-base.git"
|
||||||
|
|
||||||
|
vars:
|
||||||
|
service: "infrastructure-example"
|
||||||
|
registry: kasperhermansen
|
||||||
|
|
||||||
|
components:
|
||||||
|
database: {}
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let res = CuddleFile::parse_cuddle_file(cuddle_file).expect("to parse file");
|
||||||
|
|
||||||
|
let expected = CuddleFile {
|
||||||
|
vars: CuddleVars {
|
||||||
|
service: "infrastructure-example".into(),
|
||||||
|
registry: "kasperhermansen".into(),
|
||||||
|
clusters: None,
|
||||||
|
},
|
||||||
|
deployment: None,
|
||||||
|
components: Some(CuddleComponents {
|
||||||
|
database: Some(CuddleDatabase::Default {}),
|
||||||
|
assets: None,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
pretty_assertions::assert_eq!(expected, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -442,6 +442,7 @@ mod cargo_binstall;
|
|||||||
mod cargo_clean;
|
mod cargo_clean;
|
||||||
mod clap_sanity_test;
|
mod clap_sanity_test;
|
||||||
mod cuddle_cli;
|
mod cuddle_cli;
|
||||||
|
mod cuddle_file;
|
||||||
mod docker_cache;
|
mod docker_cache;
|
||||||
mod docker_cli;
|
mod docker_cli;
|
||||||
mod kubectl;
|
mod kubectl;
|
||||||
@ -458,6 +459,7 @@ pub mod extensions {
|
|||||||
pub use super::cargo_clean::*;
|
pub use super::cargo_clean::*;
|
||||||
pub use super::clap_sanity_test::*;
|
pub use super::clap_sanity_test::*;
|
||||||
pub use super::cuddle_cli::*;
|
pub use super::cuddle_cli::*;
|
||||||
|
pub use super::cuddle_file::*;
|
||||||
pub use super::docker_cache::*;
|
pub use super::docker_cache::*;
|
||||||
pub use super::docker_cli::*;
|
pub use super::docker_cli::*;
|
||||||
pub use super::kubectl::*;
|
pub use super::kubectl::*;
|
||||||
@ -480,6 +482,7 @@ mod test {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
#[cfg(any(feature = "dagger", feature = "integration"))]
|
||||||
async fn test_can_build_rust() -> eyre::Result<()> {
|
async fn test_can_build_rust() -> eyre::Result<()> {
|
||||||
let client = dagger_sdk::connect().await?;
|
let client = dagger_sdk::connect().await?;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::{path::PathBuf, sync::Arc};
|
use std::{path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dagger_sdk::{Container};
|
use dagger_sdk::Container;
|
||||||
|
|
||||||
use crate::{dagger_middleware::DaggerMiddleware, leptos_service::LeptosService};
|
use crate::{dagger_middleware::DaggerMiddleware, leptos_service::LeptosService};
|
||||||
|
|
||||||
|
61
crates/cuddle-ci/src/rust_service/cuddle_file.rs
Normal file
61
crates/cuddle-ci/src/rust_service/cuddle_file.rs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use crate::cuddle_file::{CuddleDatabase, CuddleFile};
|
||||||
|
|
||||||
|
use super::{
|
||||||
|
extensions::{AssetsExt, CargoCleanExt, SqlxExt},
|
||||||
|
RustService,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct CuddleFileAction {}
|
||||||
|
|
||||||
|
impl CuddleFileAction {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait CuddleFileExt {
|
||||||
|
fn with_cuddle_file(&mut self, cuddle_file: &CuddleFile) -> &mut Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CuddleFileExt for RustService {
|
||||||
|
fn with_cuddle_file(&mut self, cuddle_file: &CuddleFile) -> &mut Self {
|
||||||
|
let mut s = self
|
||||||
|
.with_bin_name(&cuddle_file.vars.service)
|
||||||
|
.with_deployment(false);
|
||||||
|
|
||||||
|
if let Some(components) = &cuddle_file.components {
|
||||||
|
s = if let Some(database) = &components.database {
|
||||||
|
match database {
|
||||||
|
CuddleDatabase::Enabled(true) => s.with_sqlx().with_sqlx_migrations(
|
||||||
|
PathBuf::from("crates")
|
||||||
|
.join(&cuddle_file.vars.service)
|
||||||
|
.join("migrations/crdb"),
|
||||||
|
),
|
||||||
|
CuddleDatabase::Values { migrations } => {
|
||||||
|
s.with_sqlx().with_sqlx_migrations(migrations)
|
||||||
|
}
|
||||||
|
CuddleDatabase::Enabled(false) | CuddleDatabase::Default {} => s,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
s
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(assets) = &components.assets {
|
||||||
|
if let Some(true) = assets.clean {
|
||||||
|
s = s.with_cargo_clean()
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(volumes) = &assets.volumes {
|
||||||
|
let mappings = volumes.iter().cloned().map(|val| (val.from, val.to));
|
||||||
|
|
||||||
|
s = s.with_assets(mappings);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user