feat: with full support for rust services
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
52
crates/cuddle-ci/src/rust_service/apt.rs
Normal file
52
crates/cuddle-ci/src/rust_service/apt.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use async_trait::async_trait;
|
||||
use dagger_sdk::Container;
|
||||
|
||||
use crate::dagger_middleware::DaggerMiddleware;
|
||||
|
||||
use super::RustService;
|
||||
|
||||
pub struct Apt {
|
||||
deps: Vec<String>,
|
||||
}
|
||||
|
||||
impl Apt {
|
||||
pub fn new() -> Self {
|
||||
Self { deps: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn add(mut self, dep_name: impl Into<String>) -> Self {
|
||||
self.deps.push(dep_name.into());
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn extend(mut self, deps: &[&str]) -> Self {
|
||||
self.deps.extend(deps.iter().map(|s| s.to_string()));
|
||||
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl DaggerMiddleware for Apt {
|
||||
async fn handle(&self, container: Container) -> eyre::Result<Container> {
|
||||
let mut deps = vec!["apt", "install", "-y"];
|
||||
deps.extend(self.deps.iter().map(|s| s.as_str()));
|
||||
|
||||
let c = container.with_exec(vec!["apt", "update"]).with_exec(deps);
|
||||
|
||||
Ok(c)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AptExt {
|
||||
fn with_apt(&mut self, deps: &[&str]) -> &mut Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AptExt for RustService {
|
||||
fn with_apt(&mut self, deps: &[&str]) -> &mut Self {
|
||||
self.with_stage(super::RustServiceStage::BeforeDeps(Box::new(Apt::new().extend(deps))))
|
||||
}
|
||||
}
|
109
crates/cuddle-ci/src/rust_service/cargo_binstall.rs
Normal file
109
crates/cuddle-ci/src/rust_service/cargo_binstall.rs
Normal file
@@ -0,0 +1,109 @@
|
||||
use async_trait::async_trait;
|
||||
use dagger_sdk::Container;
|
||||
|
||||
use crate::dagger_middleware::DaggerMiddleware;
|
||||
|
||||
use super::{
|
||||
architecture::{Architecture, Os},
|
||||
RustService,
|
||||
};
|
||||
|
||||
pub struct CargoBInstall {
|
||||
arch: Architecture,
|
||||
os: Os,
|
||||
version: String,
|
||||
crates: Vec<String>,
|
||||
}
|
||||
|
||||
impl CargoBInstall {
|
||||
pub fn new(
|
||||
arch: Architecture,
|
||||
os: Os,
|
||||
version: impl Into<String>,
|
||||
crates: impl Into<Vec<String>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
arch,
|
||||
os,
|
||||
version: version.into(),
|
||||
crates: crates.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_arch(&self) -> String {
|
||||
match self.arch {
|
||||
Architecture::Amd64 => "x86_64",
|
||||
Architecture::Arm64 => "armv7",
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
fn get_os(&self) -> String {
|
||||
match self.os {
|
||||
Os::Linux => "linux",
|
||||
Os::MacOS => "darwin",
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn get_download_url(&self) -> String {
|
||||
format!("https://github.com/cargo-bins/cargo-binstall/releases/{}/download/cargo-binstall-{}-unknown-{}-musl.tgz", self.version, self.get_arch(), self.get_os())
|
||||
}
|
||||
|
||||
pub fn get_archive(&self) -> String {
|
||||
format!(
|
||||
"cargo-binstall-{}-unknown-{}-musl.tgz",
|
||||
self.get_arch(),
|
||||
self.get_os()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl DaggerMiddleware for CargoBInstall {
|
||||
async fn handle(&self, container: Container) -> eyre::Result<Container> {
|
||||
let c =
|
||||
container
|
||||
.with_exec(vec!["wget", &self.get_download_url()])
|
||||
.with_exec(vec!["tar", "-xvf", &self.get_archive()])
|
||||
.with_exec(
|
||||
"mv cargo-binstall /usr/local/cargo/bin"
|
||||
.split_whitespace()
|
||||
.collect(),
|
||||
);
|
||||
|
||||
let c = self.crates.iter().cloned().fold(c, |acc, item| {
|
||||
acc.with_exec(vec!["cargo", "binstall", &item, "-y"])
|
||||
});
|
||||
|
||||
Ok(c)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait CargoBInstallExt {
|
||||
fn with_cargo_binstall(
|
||||
&mut self,
|
||||
arch: Architecture,
|
||||
os: Os,
|
||||
version: impl Into<String>,
|
||||
crates: impl IntoIterator<Item = impl Into<String>>,
|
||||
) -> &mut Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl CargoBInstallExt for RustService {
|
||||
fn with_cargo_binstall(
|
||||
&mut self,
|
||||
arch: Architecture,
|
||||
os: Os,
|
||||
version: impl Into<String>,
|
||||
crates: impl IntoIterator<Item = impl Into<String>>,
|
||||
) -> &mut Self {
|
||||
let crates: Vec<String> = crates.into_iter().map(|s| s.into()).collect();
|
||||
|
||||
self.with_stage(super::RustServiceStage::BeforeDeps(
|
||||
Box::new(CargoBInstall::new(arch, os, version, crates))
|
||||
))
|
||||
}
|
||||
}
|
41
crates/cuddle-ci/src/rust_service/clap_sanity_test.rs
Normal file
41
crates/cuddle-ci/src/rust_service/clap_sanity_test.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use async_trait::async_trait;
|
||||
use dagger_sdk::Container;
|
||||
|
||||
use crate::dagger_middleware::DaggerMiddleware;
|
||||
|
||||
use super::RustService;
|
||||
|
||||
pub struct ClapSanityTest {
|
||||
bin_name: String,
|
||||
}
|
||||
|
||||
impl ClapSanityTest {
|
||||
pub fn new(bin_name: impl Into<String>) -> Self {
|
||||
Self {
|
||||
bin_name: bin_name.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl DaggerMiddleware for ClapSanityTest {
|
||||
async fn handle(&self, container: Container) -> eyre::Result<Container> {
|
||||
Ok(container.with_exec(vec![&self.bin_name, "--help"]))
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ClapSanityTestExt {
|
||||
fn with_clap_sanity_test(&mut self) -> &mut Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl ClapSanityTestExt for RustService {
|
||||
fn with_clap_sanity_test(&mut self) -> &mut Self {
|
||||
self.with_stage(
|
||||
super::RustServiceStage::AfterPackage(Box::new(ClapSanityTest::new(&self.bin_name)))
|
||||
);
|
||||
|
||||
self
|
||||
}
|
||||
}
|
112
crates/cuddle-ci/src/rust_service/mold.rs
Normal file
112
crates/cuddle-ci/src/rust_service/mold.rs
Normal file
@@ -0,0 +1,112 @@
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::dagger_middleware::DaggerMiddleware;
|
||||
|
||||
use super::{
|
||||
architecture::{Architecture, Os},
|
||||
RustService,
|
||||
};
|
||||
|
||||
pub struct MoldInstall {
|
||||
arch: Architecture,
|
||||
os: Os,
|
||||
version: String,
|
||||
}
|
||||
|
||||
impl MoldInstall {
|
||||
pub fn new(arch: Architecture, os: Os, version: impl Into<String>) -> Self {
|
||||
Self {
|
||||
arch,
|
||||
os,
|
||||
version: version.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_arch(&self) -> String {
|
||||
match self.arch {
|
||||
Architecture::Amd64 => "x86_64",
|
||||
Architecture::Arm64 => "arm",
|
||||
}
|
||||
.into()
|
||||
}
|
||||
fn get_os(&self) -> String {
|
||||
match &self.os {
|
||||
Os::Linux => "linux",
|
||||
o => todo!("os not implemented for mold: {:?}", o),
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn get_download_url(&self) -> String {
|
||||
format!(
|
||||
"https://github.com/rui314/mold/releases/download/v{}/mold-{}-{}-{}.tar.gz",
|
||||
self.version,
|
||||
self.version,
|
||||
self.get_arch(),
|
||||
self.get_os()
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_folder(&self) -> String {
|
||||
format!(
|
||||
"mold-{}-{}-{}",
|
||||
self.version,
|
||||
self.get_arch(),
|
||||
self.get_os()
|
||||
)
|
||||
}
|
||||
|
||||
pub fn get_archive_name(&self) -> String {
|
||||
format!(
|
||||
"mold-{}-{}-{}.tar.gz",
|
||||
self.version,
|
||||
self.get_arch(),
|
||||
self.get_os()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl DaggerMiddleware for MoldInstall {
|
||||
async fn handle(
|
||||
&self,
|
||||
container: dagger_sdk::Container,
|
||||
) -> eyre::Result<dagger_sdk::Container> {
|
||||
println!("installing mold");
|
||||
|
||||
let c = container
|
||||
.with_exec(vec!["wget", &self.get_download_url()])
|
||||
.with_exec(vec!["tar", "-xvf", &self.get_archive_name()])
|
||||
.with_exec(vec![
|
||||
"mv",
|
||||
&format!("{}/bin/mold", self.get_folder()),
|
||||
"/usr/bin/mold",
|
||||
]);
|
||||
|
||||
Ok(c)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MoldActionExt {
|
||||
fn with_mold(
|
||||
&mut self,
|
||||
architecture: Architecture,
|
||||
os: Os,
|
||||
version: impl Into<String>,
|
||||
) -> &mut Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl MoldActionExt for RustService {
|
||||
fn with_mold(
|
||||
&mut self,
|
||||
architecture: Architecture,
|
||||
os: Os,
|
||||
version: impl Into<String>,
|
||||
) -> &mut Self {
|
||||
self.with_stage(super::RustServiceStage::AfterDeps(
|
||||
Box::new(MoldInstall::new(architecture, os, version))
|
||||
))
|
||||
}
|
||||
}
|
12
crates/cuddle-ci/src/rust_service/sqlx.rs
Normal file
12
crates/cuddle-ci/src/rust_service/sqlx.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use async_trait::async_trait;
|
||||
use dagger_sdk::Container;
|
||||
|
||||
use crate::dagger_middleware::DaggerMiddleware;
|
||||
|
||||
pub struct Sqlx {}
|
||||
#[async_trait]
|
||||
impl DaggerMiddleware for Sqlx {
|
||||
async fn handle(&self, container: Container) -> eyre::Result<Container> {
|
||||
Ok(container.with_env_variable("SQLX_OFFLINE", "true"))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user