From 4e380b17c029d03a3af60d280a77d6bd48a180c5 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Fri, 1 Dec 2023 21:59:26 +0100 Subject: [PATCH] feat: set registry Signed-off-by: kjuulh --- .../src/rust_service/docker_cache.rs | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/cuddle-ci/src/rust_service/docker_cache.rs b/crates/cuddle-ci/src/rust_service/docker_cache.rs index af91c41..2def7b4 100644 --- a/crates/cuddle-ci/src/rust_service/docker_cache.rs +++ b/crates/cuddle-ci/src/rust_service/docker_cache.rs @@ -24,12 +24,30 @@ impl DockerCache { #[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?; + match ( + std::env::var("REGISTRY_CACHE_USERNAME"), + std::env::var("REGISTRY_CACHE_PASSWORD"), + ) { + (Ok(username), Ok(password)) => { + let url = format!("harbor.front.kjuulh.io/cache/{}:cache", self.image_name); + let secret = self.client.set_secret("REGISTRY_CACHE_PASSWORD", password); + + container + .with_registry_auth(&url, &username, secret) + .publish_opts( + &url, + dagger_sdk::ContainerPublishOpts { + forced_compression: Some(dagger_sdk::ImageLayerCompression::Gzip), + media_types: Some(dagger_sdk::ImageMediaTypes::OCIMediaTypes), + platform_variants: None, + }, + ) + .await?; + } + _ => { + eprintln!("failed to find REGISTRY_CACHE_USERNAME or REGISTRY_CACHE_PASSWORD"); + } + } Ok(container) }