diff --git a/crates/cuddle-ci/src/cuddle_file.rs b/crates/cuddle-ci/src/cuddle_file.rs index 6400b3d..86304a5 100644 --- a/crates/cuddle-ci/src/cuddle_file.rs +++ b/crates/cuddle-ci/src/cuddle_file.rs @@ -13,6 +13,7 @@ pub struct CuddleFile { pub struct CuddleComponents { pub database: Option, pub assets: Option, + pub packages: Option, } #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] @@ -21,6 +22,17 @@ pub struct CuddleAssets { pub clean: Option, } +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +pub struct Packages { + pub debian: DebianPackages, +} + +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] +pub struct DebianPackages { + pub dev: Vec, + pub release: Vec, +} + #[derive(Clone, Debug, Deserialize, Serialize, PartialEq)] pub struct CuddleAssetInclude { pub from: PathBuf, @@ -111,6 +123,13 @@ components: - from: somewhere to: somewhere-else + packages: + debian: + dev: + - "capnp" + release: + - "capnp" + scripts: render: type: shell @@ -159,6 +178,12 @@ scripts: }]), clean: None, }), + packages: Some(Packages { + debian: DebianPackages { + dev: vec!["capnp".into()], + release: vec!["capnp".into()], + }, + }), }), }; @@ -190,6 +215,49 @@ components: components: Some(CuddleComponents { database: Some(CuddleDatabase::Default {}), 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()], + }, + }), }), }; diff --git a/crates/cuddle-ci/src/rust_service/cuddle_file.rs b/crates/cuddle-ci/src/rust_service/cuddle_file.rs index e60ef71..02f22b7 100644 --- a/crates/cuddle-ci/src/rust_service/cuddle_file.rs +++ b/crates/cuddle-ci/src/rust_service/cuddle_file.rs @@ -1,6 +1,9 @@ use std::path::PathBuf; -use crate::cuddle_file::{CuddleDatabase, CuddleFile}; +use crate::{ + cuddle_file::{CuddleDatabase, CuddleFile}, + rust_service::extensions::AptExt, +}; use super::{ extensions::{AssetsExt, CargoCleanExt, SqlxExt}, @@ -54,6 +57,28 @@ impl CuddleFileExt for RustService { 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::>() + .as_slice(), + ) + .with_apt_release( + packages + .debian + .release + .iter() + .map(|r| r.as_str()) + .collect::>() + .as_slice(), + ); + } } s diff --git a/crates/dagger-rust/src/build.rs b/crates/dagger-rust/src/build.rs index cf65210..13908a6 100644 --- a/crates/dagger-rust/src/build.rs +++ b/crates/dagger-rust/src/build.rs @@ -97,87 +97,94 @@ impl RustBuild { let mut containers = Vec::new(); for container_image in images { - let container = - match &container_image { - SlimImage::Debian { image, deps, .. } => { - let target = BuildTarget::from_target(&container_image); + let container = match &container_image { + SlimImage::Debian { image, deps, .. } => { + let target = BuildTarget::from_target(&container_image); - let build_container = self - .build( - source_path.clone(), - &rust_version, - BuildTarget::from_target(&container_image), - BuildProfile::Release, - crates, - extra_deps, - ) - .await?; - - let bin = build_container - .with_env_variable("SQLX_OFFLINE", "true") - .with_exec(vec!["cargo", "clean"]) - .with_exec(vec![ - "cargo", - "build", - "--target", - &target.to_string(), - "--release", - "-p", - bin_name, - ]) - .file(format!("target/{}/release/{}", target.to_string(), bin_name)); - - self.build_debian_image( - bin, - image, + let build_container = self + .build( + source_path.clone(), + &rust_version, BuildTarget::from_target(&container_image), - deps.iter() - .map(|d| d.as_str()) - .collect::>() - .as_slice(), - bin_name, + BuildProfile::Release, + crates, + extra_deps, ) - .await? - } - SlimImage::Alpine { image, deps, .. } => { - let target = BuildTarget::from_target(&container_image); + .await?; - let build_container = self - .build( - source_path.clone(), - &rust_version, - BuildTarget::from_target(&container_image), - BuildProfile::Release, - crates, - extra_deps, - ) - .await?; + let bin = build_container + .with_env_variable("SQLX_OFFLINE", "true") + .with_exec(vec!["cargo", "clean"]) + .with_exec(vec![ + "cargo", + "build", + "--target", + &target.to_string(), + "--release", + "-p", + bin_name, + ]) + .file(format!( + "target/{}/release/{}", + target.to_string(), + bin_name + )); - let bin = build_container - .with_exec(vec![ - "cargo", - "build", - "--target", - &target.to_string(), - "--release", - "-p", - bin_name, - ]) - .file(format!("target/{}/release/{}", target.to_string(), bin_name)); + self.build_debian_image( + bin, + image, + BuildTarget::from_target(&container_image), + deps.iter() + .map(|d| d.as_str()) + .collect::>() + .as_slice(), + bin_name, + ) + .await? + } + SlimImage::Alpine { image, deps, .. } => { + let target = BuildTarget::from_target(&container_image); - self.build_alpine_image( - bin, - image, + let build_container = self + .build( + source_path.clone(), + &rust_version, BuildTarget::from_target(&container_image), - deps.iter() - .map(|d| d.as_str()) - .collect::>() - .as_slice(), - bin_name, + BuildProfile::Release, + crates, + extra_deps, ) - .await? - } - }; + .await?; + + let bin = build_container + .with_exec(vec![ + "cargo", + "build", + "--target", + &target.to_string(), + "--release", + "-p", + bin_name, + ]) + .file(format!( + "target/{}/release/{}", + target.to_string(), + bin_name + )); + + self.build_alpine_image( + bin, + image, + BuildTarget::from_target(&container_image), + deps.iter() + .map(|d| d.as_str()) + .collect::>() + .as_slice(), + bin_name, + ) + .await? + } + }; containers.push(container); }