feat: include pipeline
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
365b840fe9
commit
b9417747a8
55
crates/cuddle-ci/src/drone_templater.rs
Normal file
55
crates/cuddle-ci/src/drone_templater.rs
Normal file
@ -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<PathBuf>) -> 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(())
|
||||||
|
}
|
||||||
|
}
|
@ -11,60 +11,4 @@ pub mod cuddle_please;
|
|||||||
pub mod cuddle_releaser;
|
pub mod cuddle_releaser;
|
||||||
pub mod cuddle_x;
|
pub mod cuddle_x;
|
||||||
pub mod dagger_middleware;
|
pub mod dagger_middleware;
|
||||||
pub mod drone_templater {
|
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<PathBuf>) -> 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(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -43,7 +43,7 @@ pub struct RustService {
|
|||||||
impl From<dagger_sdk::Query> for RustService {
|
impl From<dagger_sdk::Query> for RustService {
|
||||||
fn from(value: dagger_sdk::Query) -> Self {
|
fn from(value: dagger_sdk::Query) -> Self {
|
||||||
Self {
|
Self {
|
||||||
client: value,
|
client: value.pipeline("rust-service"),
|
||||||
base_image: None,
|
base_image: None,
|
||||||
final_image: None,
|
final_image: None,
|
||||||
stages: Vec::new(),
|
stages: Vec::new(),
|
||||||
@ -168,7 +168,8 @@ impl RustService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn build_base(&self) -> eyre::Result<Container> {
|
pub async fn build_base(&self) -> eyre::Result<Container> {
|
||||||
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
|
let (src, dep_src) = rust_src
|
||||||
.get_rust_src(Some(&self.get_src()), self.crates.clone())
|
.get_rust_src(Some(&self.get_src()), self.crates.clone())
|
||||||
@ -177,7 +178,7 @@ impl RustService {
|
|||||||
let base_image = self
|
let base_image = self
|
||||||
.base_image
|
.base_image
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or(self.client.container().from("rustlang/rust:nightly"));
|
.unwrap_or(client.container().from("rustlang/rust:nightly"));
|
||||||
|
|
||||||
let before_deps = self
|
let before_deps = self
|
||||||
.stages
|
.stages
|
||||||
@ -209,7 +210,7 @@ impl RustService {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let image = self.run_stage(before_base, image).await?;
|
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
|
let rust_prebuild = image
|
||||||
.with_workdir("/mnt/src")
|
.with_workdir("/mnt/src")
|
||||||
@ -244,7 +245,8 @@ impl RustService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn build_release(&self) -> eyre::Result<Container> {
|
pub async fn build_release(&self) -> eyre::Result<Container> {
|
||||||
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
|
let before_build = self
|
||||||
.stages
|
.stages
|
||||||
@ -256,8 +258,6 @@ impl RustService {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let base = self.run_stage(before_build, base).await?;
|
let base = self.run_stage(before_build, base).await?;
|
||||||
|
|
||||||
//base.export("export.tar").await?;
|
|
||||||
|
|
||||||
let binary_build =
|
let binary_build =
|
||||||
base.with_exec(vec!["cargo", "build", "--release", "--bin", &self.bin_name]);
|
base.with_exec(vec!["cargo", "build", "--release", "--bin", &self.bin_name]);
|
||||||
|
|
||||||
@ -274,7 +274,7 @@ impl RustService {
|
|||||||
let dest = self
|
let dest = self
|
||||||
.final_image
|
.final_image
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or(self.client.container().from("debian:bookworm"));
|
.unwrap_or(client.container().from("debian:bookworm"));
|
||||||
|
|
||||||
let before_package = self
|
let before_package = self
|
||||||
.stages
|
.stages
|
||||||
@ -305,7 +305,7 @@ impl RustService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn build_test(&self) -> eyre::Result<()> {
|
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
|
let before_build = self
|
||||||
.stages
|
.stages
|
||||||
@ -358,7 +358,7 @@ impl RustServiceContext for Context {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl MainAction for RustService {
|
impl MainAction for RustService {
|
||||||
async fn execute_main(&self, ctx: &mut Context) -> eyre::Result<()> {
|
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()
|
let timestamp = std::time::SystemTime::now()
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
Loading…
Reference in New Issue
Block a user