use std::sync::Arc; use async_trait::async_trait; use dagger_sdk::Container; use crate::dagger_middleware::DaggerMiddleware; use super::RustService; pub struct DockerCache { client: dagger_sdk::Query, image_name: String, } impl DockerCache { pub fn new(client: dagger_sdk::Query, image_name: impl Into) -> Self { Self { client, image_name: image_name.into(), } } } #[async_trait] impl DaggerMiddleware for DockerCache { async fn handle(&self, container: Container) -> eyre::Result { container .publish(format!( "harbor.front.kjuulh.io/cache/{}:cache", self.image_name )) .await?; Ok(container) } } pub trait DockerCacheExt { fn with_docker_cache(&mut self) -> &mut Self { self } } impl DockerCacheExt for RustService { fn with_docker_cache(&mut self) -> &mut Self { self.with_stage(super::RustServiceStage::AfterRelease(Arc::new( DockerCache::new(self.client.clone(), self.bin_name.clone()), ))); self } }