feat: add dagger bin
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 22:29:06 +02:00
parent 48f142ef58
commit 7d586337e9
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
2 changed files with 63 additions and 0 deletions

View File

@ -443,6 +443,7 @@ mod cargo_clean;
mod clap_sanity_test;
mod cuddle_cli;
mod cuddle_file;
mod dagger_bin;
mod docker_cache;
mod docker_cli;
mod kubectl;
@ -460,6 +461,7 @@ pub mod extensions {
pub use super::clap_sanity_test::*;
pub use super::cuddle_cli::*;
pub use super::cuddle_file::*;
pub use super::dagger_bin::*;
pub use super::docker_cache::*;
pub use super::docker_cli::*;
pub use super::kubectl::*;

View File

@ -0,0 +1,61 @@
use std::sync::Arc;
use async_trait::async_trait;
use dagger_sdk::{Container, ImageMediaTypes};
use crate::dagger_middleware::DaggerMiddleware;
use super::RustService;
pub struct DaggerBin {
client: dagger_sdk::Query,
version: String,
}
impl DaggerBin {
pub fn new(client: dagger_sdk::Query, version: impl Into<String>) -> Self {
Self {
client,
version: version.into(),
}
}
}
#[async_trait]
impl DaggerMiddleware for DaggerBin {
async fn handle(&self, container: Container) -> eyre::Result<Container> {
let install_script = self.client.http("https://dl.dagger.io/dagger/install.sh");
let dagger_bin = self
.client
.container()
.from("debian:bookworm")
.with_file_opts(
"/mnt/install.sh",
install_script,
dagger_sdk::ContainerWithFileOpts {
owner: None,
permissions: Some(755),
},
)
.with_env_variable("DAGGER_VERSION", self.version)
.with_exec(vec!["/mtn/install.sh"])
.file("/bin/dagger");
Some(container.with_file("/bin/dagger", dagger_bin))
}
}
pub trait DaggerBinExt {
fn with_dagger_bin(&mut self, dagger_version: impl Into<String>) -> &mut Self;
}
impl DaggerBinExt for RustService {
fn with_dagger_bin(&mut self, dagger_version: impl Into<String>) -> &mut Self {
self.with_stage(super::RustServiceStage::AfterPackage(Arc::new(
DaggerBin::new(self.client.clone(), dagger_version.into()),
)));
self
}
}