feat: add file
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-04-06 21:53:09 +02:00
parent 59748fb6e6
commit 48f142ef58
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
3 changed files with 174 additions and 74 deletions

View File

@ -13,6 +13,7 @@ pub struct CuddleFile {
pub struct CuddleComponents { pub struct CuddleComponents {
pub database: Option<CuddleDatabase>, pub database: Option<CuddleDatabase>,
pub assets: Option<CuddleAssets>, pub assets: Option<CuddleAssets>,
pub packages: Option<Packages>,
} }
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
@ -21,6 +22,17 @@ pub struct CuddleAssets {
pub clean: Option<bool>, pub clean: Option<bool>,
} }
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct Packages {
pub debian: DebianPackages,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct DebianPackages {
pub dev: Vec<String>,
pub release: Vec<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct CuddleAssetInclude { pub struct CuddleAssetInclude {
pub from: PathBuf, pub from: PathBuf,
@ -111,6 +123,13 @@ components:
- from: somewhere - from: somewhere
to: somewhere-else to: somewhere-else
packages:
debian:
dev:
- "capnp"
release:
- "capnp"
scripts: scripts:
render: render:
type: shell type: shell
@ -159,6 +178,12 @@ scripts:
}]), }]),
clean: None, clean: None,
}), }),
packages: Some(Packages {
debian: DebianPackages {
dev: vec!["capnp".into()],
release: vec!["capnp".into()],
},
}),
}), }),
}; };
@ -190,6 +215,49 @@ components:
components: Some(CuddleComponents { components: Some(CuddleComponents {
database: Some(CuddleDatabase::Default {}), database: Some(CuddleDatabase::Default {}),
assets: None, assets: None,
packages: None,
}),
};
pretty_assertions::assert_eq!(expected, res)
}
#[test]
fn cuddle_packages() {
let cuddle_file = r#"
base: "git@git.front.kjuulh.io:kjuulh/cuddle-base.git"
vars:
service: "infrastructure-example"
registry: kasperhermansen
components:
packages:
debian:
dev:
- "capnp"
release:
- "capnp"
"#;
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: None,
assets: None,
packages: Some(Packages {
debian: DebianPackages {
dev: vec!["capnp".into()],
release: vec!["capnp".into()],
},
}),
}), }),
}; };

View File

@ -1,6 +1,9 @@
use std::path::PathBuf; use std::path::PathBuf;
use crate::cuddle_file::{CuddleDatabase, CuddleFile}; use crate::{
cuddle_file::{CuddleDatabase, CuddleFile},
rust_service::extensions::AptExt,
};
use super::{ use super::{
extensions::{AssetsExt, CargoCleanExt, SqlxExt}, extensions::{AssetsExt, CargoCleanExt, SqlxExt},
@ -54,6 +57,28 @@ impl CuddleFileExt for RustService {
s = s.with_assets(mappings); s = s.with_assets(mappings);
} }
} }
if let Some(packages) = &components.packages {
s = s
.with_apt(
packages
.debian
.dev
.iter()
.map(|r| r.as_str())
.collect::<Vec<_>>()
.as_slice(),
)
.with_apt_release(
packages
.debian
.release
.iter()
.map(|r| r.as_str())
.collect::<Vec<_>>()
.as_slice(),
);
}
} }
s s

View File

@ -97,8 +97,7 @@ impl RustBuild {
let mut containers = Vec::new(); let mut containers = Vec::new();
for container_image in images { for container_image in images {
let container = let container = match &container_image {
match &container_image {
SlimImage::Debian { image, deps, .. } => { SlimImage::Debian { image, deps, .. } => {
let target = BuildTarget::from_target(&container_image); let target = BuildTarget::from_target(&container_image);
@ -125,7 +124,11 @@ impl RustBuild {
"-p", "-p",
bin_name, bin_name,
]) ])
.file(format!("target/{}/release/{}", target.to_string(), bin_name)); .file(format!(
"target/{}/release/{}",
target.to_string(),
bin_name
));
self.build_debian_image( self.build_debian_image(
bin, bin,
@ -163,7 +166,11 @@ impl RustBuild {
"-p", "-p",
bin_name, bin_name,
]) ])
.file(format!("target/{}/release/{}", target.to_string(), bin_name)); .file(format!(
"target/{}/release/{}",
target.to_string(),
bin_name
));
self.build_alpine_image( self.build_alpine_image(
bin, bin,