From 7363871ffb9aa0033a1840b47bf75b7e4880d29e Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 28 Jan 2024 23:34:05 +0100 Subject: [PATCH] feat: with docker Signed-off-by: kjuulh --- crates/cuddle-ci/src/rust_service.rs | 2 + .../cuddle-ci/src/rust_service/docker_cli.rs | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 crates/cuddle-ci/src/rust_service/docker_cli.rs diff --git a/crates/cuddle-ci/src/rust_service.rs b/crates/cuddle-ci/src/rust_service.rs index 148dcbd..96aa5a9 100644 --- a/crates/cuddle-ci/src/rust_service.rs +++ b/crates/cuddle-ci/src/rust_service.rs @@ -418,6 +418,7 @@ mod cargo_binstall; mod cargo_clean; mod clap_sanity_test; mod docker_cache; +mod docker_cli; mod mold; mod sqlx; mod ssh_agent; @@ -430,6 +431,7 @@ pub mod extensions { pub use super::cargo_clean::*; pub use super::clap_sanity_test::*; pub use super::docker_cache::*; + pub use super::docker_cli::*; pub use super::mold::*; pub use super::sqlx::*; pub use super::ssh_agent::*; diff --git a/crates/cuddle-ci/src/rust_service/docker_cli.rs b/crates/cuddle-ci/src/rust_service/docker_cli.rs new file mode 100644 index 0000000..70dc077 --- /dev/null +++ b/crates/cuddle-ci/src/rust_service/docker_cli.rs @@ -0,0 +1,48 @@ +use std::sync::Arc; + +use async_trait::async_trait; +use dagger_sdk::{Container, ImageMediaTypes}; + +use crate::dagger_middleware::DaggerMiddleware; + +use super::RustService; + +pub struct DockerCli { + client: dagger_sdk::Query, +} + +impl DockerCli { + pub fn new(client: dagger_sdk::Query) -> Self { + Self { client } + } +} + +#[async_trait] +impl DaggerMiddleware for DockerCli { + async fn handle(&self, container: Container) -> eyre::Result { + let docker = self.client.container().from("docker:cli"); + + Ok(container + .with_file( + "/usr/local/bin/docker", + docker.file("/usr/local/bin/docker"), + ) + .with_directory("/certs", docker.directory("/certs"))) + } +} + +pub trait DockerCliExt { + fn with_docker_cli(&mut self) -> &mut Self { + self + } +} + +impl DockerCliExt for RustService { + fn with_docker_cli(&mut self) -> &mut Self { + self.with_stage(super::RustServiceStage::BeforePackage(Arc::new( + DockerCli::new(self.client.clone()), + ))); + + self + } +}