From bda242422ddd930d86bff2e68e19e147bde47836 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Mon, 27 Nov 2023 20:11:49 +0100 Subject: [PATCH] feat: with arc Signed-off-by: kjuulh --- crates/cuddle-ci/src/dagger_middleware.rs | 4 +-- crates/cuddle-ci/src/rust_service.rs | 30 ++++--------------- crates/cuddle-ci/src/rust_service/apt.rs | 6 +++- .../src/rust_service/cargo_binstall.rs | 25 ++++++++-------- .../cuddle-ci/src/rust_service/cargo_clean.rs | 4 ++- .../src/rust_service/clap_sanity_test.rs | 8 +++-- crates/cuddle-ci/src/rust_service/mold.rs | 8 +++-- crates/cuddle-ci/src/rust_service/sqlx.rs | 4 ++- 8 files changed, 41 insertions(+), 48 deletions(-) diff --git a/crates/cuddle-ci/src/dagger_middleware.rs b/crates/cuddle-ci/src/dagger_middleware.rs index 826de75..2b24d4f 100644 --- a/crates/cuddle-ci/src/dagger_middleware.rs +++ b/crates/cuddle-ci/src/dagger_middleware.rs @@ -1,8 +1,8 @@ use async_trait::async_trait; use dagger_sdk::Container; -use std::{future::Future, pin::Pin}; +use std::{future::Future, pin::Pin, sync::Arc}; -pub type DynMiddleware = Box; +pub type DynMiddleware = Arc; #[async_trait] pub trait DaggerMiddleware { diff --git a/crates/cuddle-ci/src/rust_service.rs b/crates/cuddle-ci/src/rust_service.rs index 9c2c3fe..b858e29 100644 --- a/crates/cuddle-ci/src/rust_service.rs +++ b/crates/cuddle-ci/src/rust_service.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::{path::PathBuf, sync::Arc}; use async_trait::async_trait; use dagger_rust::source::RustSource; @@ -12,6 +12,7 @@ use crate::{ use self::architecture::{Architecture, Os}; +#[derive(Clone)] pub enum RustServiceStage { BeforeDeps(DynMiddleware), AfterDeps(DynMiddleware), @@ -25,6 +26,7 @@ pub enum RustServiceStage { AfterRelease(DynMiddleware), } +#[derive(Clone)] pub struct RustService { client: dagger_sdk::Query, base_image: Option, @@ -141,7 +143,7 @@ impl RustService { async fn run_stage( &self, - stages: impl IntoIterator>, + stages: impl IntoIterator>, container: Container, ) -> eyre::Result { let before_deps_stream = stream::iter(stages.into_iter().map(Ok)); @@ -317,29 +319,7 @@ impl MainAction for RustService { let container = self.build_release().await?; container - .publish(format!("docker.io/kjuulh/{}", self.bin_name)) - .await?; - - Ok(()) - } -} - -#[async_trait] -impl PullRequestAction for &mut RustService { - async fn execute_pull_request(&self) -> eyre::Result<()> { - self.build_test().await?; - - Ok(()) - } -} - -#[async_trait] -impl MainAction for &mut RustService { - async fn execute_main(&self) -> eyre::Result<()> { - let container = self.build_release().await?; - - container - .publish(format!("docker.io/kjuulh/{}", self.bin_name)) + .publish(format!("docker.io//{}", self.bin_name)) .await?; Ok(()) diff --git a/crates/cuddle-ci/src/rust_service/apt.rs b/crates/cuddle-ci/src/rust_service/apt.rs index 3fcbb47..ad10b60 100644 --- a/crates/cuddle-ci/src/rust_service/apt.rs +++ b/crates/cuddle-ci/src/rust_service/apt.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use async_trait::async_trait; use dagger_sdk::Container; @@ -47,6 +49,8 @@ pub trait AptExt { 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)))) + self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new( + Apt::new().extend(deps), + ))) } } diff --git a/crates/cuddle-ci/src/rust_service/cargo_binstall.rs b/crates/cuddle-ci/src/rust_service/cargo_binstall.rs index 5754a84..11e35de 100644 --- a/crates/cuddle-ci/src/rust_service/cargo_binstall.rs +++ b/crates/cuddle-ci/src/rust_service/cargo_binstall.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use async_trait::async_trait; use dagger_sdk::Container; @@ -62,15 +64,14 @@ impl CargoBInstall { #[async_trait] impl DaggerMiddleware for CargoBInstall { async fn handle(&self, container: Container) -> eyre::Result { - let c = - container - .with_exec(vec!["wget", &self.get_download_url()]) - .with_exec(vec!["tar", "-xvf", &self.get_archive()]) - .with_exec( - "mv cargo-binstall /usr/local/cargo/bin" - .split_whitespace() - .collect(), - ); + let c = container + .with_exec(vec!["wget", &self.get_download_url()]) + .with_exec(vec!["tar", "-xvf", &self.get_archive()]) + .with_exec( + "mv cargo-binstall /usr/local/cargo/bin" + .split_whitespace() + .collect(), + ); let c = self.crates.iter().cloned().fold(c, |acc, item| { acc.with_exec(vec!["cargo", "binstall", &item, "-y"]) @@ -98,8 +99,8 @@ impl CargoBInstallExt for RustService { ) -> &mut Self { let crates: Vec = crates.into_iter().map(|s| s.into()).collect(); - self.with_stage(super::RustServiceStage::BeforeDeps( - Box::new(CargoBInstall::new(self.get_arch(), self.get_os(), version, crates)) - )) + self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new( + CargoBInstall::new(self.get_arch(), self.get_os(), version, crates), + ))) } } diff --git a/crates/cuddle-ci/src/rust_service/cargo_clean.rs b/crates/cuddle-ci/src/rust_service/cargo_clean.rs index 7b25dd0..1b9cb68 100644 --- a/crates/cuddle-ci/src/rust_service/cargo_clean.rs +++ b/crates/cuddle-ci/src/rust_service/cargo_clean.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use async_trait::async_trait; use dagger_sdk::Container; @@ -28,7 +30,7 @@ pub trait CargoCleanExt { impl CargoCleanExt for RustService { fn with_cargo_clean(&mut self) -> &mut Self { - self.with_stage(super::RustServiceStage::BeforeBuild(Box::new( + self.with_stage(super::RustServiceStage::BeforeBuild(Arc::new( CargoClean::new(), ))); diff --git a/crates/cuddle-ci/src/rust_service/clap_sanity_test.rs b/crates/cuddle-ci/src/rust_service/clap_sanity_test.rs index 5e9ac60..42fd531 100644 --- a/crates/cuddle-ci/src/rust_service/clap_sanity_test.rs +++ b/crates/cuddle-ci/src/rust_service/clap_sanity_test.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use async_trait::async_trait; use dagger_sdk::Container; @@ -32,9 +34,9 @@ pub trait ClapSanityTestExt { impl ClapSanityTestExt for RustService { fn with_clap_sanity_test(&mut self) -> &mut Self { - self.with_stage( - super::RustServiceStage::AfterPackage(Box::new(ClapSanityTest::new(&self.bin_name))) - ); + self.with_stage(super::RustServiceStage::AfterPackage(Arc::new( + ClapSanityTest::new(&self.bin_name), + ))); self } diff --git a/crates/cuddle-ci/src/rust_service/mold.rs b/crates/cuddle-ci/src/rust_service/mold.rs index ae26ba8..105e135 100644 --- a/crates/cuddle-ci/src/rust_service/mold.rs +++ b/crates/cuddle-ci/src/rust_service/mold.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use async_trait::async_trait; use crate::dagger_middleware::DaggerMiddleware; @@ -95,8 +97,8 @@ pub trait MoldActionExt { impl MoldActionExt for RustService { fn with_mold(&mut self, version: impl Into) -> &mut Self { - self.with_stage(super::RustServiceStage::AfterDeps( - Box::new(MoldInstall::new(self.get_arch(), self.get_os(), version)) - )) + self.with_stage(super::RustServiceStage::AfterDeps(Arc::new( + MoldInstall::new(self.get_arch(), self.get_os(), version), + ))) } } diff --git a/crates/cuddle-ci/src/rust_service/sqlx.rs b/crates/cuddle-ci/src/rust_service/sqlx.rs index ea9c7d0..ebd4d0f 100644 --- a/crates/cuddle-ci/src/rust_service/sqlx.rs +++ b/crates/cuddle-ci/src/rust_service/sqlx.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use async_trait::async_trait; use dagger_sdk::Container; @@ -34,7 +36,7 @@ pub trait SqlxExt { impl SqlxExt for RustService { fn with_sqlx(&mut self) -> &mut Self { - self.with_stage(super::RustServiceStage::BeforeBuild(Box::new(Sqlx::new( + self.with_stage(super::RustServiceStage::BeforeBuild(Arc::new(Sqlx::new( self.client.clone(), ))));