Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
59748fb6e6
commit
48f142ef58
@ -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()],
|
||||||
|
},
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -97,87 +97,94 @@ 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);
|
|
||||||
|
|
||||||
let build_container = self
|
let build_container = self
|
||||||
.build(
|
.build(
|
||||||
source_path.clone(),
|
source_path.clone(),
|
||||||
&rust_version,
|
&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,
|
|
||||||
BuildTarget::from_target(&container_image),
|
BuildTarget::from_target(&container_image),
|
||||||
deps.iter()
|
BuildProfile::Release,
|
||||||
.map(|d| d.as_str())
|
crates,
|
||||||
.collect::<Vec<&str>>()
|
extra_deps,
|
||||||
.as_slice(),
|
|
||||||
bin_name,
|
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
}
|
|
||||||
SlimImage::Alpine { image, deps, .. } => {
|
|
||||||
let target = BuildTarget::from_target(&container_image);
|
|
||||||
|
|
||||||
let build_container = self
|
let bin = build_container
|
||||||
.build(
|
.with_env_variable("SQLX_OFFLINE", "true")
|
||||||
source_path.clone(),
|
.with_exec(vec!["cargo", "clean"])
|
||||||
&rust_version,
|
.with_exec(vec![
|
||||||
BuildTarget::from_target(&container_image),
|
"cargo",
|
||||||
BuildProfile::Release,
|
"build",
|
||||||
crates,
|
"--target",
|
||||||
extra_deps,
|
&target.to_string(),
|
||||||
)
|
"--release",
|
||||||
.await?;
|
"-p",
|
||||||
|
bin_name,
|
||||||
|
])
|
||||||
|
.file(format!(
|
||||||
|
"target/{}/release/{}",
|
||||||
|
target.to_string(),
|
||||||
|
bin_name
|
||||||
|
));
|
||||||
|
|
||||||
let bin = build_container
|
self.build_debian_image(
|
||||||
.with_exec(vec![
|
bin,
|
||||||
"cargo",
|
image,
|
||||||
"build",
|
BuildTarget::from_target(&container_image),
|
||||||
"--target",
|
deps.iter()
|
||||||
&target.to_string(),
|
.map(|d| d.as_str())
|
||||||
"--release",
|
.collect::<Vec<&str>>()
|
||||||
"-p",
|
.as_slice(),
|
||||||
bin_name,
|
bin_name,
|
||||||
])
|
)
|
||||||
.file(format!("target/{}/release/{}", target.to_string(), bin_name));
|
.await?
|
||||||
|
}
|
||||||
|
SlimImage::Alpine { image, deps, .. } => {
|
||||||
|
let target = BuildTarget::from_target(&container_image);
|
||||||
|
|
||||||
self.build_alpine_image(
|
let build_container = self
|
||||||
bin,
|
.build(
|
||||||
image,
|
source_path.clone(),
|
||||||
|
&rust_version,
|
||||||
BuildTarget::from_target(&container_image),
|
BuildTarget::from_target(&container_image),
|
||||||
deps.iter()
|
BuildProfile::Release,
|
||||||
.map(|d| d.as_str())
|
crates,
|
||||||
.collect::<Vec<&str>>()
|
extra_deps,
|
||||||
.as_slice(),
|
|
||||||
bin_name,
|
|
||||||
)
|
)
|
||||||
.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);
|
containers.push(container);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user