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 database: Option<CuddleDatabase>,
pub assets: Option<CuddleAssets>,
pub packages: Option<Packages>,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
@ -21,6 +22,17 @@ pub struct CuddleAssets {
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)]
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()],
},
}),
}),
};

View File

@ -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::<Vec<_>>()
.as_slice(),
)
.with_apt_release(
packages
.debian
.release
.iter()
.map(|r| r.as_str())
.collect::<Vec<_>>()
.as_slice(),
);
}
}
s

View File

@ -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::<Vec<&str>>()
.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::<Vec<&str>>()
.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::<Vec<&str>>()
.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::<Vec<&str>>()
.as_slice(),
bin_name,
)
.await?
}
};
containers.push(container);
}