Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
999d81bb7a
commit
bda242422d
@ -1,8 +1,8 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dagger_sdk::Container;
|
use dagger_sdk::Container;
|
||||||
use std::{future::Future, pin::Pin};
|
use std::{future::Future, pin::Pin, sync::Arc};
|
||||||
|
|
||||||
pub type DynMiddleware = Box<dyn DaggerMiddleware + Send + Sync>;
|
pub type DynMiddleware = Arc<dyn DaggerMiddleware + Send + Sync>;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait DaggerMiddleware {
|
pub trait DaggerMiddleware {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::path::PathBuf;
|
use std::{path::PathBuf, sync::Arc};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dagger_rust::source::RustSource;
|
use dagger_rust::source::RustSource;
|
||||||
@ -12,6 +12,7 @@ use crate::{
|
|||||||
|
|
||||||
use self::architecture::{Architecture, Os};
|
use self::architecture::{Architecture, Os};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub enum RustServiceStage {
|
pub enum RustServiceStage {
|
||||||
BeforeDeps(DynMiddleware),
|
BeforeDeps(DynMiddleware),
|
||||||
AfterDeps(DynMiddleware),
|
AfterDeps(DynMiddleware),
|
||||||
@ -25,6 +26,7 @@ pub enum RustServiceStage {
|
|||||||
AfterRelease(DynMiddleware),
|
AfterRelease(DynMiddleware),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct RustService {
|
pub struct RustService {
|
||||||
client: dagger_sdk::Query,
|
client: dagger_sdk::Query,
|
||||||
base_image: Option<dagger_sdk::Container>,
|
base_image: Option<dagger_sdk::Container>,
|
||||||
@ -141,7 +143,7 @@ impl RustService {
|
|||||||
|
|
||||||
async fn run_stage(
|
async fn run_stage(
|
||||||
&self,
|
&self,
|
||||||
stages: impl IntoIterator<Item = &Box<dyn DaggerMiddleware + Send + Sync>>,
|
stages: impl IntoIterator<Item = &Arc<dyn DaggerMiddleware + Send + Sync>>,
|
||||||
container: Container,
|
container: Container,
|
||||||
) -> eyre::Result<Container> {
|
) -> eyre::Result<Container> {
|
||||||
let before_deps_stream = stream::iter(stages.into_iter().map(Ok));
|
let before_deps_stream = stream::iter(stages.into_iter().map(Ok));
|
||||||
@ -317,29 +319,7 @@ impl MainAction for RustService {
|
|||||||
let container = self.build_release().await?;
|
let container = self.build_release().await?;
|
||||||
|
|
||||||
container
|
container
|
||||||
.publish(format!("docker.io/kjuulh/{}", self.bin_name))
|
.publish(format!("docker.io//{}", self.bin_name))
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl PullRequestAction for &mut RustService {
|
|
||||||
async fn execute_pull_request(&self) -> eyre::Result<()> {
|
|
||||||
self.build_test().await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait]
|
|
||||||
impl MainAction for &mut RustService {
|
|
||||||
async fn execute_main(&self) -> eyre::Result<()> {
|
|
||||||
let container = self.build_release().await?;
|
|
||||||
|
|
||||||
container
|
|
||||||
.publish(format!("docker.io/kjuulh/{}", self.bin_name))
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dagger_sdk::Container;
|
use dagger_sdk::Container;
|
||||||
|
|
||||||
@ -47,6 +49,8 @@ pub trait AptExt {
|
|||||||
|
|
||||||
impl AptExt for RustService {
|
impl AptExt for RustService {
|
||||||
fn with_apt(&mut self, deps: &[&str]) -> &mut Self {
|
fn with_apt(&mut self, deps: &[&str]) -> &mut Self {
|
||||||
self.with_stage(super::RustServiceStage::BeforeDeps(Box::new(Apt::new().extend(deps))))
|
self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new(
|
||||||
|
Apt::new().extend(deps),
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dagger_sdk::Container;
|
use dagger_sdk::Container;
|
||||||
|
|
||||||
@ -62,8 +64,7 @@ impl CargoBInstall {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl DaggerMiddleware for CargoBInstall {
|
impl DaggerMiddleware for CargoBInstall {
|
||||||
async fn handle(&self, container: Container) -> eyre::Result<Container> {
|
async fn handle(&self, container: Container) -> eyre::Result<Container> {
|
||||||
let c =
|
let c = container
|
||||||
container
|
|
||||||
.with_exec(vec!["wget", &self.get_download_url()])
|
.with_exec(vec!["wget", &self.get_download_url()])
|
||||||
.with_exec(vec!["tar", "-xvf", &self.get_archive()])
|
.with_exec(vec!["tar", "-xvf", &self.get_archive()])
|
||||||
.with_exec(
|
.with_exec(
|
||||||
@ -98,8 +99,8 @@ impl CargoBInstallExt for RustService {
|
|||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
let crates: Vec<String> = crates.into_iter().map(|s| s.into()).collect();
|
let crates: Vec<String> = crates.into_iter().map(|s| s.into()).collect();
|
||||||
|
|
||||||
self.with_stage(super::RustServiceStage::BeforeDeps(
|
self.with_stage(super::RustServiceStage::BeforeDeps(Arc::new(
|
||||||
Box::new(CargoBInstall::new(self.get_arch(), self.get_os(), version, crates))
|
CargoBInstall::new(self.get_arch(), self.get_os(), version, crates),
|
||||||
))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dagger_sdk::Container;
|
use dagger_sdk::Container;
|
||||||
|
|
||||||
@ -28,7 +30,7 @@ pub trait CargoCleanExt {
|
|||||||
|
|
||||||
impl CargoCleanExt for RustService {
|
impl CargoCleanExt for RustService {
|
||||||
fn with_cargo_clean(&mut self) -> &mut Self {
|
fn with_cargo_clean(&mut self) -> &mut Self {
|
||||||
self.with_stage(super::RustServiceStage::BeforeBuild(Box::new(
|
self.with_stage(super::RustServiceStage::BeforeBuild(Arc::new(
|
||||||
CargoClean::new(),
|
CargoClean::new(),
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dagger_sdk::Container;
|
use dagger_sdk::Container;
|
||||||
|
|
||||||
@ -32,9 +34,9 @@ pub trait ClapSanityTestExt {
|
|||||||
|
|
||||||
impl ClapSanityTestExt for RustService {
|
impl ClapSanityTestExt for RustService {
|
||||||
fn with_clap_sanity_test(&mut self) -> &mut Self {
|
fn with_clap_sanity_test(&mut self) -> &mut Self {
|
||||||
self.with_stage(
|
self.with_stage(super::RustServiceStage::AfterPackage(Arc::new(
|
||||||
super::RustServiceStage::AfterPackage(Box::new(ClapSanityTest::new(&self.bin_name)))
|
ClapSanityTest::new(&self.bin_name),
|
||||||
);
|
)));
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
use crate::dagger_middleware::DaggerMiddleware;
|
use crate::dagger_middleware::DaggerMiddleware;
|
||||||
@ -95,8 +97,8 @@ pub trait MoldActionExt {
|
|||||||
|
|
||||||
impl MoldActionExt for RustService {
|
impl MoldActionExt for RustService {
|
||||||
fn with_mold(&mut self, version: impl Into<String>) -> &mut Self {
|
fn with_mold(&mut self, version: impl Into<String>) -> &mut Self {
|
||||||
self.with_stage(super::RustServiceStage::AfterDeps(
|
self.with_stage(super::RustServiceStage::AfterDeps(Arc::new(
|
||||||
Box::new(MoldInstall::new(self.get_arch(), self.get_os(), version))
|
MoldInstall::new(self.get_arch(), self.get_os(), version),
|
||||||
))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use dagger_sdk::Container;
|
use dagger_sdk::Container;
|
||||||
|
|
||||||
@ -34,7 +36,7 @@ pub trait SqlxExt {
|
|||||||
|
|
||||||
impl SqlxExt for RustService {
|
impl SqlxExt for RustService {
|
||||||
fn with_sqlx(&mut self) -> &mut Self {
|
fn with_sqlx(&mut self) -> &mut Self {
|
||||||
self.with_stage(super::RustServiceStage::BeforeBuild(Box::new(Sqlx::new(
|
self.with_stage(super::RustServiceStage::BeforeBuild(Arc::new(Sqlx::new(
|
||||||
self.client.clone(),
|
self.client.clone(),
|
||||||
))));
|
))));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user