diff --git a/crates/cuddle-ci/src/drone_templater.rs b/crates/cuddle-ci/src/drone_templater.rs new file mode 100644 index 0000000..12c90d2 --- /dev/null +++ b/crates/cuddle-ci/src/drone_templater.rs @@ -0,0 +1,55 @@ +use std::path::PathBuf; + +const DRONE_TEMPLATER_IMAGE: &str = "kasperhermansen/drone-templater:main-1711758171"; + +use async_trait::async_trait; +use eyre::Context; + +use crate::MainAction; + +pub struct DroneTemplater { + client: dagger_sdk::Query, + template: PathBuf, +} + +impl DroneTemplater { + pub fn new(client: dagger_sdk::Query, template: impl Into) -> Self { + Self { + client: client.pipeline("drone-templater"), + template: template.into(), + } + } +} + +#[async_trait] +impl MainAction for DroneTemplater { + async fn execute_main(&self, _ctx: &mut crate::Context) -> eyre::Result<()> { + let src = self.client.host().directory(".cuddle/tmp/"); + + let drone_host = std::env::var("DRONE_HOST").context("DRONE_HOST is missing")?; + let drone_user = std::env::var("DRONE_USER").context("DRONE_USER is missing")?; + let drone_token = std::env::var("DRONE_TOKEN").context("DRONE_TOKEN is missing")?; + + let drone_token_secret = self.client.set_secret("DRONE_TOKEN", drone_token); + + self.client + .container() + .from(DRONE_TEMPLATER_IMAGE) + .with_directory("/src/templates", src) + .with_workdir("/src") + .with_env_variable("DRONE_HOST", drone_host) + .with_env_variable("DRONE_USER", drone_user) + .with_secret_variable("DRONE_TOKEN", drone_token_secret) + .with_exec(vec![ + "drone-templater", + "upload", + "--template", + &self.template.display().to_string(), + ]) + .sync() + .await + .context("failed to upload drone templates with error")?; + + Ok(()) + } +} diff --git a/crates/cuddle-ci/src/lib.rs b/crates/cuddle-ci/src/lib.rs index 7edc767..5a0d955 100644 --- a/crates/cuddle-ci/src/lib.rs +++ b/crates/cuddle-ci/src/lib.rs @@ -11,60 +11,4 @@ pub mod cuddle_please; pub mod cuddle_releaser; pub mod cuddle_x; pub mod dagger_middleware; -pub mod drone_templater { - use std::path::PathBuf; - - const DRONE_TEMPLATER_IMAGE: &str = "kasperhermansen/drone-templater:main-1711758171"; - - use async_trait::async_trait; - use eyre::Context; - - use crate::MainAction; - - pub struct DroneTemplater { - client: dagger_sdk::Query, - template: PathBuf, - } - - impl DroneTemplater { - pub fn new(client: dagger_sdk::Query, template: impl Into) -> Self { - Self { - client: client.pipeline("drone-templater"), - template: template.into(), - } - } - } - - #[async_trait] - impl MainAction for DroneTemplater { - async fn execute_main(&self, _ctx: &mut crate::Context) -> eyre::Result<()> { - let src = self.client.host().directory(".cuddle/tmp/"); - - let drone_host = std::env::var("DRONE_HOST").context("DRONE_HOST is missing")?; - let drone_user = std::env::var("DRONE_USER").context("DRONE_USER is missing")?; - let drone_token = std::env::var("DRONE_TOKEN").context("DRONE_TOKEN is missing")?; - - let drone_token_secret = self.client.set_secret("DRONE_TOKEN", drone_token); - - self.client - .container() - .from(DRONE_TEMPLATER_IMAGE) - .with_directory("/src/templates", src) - .with_workdir("/src") - .with_env_variable("DRONE_HOST", drone_host) - .with_env_variable("DRONE_USER", drone_user) - .with_secret_variable("DRONE_TOKEN", drone_token_secret) - .with_exec(vec![ - "drone-templater", - "upload", - "--template", - &self.template.display().to_string(), - ]) - .sync() - .await - .context("failed to upload drone templates with error")?; - - Ok(()) - } - } -} +pub mod drone_templater; diff --git a/crates/cuddle-ci/src/rust_service.rs b/crates/cuddle-ci/src/rust_service.rs index 5bb2f36..52a53af 100644 --- a/crates/cuddle-ci/src/rust_service.rs +++ b/crates/cuddle-ci/src/rust_service.rs @@ -43,7 +43,7 @@ pub struct RustService { impl From for RustService { fn from(value: dagger_sdk::Query) -> Self { Self { - client: value, + client: value.pipeline("rust-service"), base_image: None, final_image: None, stages: Vec::new(), @@ -168,7 +168,8 @@ impl RustService { } pub async fn build_base(&self) -> eyre::Result { - let rust_src = RustSource::new(self.client.clone()); + let client = self.client.pipeline("build-base"); + let rust_src = RustSource::new(client.pipeline("load-source")); let (src, dep_src) = rust_src .get_rust_src(Some(&self.get_src()), self.crates.clone()) @@ -177,7 +178,7 @@ impl RustService { let base_image = self .base_image .clone() - .unwrap_or(self.client.container().from("rustlang/rust:nightly")); + .unwrap_or(client.container().from("rustlang/rust:nightly")); let before_deps = self .stages @@ -209,7 +210,7 @@ impl RustService { .collect::>(); let image = self.run_stage(before_base, image).await?; - let cache = self.client.cache_volume("rust_target_cache"); + let cache = client.cache_volume("rust_target_cache"); let rust_prebuild = image .with_workdir("/mnt/src") @@ -244,7 +245,8 @@ impl RustService { } pub async fn build_release(&self) -> eyre::Result { - let base = self.build_base().await?; + let base = self.build_base().await?.pipeline("build-release"); + let client = self.client.pipeline("build-release"); let before_build = self .stages @@ -256,8 +258,6 @@ impl RustService { .collect::>(); let base = self.run_stage(before_build, base).await?; - //base.export("export.tar").await?; - let binary_build = base.with_exec(vec!["cargo", "build", "--release", "--bin", &self.bin_name]); @@ -274,7 +274,7 @@ impl RustService { let dest = self .final_image .clone() - .unwrap_or(self.client.container().from("debian:bookworm")); + .unwrap_or(client.container().from("debian:bookworm")); let before_package = self .stages @@ -305,7 +305,7 @@ impl RustService { } pub async fn build_test(&self) -> eyre::Result<()> { - let base = self.build_base().await?; + let base = self.build_base().await?.pipeline("build-test"); let before_build = self .stages @@ -358,7 +358,7 @@ impl RustServiceContext for Context { #[async_trait] impl MainAction for RustService { async fn execute_main(&self, ctx: &mut Context) -> eyre::Result<()> { - let container = self.build_release().await?; + let container = self.build_release().await?.pipeline("main"); let timestamp = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) .unwrap()