2023-11-25 23:14:38 +01:00
|
|
|
use async_trait::async_trait;
|
|
|
|
use dagger_sdk::Container;
|
|
|
|
|
|
|
|
use crate::{dagger_middleware::DaggerMiddleware, MainAction, PullRequestAction};
|
|
|
|
|
|
|
|
pub type DynMiddleware = Box<dyn DaggerMiddleware + Send + Sync>;
|
|
|
|
|
|
|
|
pub enum RustServiceStage {
|
2023-11-25 23:16:21 +01:00
|
|
|
BeforeDeps(DynMiddleware),
|
|
|
|
AfterDeps(DynMiddleware),
|
2023-11-25 23:14:38 +01:00
|
|
|
BeforeBase(DynMiddleware),
|
|
|
|
AfterBase(DynMiddleware),
|
|
|
|
BeforeRelease(DynMiddleware),
|
|
|
|
AfterRelease(DynMiddleware),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct RustService {
|
|
|
|
client: dagger_sdk::Query,
|
|
|
|
|
|
|
|
base_image: Option<dagger_sdk::Container>,
|
|
|
|
|
|
|
|
stages: Vec<RustServiceStage>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<dagger_sdk::Query> for RustService {
|
|
|
|
fn from(value: dagger_sdk::Query) -> Self {
|
|
|
|
Self {
|
|
|
|
client: value,
|
|
|
|
base_image: None,
|
|
|
|
stages: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RustService {
|
|
|
|
pub async fn new() -> eyre::Result<Self> {
|
|
|
|
Ok(Self {
|
|
|
|
client: dagger_sdk::connect().await?,
|
|
|
|
base_image: None,
|
|
|
|
stages: Vec::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_base_image(&mut self, base: dagger_sdk::Container) -> &mut Self {
|
|
|
|
self.base_image = Some(base);
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_stage(&mut self, _stage: RustServiceStage) -> &mut Self {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_sqlx(&mut self) -> &mut Self {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn build_release(&self) -> eyre::Result<Vec<Container>> {
|
|
|
|
Ok(Vec::new())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl PullRequestAction for RustService {
|
|
|
|
async fn execute_pull_request(&self) -> eyre::Result<()> {
|
|
|
|
self.build_release().await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl MainAction for RustService {
|
|
|
|
async fn execute_main(&self) -> eyre::Result<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use futures::FutureExt;
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
dagger_middleware::middleware,
|
|
|
|
rust_service::{RustService, RustServiceStage},
|
|
|
|
};
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn can_build_rust() -> eyre::Result<()> {
|
|
|
|
let client = dagger_sdk::connect().await?;
|
|
|
|
|
|
|
|
RustService::from(client.clone())
|
|
|
|
.with_base_image(client.container().from("rustlang/rust:nightly"))
|
|
|
|
.with_sqlx()
|
2023-11-25 23:16:21 +01:00
|
|
|
.with_stage(RustServiceStage::BeforeDeps(middleware(|c| async move { Ok(c) }.boxed())))
|
2023-11-25 23:14:38 +01:00
|
|
|
.build_release()
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|