feat: with full support for rust services
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
52
crates/cuddle-ci/src/rust_service/apt.rs
Normal file
52
crates/cuddle-ci/src/rust_service/apt.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use async_trait::async_trait;
|
||||
use dagger_sdk::Container;
|
||||
|
||||
use crate::dagger_middleware::DaggerMiddleware;
|
||||
|
||||
use super::RustService;
|
||||
|
||||
pub struct Apt {
|
||||
deps: Vec<String>,
|
||||
}
|
||||
|
||||
impl Apt {
|
||||
pub fn new() -> Self {
|
||||
Self { deps: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn add(mut self, dep_name: impl Into<String>) -> Self {
|
||||
self.deps.push(dep_name.into());
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn extend(mut self, deps: &[&str]) -> Self {
|
||||
self.deps.extend(deps.iter().map(|s| s.to_string()));
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl DaggerMiddleware for Apt {
|
||||
async fn handle(&self, container: Container) -> eyre::Result<Container> {
|
||||
let mut deps = vec!["apt", "install", "-y"];
|
||||
deps.extend(self.deps.iter().map(|s| s.as_str()));
|
||||
|
||||
let c = container.with_exec(vec!["apt", "update"]).with_exec(deps);
|
||||
|
||||
Ok(c)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AptExt {
|
||||
fn with_apt(&mut self, deps: &[&str]) -> &mut Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AptExt for RustService {
|
||||
fn with_apt(&mut self, deps: &[&str]) -> &mut Self {
|
||||
self.with_stage(super::RustServiceStage::BeforeDeps(Box::new(Apt::new().extend(deps))))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user