From 5378b5f537475afbc0fca8264f10e1b76da06a0d Mon Sep 17 00:00:00 2001 From: kjuulh Date: Sun, 28 Jan 2024 19:20:38 +0100 Subject: [PATCH] feat: add releaser Signed-off-by: kjuulh --- crates/cuddle-ci/src/lib.rs | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/crates/cuddle-ci/src/lib.rs b/crates/cuddle-ci/src/lib.rs index d0ae2d3..e40d12a 100644 --- a/crates/cuddle-ci/src/lib.rs +++ b/crates/cuddle-ci/src/lib.rs @@ -7,3 +7,61 @@ pub mod dagger_middleware; pub mod node_service; pub mod rust_lib; pub mod rust_service; + +pub mod cuddle_releaser { + use async_trait::async_trait; + + use crate::{rust_service::RustService, MainAction}; + + pub struct CuddleReleaser { + client: dagger_sdk::Query, + options: CuddleReleaserOptions, + } + + pub struct CuddleReleaserOptions { + upstream: String, + folder: String, + cluster: String, + namespace: String, + app: String, + } + + impl CuddleReleaser { + pub async fn new( + client: dagger_sdk::Query, + options: CuddleReleaserOptions, + ) -> eyre::Result { + Ok(Self { client, options }) + } + } + + #[async_trait] + impl MainAction for CuddleReleaser { + async fn execute_main(&self) -> eyre::Result<()> { + let client = self.client; + + let cuddle_releaser_image = "docker.io/kasperhermansen:cuddle-releaser:main-1706438736"; + + let folder = client.host().directory(self.options.folder); + + let cuddle_releaser = client + .container() + .from(cuddle_releaser_image) + .with_mounted_directory("/mnt/templates", folder); + + cuddle_releaser + .with_exec(vec![ + "cuddle-releaser", + "release", + &format!("--upstream={}", self.options.upstream), + &format!("--folder={}", "/mnt/templates"), + &format!("--cluster={}", self.options.cluster), + &format!("--namespace={}", self.options.namespace), + &format!("--app={}", self.options.app), + ]) + .sync()?; + + Ok(()) + } + } +}