feat: with docker cache
Some checks failed
continuous-integration/drone/push Build is failing

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-12-01 21:41:13 +01:00
parent 94efc99d05
commit bcdfaf2b2d
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394
2 changed files with 54 additions and 0 deletions

View File

@ -407,6 +407,7 @@ mod assets;
mod cargo_binstall;
mod cargo_clean;
mod clap_sanity_test;
mod docker_cache;
mod mold;
mod sqlx;
@ -417,6 +418,7 @@ pub mod extensions {
pub use super::cargo_binstall::*;
pub use super::cargo_clean::*;
pub use super::clap_sanity_test::*;
pub use super::docker_cache::*;
pub use super::mold::*;
pub use super::sqlx::*;
}

View File

@ -0,0 +1,52 @@
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<String>) -> Self {
Self {
client,
image_name: image_name.into(),
}
}
}
#[async_trait]
impl DaggerMiddleware for DockerCache {
async fn handle(&self, container: Container) -> eyre::Result<Container> {
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
}
}