2023-11-27 20:11:49 +01:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
use async_trait::async_trait;
|
|
|
|
use dagger_sdk::Container;
|
|
|
|
|
2023-12-28 14:17:31 +01:00
|
|
|
use crate::{dagger_middleware::DaggerMiddleware, leptos_service::LeptosService};
|
2023-11-26 22:19:34 +01:00
|
|
|
|
|
|
|
use super::RustService;
|
|
|
|
|
|
|
|
pub struct Apt {
|
|
|
|
deps: Vec<String>,
|
|
|
|
}
|
|
|
|
|
2024-02-11 14:13:27 +01:00
|
|
|
impl Default for Apt {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
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
|
|
|
|
}
|
2024-01-28 23:24:33 +01:00
|
|
|
|
|
|
|
fn with_apt_release(&mut self, deps: &[&str]) -> &mut Self {
|
|
|
|
self
|
|
|
|
}
|
2023-11-26 22:19:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl AptExt for RustService {
|
|
|
|
fn with_apt(&mut self, deps: &[&str]) -> &mut Self {
|
2023-11-27 20:11:49 +01:00
|
|
|
self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new(
|
|
|
|
Apt::new().extend(deps),
|
|
|
|
)))
|
2023-11-26 22:19:34 +01:00
|
|
|
}
|
2024-01-28 23:24:33 +01:00
|
|
|
|
|
|
|
fn with_apt_release(&mut self, deps: &[&str]) -> &mut Self {
|
|
|
|
self.with_stage(super::RustServiceStage::BeforePackage(Arc::new(
|
|
|
|
Apt::new().extend(deps),
|
|
|
|
)))
|
|
|
|
}
|
2023-11-26 22:19:34 +01:00
|
|
|
}
|
2023-12-28 14:17:31 +01:00
|
|
|
|
|
|
|
impl AptExt for LeptosService {
|
|
|
|
fn with_apt(&mut self, deps: &[&str]) -> &mut Self {
|
|
|
|
self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new(
|
|
|
|
Apt::new().extend(deps),
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
}
|