2024-03-30 14:33:36 +01:00
|
|
|
use std::{path::PathBuf, time::UNIX_EPOCH};
|
2024-03-30 02:26:08 +01:00
|
|
|
|
2024-03-30 14:25:00 +01:00
|
|
|
const DRONE_TEMPLATER_IMAGE: &str = "kasperhermansen/drone-templater:main-1711805042";
|
2024-03-30 02:26:08 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2024-03-30 14:33:36 +01:00
|
|
|
let now = std::time::SystemTime::now()
|
|
|
|
.duration_since(UNIX_EPOCH)
|
|
|
|
.context("failed to get system time")?;
|
|
|
|
|
2024-03-30 02:26:08 +01:00
|
|
|
self.client
|
|
|
|
.container()
|
|
|
|
.from(DRONE_TEMPLATER_IMAGE)
|
2024-03-30 14:33:36 +01:00
|
|
|
.with_exec(vec!["echo", &format!("{}", now.as_secs())])
|
2024-03-30 02:26:08 +01:00
|
|
|
.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(())
|
|
|
|
}
|
|
|
|
}
|