Rewrite rust (#38)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

Co-authored-by: kjuulh <contact@kjuulh.io>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/octopush/pulls/38
This commit is contained in:
2022-11-27 11:21:35 +00:00
parent 0d6e8bc4a0
commit 991861db99
445 changed files with 53358 additions and 2568 deletions

View File

@@ -0,0 +1,36 @@
use std::{path::PathBuf, sync::Arc};
use async_trait::async_trait;
use crate::schema::models::Action;
use super::{
builders::golang_bin::{GolangBinBuild, GolangBinBuildOpts},
Builder, DynRunnableBin,
};
pub struct BuilderCapabilities;
impl BuilderCapabilities {
pub fn new() -> Self {
Self {}
}
}
#[async_trait]
impl Builder for BuilderCapabilities {
async fn build(&self, action_path: &PathBuf, action: &Action) -> eyre::Result<DynRunnableBin> {
match action {
Action::Go { entry } => {
let bin = GolangBinBuild::new()
.build(GolangBinBuildOpts {
entry: entry.clone(),
src_path: action_path.clone(),
})
.await?;
Ok(Arc::new(bin))
}
}
}
}

View File

@@ -0,0 +1,59 @@
use std::path::PathBuf;
use async_trait::async_trait;
use crate::{builder::RunnableBin, shell::execute_shell};
pub struct GolangBinBuildOpts {
pub entry: String,
pub src_path: PathBuf,
}
pub struct GolangBinBuild;
impl GolangBinBuild {
pub fn new() -> Self {
Self {}
}
pub async fn build(&self, opts: GolangBinBuildOpts) -> eyre::Result<GolangBin> {
tracing::trace!(
src = opts.src_path.to_string_lossy().to_string(),
entry = opts.entry,
"build golang_bin"
);
execute_shell(
format!("go build -o dist/bin {}", opts.entry),
Some(opts.src_path.clone()),
)
.await?;
let abs_path = std::fs::canonicalize(opts.src_path.join("dist/bin"))?;
Ok(GolangBin::new(abs_path))
}
}
pub struct GolangBin {
path: PathBuf,
}
impl GolangBin {
fn new(path: PathBuf) -> Self {
Self { path }
}
}
#[async_trait]
impl RunnableBin for GolangBin {
async fn run(&self, victim_path: &PathBuf) -> eyre::Result<()> {
execute_shell(
self.path.to_string_lossy().to_string(),
Some(victim_path.clone()),
)
.await?;
Ok(())
}
}

View File

@@ -0,0 +1 @@
pub mod golang_bin;

View File

@@ -0,0 +1,22 @@
pub mod builder_capabilities;
mod builders;
use std::{path::PathBuf, sync::Arc};
use async_trait::async_trait;
use crate::schema::models::Action;
#[async_trait]
pub trait RunnableBin {
async fn run(&self, victim_path: &PathBuf) -> eyre::Result<()>;
}
pub type DynRunnableBin = Arc<dyn RunnableBin + Send + Sync>;
#[async_trait]
pub trait Builder {
async fn build(&self, action_path: &PathBuf, action: &Action) -> eyre::Result<DynRunnableBin>;
}
pub type DynBuilder = Arc<dyn Builder + Send + Sync>;