2023-11-27 20:11:49 +01:00
|
|
|
use std::{path::PathBuf, sync::Arc};
|
2023-11-26 22:19:34 +01:00
|
|
|
|
2023-11-25 23:14:38 +01:00
|
|
|
use async_trait::async_trait;
|
2023-11-26 22:19:34 +01:00
|
|
|
use dagger_rust::source::RustSource;
|
2023-11-25 23:14:38 +01:00
|
|
|
use dagger_sdk::Container;
|
2023-11-26 22:19:34 +01:00
|
|
|
use futures::{stream, StreamExt};
|
2023-11-25 23:14:38 +01:00
|
|
|
|
2023-11-26 22:46:34 +01:00
|
|
|
use crate::{
|
|
|
|
dagger_middleware::{DaggerMiddleware, DynMiddleware},
|
2024-02-03 18:54:17 +01:00
|
|
|
Context, MainAction, PullRequestAction,
|
2023-11-26 22:46:34 +01:00
|
|
|
};
|
2023-11-25 23:14:38 +01:00
|
|
|
|
2023-11-26 22:46:34 +01:00
|
|
|
use self::architecture::{Architecture, Os};
|
2023-11-25 23:14:38 +01:00
|
|
|
|
2023-11-27 20:11:49 +01:00
|
|
|
#[derive(Clone)]
|
2023-11-25 23:14:38 +01:00
|
|
|
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),
|
2023-11-26 22:19:34 +01:00
|
|
|
BeforeBuild(DynMiddleware),
|
|
|
|
AfterBuild(DynMiddleware),
|
|
|
|
BeforePackage(DynMiddleware),
|
|
|
|
AfterPackage(DynMiddleware),
|
2023-11-25 23:14:38 +01:00
|
|
|
BeforeRelease(DynMiddleware),
|
|
|
|
AfterRelease(DynMiddleware),
|
|
|
|
}
|
|
|
|
|
2023-11-27 20:11:49 +01:00
|
|
|
#[derive(Clone)]
|
2023-11-25 23:14:38 +01:00
|
|
|
pub struct RustService {
|
|
|
|
client: dagger_sdk::Query,
|
|
|
|
base_image: Option<dagger_sdk::Container>,
|
2023-11-26 22:19:34 +01:00
|
|
|
final_image: Option<dagger_sdk::Container>,
|
2023-11-25 23:14:38 +01:00
|
|
|
stages: Vec<RustServiceStage>,
|
2023-11-26 22:19:34 +01:00
|
|
|
source: Option<PathBuf>,
|
|
|
|
crates: Vec<String>,
|
|
|
|
bin_name: String,
|
2023-11-26 22:46:34 +01:00
|
|
|
arch: Option<Architecture>,
|
|
|
|
os: Option<Os>,
|
2024-01-28 00:25:42 +01:00
|
|
|
deployment: bool,
|
2023-11-25 23:14:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<dagger_sdk::Query> for RustService {
|
|
|
|
fn from(value: dagger_sdk::Query) -> Self {
|
|
|
|
Self {
|
2024-03-30 02:26:08 +01:00
|
|
|
client: value.pipeline("rust-service"),
|
2023-11-25 23:14:38 +01:00
|
|
|
base_image: None,
|
2023-11-26 22:19:34 +01:00
|
|
|
final_image: None,
|
2023-11-25 23:14:38 +01:00
|
|
|
stages: Vec::new(),
|
2023-11-26 22:19:34 +01:00
|
|
|
source: None,
|
|
|
|
crates: Vec::new(),
|
|
|
|
bin_name: String::new(),
|
2023-11-26 22:46:34 +01:00
|
|
|
arch: None,
|
|
|
|
os: None,
|
2024-01-28 00:25:42 +01:00
|
|
|
deployment: true,
|
2023-11-25 23:14:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RustService {
|
|
|
|
pub async fn new() -> eyre::Result<Self> {
|
|
|
|
Ok(Self {
|
|
|
|
client: dagger_sdk::connect().await?,
|
|
|
|
base_image: None,
|
2023-11-26 22:19:34 +01:00
|
|
|
final_image: None,
|
2023-11-25 23:14:38 +01:00
|
|
|
stages: Vec::new(),
|
2023-11-26 22:19:34 +01:00
|
|
|
source: None,
|
|
|
|
crates: Vec::new(),
|
|
|
|
bin_name: String::new(),
|
2023-11-26 22:46:34 +01:00
|
|
|
arch: None,
|
|
|
|
os: None,
|
2024-01-28 00:25:42 +01:00
|
|
|
deployment: true,
|
2023-11-25 23:14:38 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_base_image(&mut self, base: dagger_sdk::Container) -> &mut Self {
|
|
|
|
self.base_image = Some(base);
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
pub fn with_stage(&mut self, stage: RustServiceStage) -> &mut Self {
|
|
|
|
self.stages.push(stage);
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_source(&mut self, path: impl Into<PathBuf>) -> &mut Self {
|
|
|
|
self.source = Some(path.into());
|
|
|
|
|
2023-11-25 23:14:38 +01:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
pub fn with_bin_name(&mut self, bin_name: impl Into<String>) -> &mut Self {
|
|
|
|
self.bin_name = bin_name.into();
|
|
|
|
|
2023-11-25 23:14:38 +01:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
pub fn with_crates(
|
|
|
|
&mut self,
|
|
|
|
crates: impl IntoIterator<Item = impl Into<String>>,
|
|
|
|
) -> &mut Self {
|
|
|
|
self.crates = crates.into_iter().map(|c| c.into()).collect();
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:46:34 +01:00
|
|
|
pub fn with_arch(&mut self, arch: Architecture) -> &mut Self {
|
|
|
|
self.arch = Some(arch);
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_os(&mut self, os: Os) -> &mut Self {
|
|
|
|
self.os = Some(os);
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2024-01-28 00:25:42 +01:00
|
|
|
pub fn with_deployment(&mut self, deployment: bool) -> &mut Self {
|
|
|
|
self.deployment = deployment;
|
|
|
|
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
fn get_src(&self) -> PathBuf {
|
|
|
|
self.source
|
|
|
|
.clone()
|
|
|
|
.unwrap_or(std::env::current_dir().unwrap())
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:46:34 +01:00
|
|
|
fn get_arch(&self) -> Architecture {
|
|
|
|
self.arch
|
|
|
|
.clone()
|
|
|
|
.unwrap_or_else(|| match std::env::consts::ARCH {
|
|
|
|
"x86" | "x86_64" | "amd64" => Architecture::Amd64,
|
|
|
|
"arm" => Architecture::Arm64,
|
|
|
|
arch => panic!("unsupported architecture: {arch}"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_os(&self) -> Os {
|
|
|
|
self.os
|
|
|
|
.clone()
|
|
|
|
.unwrap_or_else(|| match std::env::consts::OS {
|
|
|
|
"linux" => Os::Linux,
|
|
|
|
"macos" => Os::MacOS,
|
|
|
|
os => panic!("unsupported os: {os}"),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
async fn run_stage(
|
|
|
|
&self,
|
2023-11-27 20:11:49 +01:00
|
|
|
stages: impl IntoIterator<Item = &Arc<dyn DaggerMiddleware + Send + Sync>>,
|
2023-11-26 22:19:34 +01:00
|
|
|
container: Container,
|
|
|
|
) -> eyre::Result<Container> {
|
|
|
|
let before_deps_stream = stream::iter(stages.into_iter().map(Ok));
|
|
|
|
let res = StreamExt::fold(before_deps_stream, Ok(container), |base, m| async move {
|
|
|
|
match (base, m) {
|
|
|
|
(Ok(base), Ok(m)) => m.handle(base).await,
|
|
|
|
(_, Err(e)) | (Err(e), _) => eyre::bail!("failed with {e}"),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn build_base(&self) -> eyre::Result<Container> {
|
2024-03-30 02:26:08 +01:00
|
|
|
let client = self.client.pipeline("build-base");
|
|
|
|
let rust_src = RustSource::new(client.pipeline("load-source"));
|
2023-11-26 22:19:34 +01:00
|
|
|
|
|
|
|
let (src, dep_src) = rust_src
|
|
|
|
.get_rust_src(Some(&self.get_src()), self.crates.clone())
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
let base_image = self
|
|
|
|
.base_image
|
|
|
|
.clone()
|
2024-03-30 02:26:08 +01:00
|
|
|
.unwrap_or(client.container().from("rustlang/rust:nightly"));
|
2023-11-26 22:19:34 +01:00
|
|
|
|
|
|
|
let before_deps = self
|
|
|
|
.stages
|
|
|
|
.iter()
|
|
|
|
.filter_map(|s| match s {
|
|
|
|
RustServiceStage::BeforeDeps(middleware) => Some(middleware),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let image = self.run_stage(before_deps, base_image).await?;
|
|
|
|
|
|
|
|
let after_deps = self
|
|
|
|
.stages
|
|
|
|
.iter()
|
|
|
|
.filter_map(|s| match s {
|
|
|
|
RustServiceStage::AfterDeps(m) => Some(m),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let image = self.run_stage(after_deps, image).await?;
|
|
|
|
|
|
|
|
let before_base = self
|
|
|
|
.stages
|
|
|
|
.iter()
|
|
|
|
.filter_map(|s| match s {
|
|
|
|
RustServiceStage::BeforeBase(m) => Some(m),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let image = self.run_stage(before_base, image).await?;
|
|
|
|
|
2024-03-30 02:26:08 +01:00
|
|
|
let cache = client.cache_volume("rust_target_cache");
|
2023-11-26 22:19:34 +01:00
|
|
|
|
|
|
|
let rust_prebuild = image
|
|
|
|
.with_workdir("/mnt/src")
|
|
|
|
.with_directory("/mnt/src", dep_src)
|
|
|
|
.with_exec(vec!["cargo", "build", "--release", "--bin", &self.bin_name])
|
|
|
|
.with_mounted_cache("/mnt/src/target/", cache);
|
|
|
|
|
|
|
|
let incremental_dir = rust_src
|
|
|
|
.get_rust_target_src(&self.get_src(), rust_prebuild.clone(), self.crates.clone())
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
let rust_with_src = image
|
|
|
|
.with_workdir("/mnt/src")
|
|
|
|
.with_directory(
|
|
|
|
"/usr/local/cargo",
|
|
|
|
rust_prebuild.directory("/usr/local/cargo"),
|
|
|
|
)
|
|
|
|
.with_directory("/mnt/src/target", incremental_dir)
|
|
|
|
.with_directory("/mnt/src/", src);
|
|
|
|
|
|
|
|
let after_base = self
|
|
|
|
.stages
|
|
|
|
.iter()
|
|
|
|
.filter_map(|s| match s {
|
|
|
|
RustServiceStage::AfterBase(m) => Some(m),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let image = self.run_stage(after_base, rust_with_src).await?;
|
|
|
|
|
|
|
|
Ok(image)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn build_release(&self) -> eyre::Result<Container> {
|
2024-03-30 02:26:08 +01:00
|
|
|
let base = self.build_base().await?.pipeline("build-release");
|
|
|
|
let client = self.client.pipeline("build-release");
|
2023-11-26 22:19:34 +01:00
|
|
|
|
|
|
|
let before_build = self
|
|
|
|
.stages
|
|
|
|
.iter()
|
|
|
|
.filter_map(|s| match s {
|
|
|
|
RustServiceStage::BeforeBuild(m) => Some(m),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let base = self.run_stage(before_build, base).await?;
|
|
|
|
|
|
|
|
let binary_build =
|
|
|
|
base.with_exec(vec!["cargo", "build", "--release", "--bin", &self.bin_name]);
|
|
|
|
|
|
|
|
let after_build = self
|
|
|
|
.stages
|
|
|
|
.iter()
|
|
|
|
.filter_map(|s| match s {
|
|
|
|
RustServiceStage::AfterBuild(m) => Some(m),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let binary_build = self.run_stage(after_build, binary_build).await?;
|
|
|
|
|
|
|
|
let dest = self
|
|
|
|
.final_image
|
|
|
|
.clone()
|
2024-03-30 02:26:08 +01:00
|
|
|
.unwrap_or(client.container().from("debian:bookworm"));
|
2023-11-26 22:19:34 +01:00
|
|
|
|
|
|
|
let before_package = self
|
|
|
|
.stages
|
|
|
|
.iter()
|
|
|
|
.filter_map(|s| match s {
|
|
|
|
RustServiceStage::BeforePackage(m) => Some(m),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let dest = self.run_stage(before_package, dest).await?;
|
|
|
|
|
|
|
|
let final_image = dest.with_workdir("/mnt/app").with_file(
|
|
|
|
format!("/usr/local/bin/{}", self.bin_name),
|
|
|
|
binary_build.file(format!("/mnt/src/target/release/{}", self.bin_name)),
|
|
|
|
);
|
|
|
|
|
|
|
|
let after_package = self
|
|
|
|
.stages
|
|
|
|
.iter()
|
|
|
|
.filter_map(|s| match s {
|
|
|
|
RustServiceStage::AfterPackage(m) => Some(m),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let final_image = self.run_stage(after_package, final_image).await?;
|
|
|
|
|
|
|
|
Ok(final_image)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn build_test(&self) -> eyre::Result<()> {
|
2024-03-30 02:26:08 +01:00
|
|
|
let base = self.build_base().await?.pipeline("build-test");
|
2023-11-26 22:19:34 +01:00
|
|
|
|
2023-11-27 20:31:29 +01:00
|
|
|
let before_build = self
|
|
|
|
.stages
|
|
|
|
.iter()
|
|
|
|
.filter_map(|s| match s {
|
|
|
|
RustServiceStage::BeforeBuild(m) => Some(m),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let base = self.run_stage(before_build, base).await?;
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
base.with_exec(vec!["cargo", "test", "--release"])
|
|
|
|
.sync()
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
2023-11-25 23:14:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl PullRequestAction for RustService {
|
2024-02-03 18:54:17 +01:00
|
|
|
async fn execute_pull_request(&self, _ctx: &mut Context) -> eyre::Result<()> {
|
2023-11-27 18:11:58 +01:00
|
|
|
self.build_test().await?;
|
2023-11-25 23:14:38 +01:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-03 18:54:17 +01:00
|
|
|
const IMAGE_TAG: &str = "RUST_SERVICE_IMAGE_TAG";
|
|
|
|
|
|
|
|
pub trait RustServiceContext {
|
|
|
|
fn set_image_tag(&mut self, tag: impl Into<String>) -> eyre::Result<()>;
|
|
|
|
fn get_image_tag(&self) -> eyre::Result<Option<String>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RustServiceContext for Context {
|
|
|
|
fn get_image_tag(&self) -> eyre::Result<Option<String>> {
|
|
|
|
Ok(self.get(IMAGE_TAG).cloned())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_image_tag(&mut self, tag: impl Into<String>) -> eyre::Result<()> {
|
|
|
|
let tag = tag.into();
|
|
|
|
|
|
|
|
self.insert(IMAGE_TAG.to_string(), tag);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-25 23:14:38 +01:00
|
|
|
#[async_trait]
|
|
|
|
impl MainAction for RustService {
|
2024-02-03 18:54:17 +01:00
|
|
|
async fn execute_main(&self, ctx: &mut Context) -> eyre::Result<()> {
|
2024-03-30 02:26:08 +01:00
|
|
|
let container = self.build_release().await?.pipeline("main");
|
2023-11-27 21:24:45 +01:00
|
|
|
let timestamp = std::time::SystemTime::now()
|
|
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
|
|
.unwrap()
|
|
|
|
.as_secs();
|
2023-11-27 19:20:41 +01:00
|
|
|
|
2024-02-03 20:42:17 +01:00
|
|
|
let tag = format!(
|
|
|
|
"docker.io/kasperhermansen/{}:main-{}",
|
|
|
|
self.bin_name, timestamp,
|
|
|
|
);
|
2024-02-03 19:39:05 +01:00
|
|
|
|
2024-02-03 20:42:23 +01:00
|
|
|
container.publish(&tag).await?;
|
2024-02-03 21:09:08 +01:00
|
|
|
ctx.set_image_tag(format!("main-{}", ×tamp.to_string()))?;
|
2024-02-03 18:54:17 +01:00
|
|
|
|
2024-01-28 00:25:42 +01:00
|
|
|
if self.deployment {
|
|
|
|
let update_deployments_docker_image =
|
|
|
|
"docker.io/kasperhermansen/update-deployment:1701123940";
|
|
|
|
let dep = self
|
|
|
|
.client
|
|
|
|
.container()
|
|
|
|
.from(update_deployments_docker_image);
|
|
|
|
|
|
|
|
let dep = if let Ok(sock) = std::env::var("SSH_AUTH_SOCK") {
|
|
|
|
dep.with_unix_socket("/tmp/ssh_sock", self.client.host().unix_socket(sock))
|
|
|
|
.with_env_variable("SSH_AUTH_SOCK", "/tmp/ssh_sock")
|
|
|
|
.with_exec(vec![
|
|
|
|
"update-deployment",
|
|
|
|
"--repo",
|
|
|
|
&format!(
|
|
|
|
"git@git.front.kjuulh.io:kjuulh/{}-deployment.git",
|
|
|
|
self.bin_name
|
|
|
|
),
|
|
|
|
"--service",
|
|
|
|
&self.bin_name,
|
|
|
|
"--image",
|
|
|
|
&format!("kasperhermansen/{}:main-{}", self.bin_name, timestamp),
|
|
|
|
])
|
|
|
|
} else {
|
|
|
|
dep.with_env_variable("GIT_USERNAME", "kjuulh")
|
|
|
|
.with_env_variable(
|
|
|
|
"GIT_PASSWORD",
|
|
|
|
std::env::var("GIT_PASSWORD").expect("GIT_PASSWORD to be set"),
|
|
|
|
)
|
|
|
|
.with_exec(vec![
|
|
|
|
"update-deployment",
|
|
|
|
"--repo",
|
|
|
|
&format!(
|
|
|
|
"https://git.front.kjuulh.io/kjuulh/{}-deployment.git",
|
|
|
|
self.bin_name
|
|
|
|
),
|
|
|
|
"--service",
|
|
|
|
&self.bin_name,
|
|
|
|
"--image",
|
|
|
|
&format!("kasperhermansen/{}:main-{}", self.bin_name, timestamp),
|
|
|
|
])
|
|
|
|
};
|
|
|
|
|
|
|
|
dep.sync().await?;
|
|
|
|
}
|
2023-11-25 23:14:38 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
pub mod architecture {
|
2023-11-26 22:46:34 +01:00
|
|
|
#[derive(Debug, Clone)]
|
2023-11-26 22:19:34 +01:00
|
|
|
pub enum Architecture {
|
|
|
|
Amd64,
|
|
|
|
Arm64,
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:46:34 +01:00
|
|
|
#[derive(Debug, Clone)]
|
2023-11-26 22:19:34 +01:00
|
|
|
pub enum Os {
|
|
|
|
Linux,
|
|
|
|
MacOS,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-26 22:46:34 +01:00
|
|
|
mod apt;
|
2023-11-28 00:49:28 +01:00
|
|
|
mod apt_ca_certificates;
|
2023-11-28 10:12:19 +01:00
|
|
|
mod assets;
|
2023-11-26 22:46:34 +01:00
|
|
|
mod cargo_binstall;
|
2023-11-27 13:42:13 +01:00
|
|
|
mod cargo_clean;
|
2023-11-26 22:46:34 +01:00
|
|
|
mod clap_sanity_test;
|
2024-01-28 23:41:59 +01:00
|
|
|
mod cuddle_cli;
|
2024-04-05 22:45:25 +02:00
|
|
|
mod cuddle_file;
|
2024-04-06 22:29:06 +02:00
|
|
|
mod dagger_bin;
|
2023-12-01 21:41:13 +01:00
|
|
|
mod docker_cache;
|
2024-01-28 23:34:05 +01:00
|
|
|
mod docker_cli;
|
2024-01-31 20:55:24 +01:00
|
|
|
mod kubectl;
|
2023-11-26 22:46:34 +01:00
|
|
|
mod mold;
|
2024-03-30 22:33:25 +01:00
|
|
|
mod rust_workspace;
|
2023-11-26 22:46:34 +01:00
|
|
|
mod sqlx;
|
2023-12-30 21:55:29 +01:00
|
|
|
mod ssh_agent;
|
2023-11-26 22:46:34 +01:00
|
|
|
|
|
|
|
pub mod extensions {
|
|
|
|
pub use super::apt::*;
|
2023-11-28 00:49:28 +01:00
|
|
|
pub use super::apt_ca_certificates::*;
|
2023-11-28 10:12:19 +01:00
|
|
|
pub use super::assets::*;
|
2023-11-26 22:46:34 +01:00
|
|
|
pub use super::cargo_binstall::*;
|
2023-11-27 13:42:13 +01:00
|
|
|
pub use super::cargo_clean::*;
|
2023-11-26 22:46:34 +01:00
|
|
|
pub use super::clap_sanity_test::*;
|
2024-01-28 23:41:59 +01:00
|
|
|
pub use super::cuddle_cli::*;
|
2024-04-05 22:45:25 +02:00
|
|
|
pub use super::cuddle_file::*;
|
2024-04-06 22:29:06 +02:00
|
|
|
pub use super::dagger_bin::*;
|
2023-12-01 21:41:13 +01:00
|
|
|
pub use super::docker_cache::*;
|
2024-01-28 23:34:05 +01:00
|
|
|
pub use super::docker_cli::*;
|
2024-01-31 20:55:24 +01:00
|
|
|
pub use super::kubectl::*;
|
2023-11-26 22:46:34 +01:00
|
|
|
pub use super::mold::*;
|
2024-03-30 22:33:25 +01:00
|
|
|
pub use super::rust_workspace::*;
|
2023-11-26 22:46:34 +01:00
|
|
|
pub use super::sqlx::*;
|
2023-12-30 21:55:29 +01:00
|
|
|
pub use super::ssh_agent::*;
|
2023-11-26 22:46:34 +01:00
|
|
|
}
|
2023-11-26 22:19:34 +01:00
|
|
|
|
2023-11-25 23:14:38 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2024-02-03 18:54:17 +01:00
|
|
|
|
|
|
|
use crate::rust_service::{
|
|
|
|
apt::AptExt,
|
|
|
|
architecture::{Architecture, Os},
|
|
|
|
cargo_binstall::CargoBInstallExt,
|
|
|
|
clap_sanity_test::ClapSanityTestExt,
|
|
|
|
mold::MoldActionExt,
|
|
|
|
RustService,
|
2023-11-25 23:14:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#[tokio::test]
|
2024-04-05 22:45:25 +02:00
|
|
|
#[cfg(any(feature = "dagger", feature = "integration"))]
|
2023-11-26 22:19:34 +01:00
|
|
|
async fn test_can_build_rust() -> eyre::Result<()> {
|
2023-11-25 23:14:38 +01:00
|
|
|
let client = dagger_sdk::connect().await?;
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
let root_dir = std::path::PathBuf::from("../../").canonicalize()?;
|
|
|
|
|
|
|
|
let container = RustService::from(client.clone())
|
2023-11-26 22:46:34 +01:00
|
|
|
.with_arch(Architecture::Amd64)
|
|
|
|
.with_os(Os::Linux)
|
2023-11-26 22:19:34 +01:00
|
|
|
.with_source(root_dir)
|
|
|
|
.with_bin_name("ci")
|
|
|
|
.with_crates(["crates/*", "examples/*", "ci"])
|
2023-11-27 13:25:31 +01:00
|
|
|
.with_apt(&["git"])
|
|
|
|
.with_cargo_binstall("latest", ["sqlx-cli"])
|
2023-11-26 22:46:34 +01:00
|
|
|
.with_mold("2.3.3")
|
2024-01-28 20:44:12 +01:00
|
|
|
// .with_stage(RustServiceStage::BeforeDeps(middleware(|c| {
|
|
|
|
// async move {
|
|
|
|
// // Noop
|
|
|
|
// Ok(c)
|
|
|
|
// }
|
|
|
|
// .boxed()
|
|
|
|
// })))
|
2023-11-26 22:19:34 +01:00
|
|
|
.with_clap_sanity_test()
|
2023-11-25 23:14:38 +01:00
|
|
|
.build_release()
|
|
|
|
.await?;
|
|
|
|
|
2023-11-26 22:19:34 +01:00
|
|
|
container.sync().await?;
|
|
|
|
|
2023-11-25 23:14:38 +01:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|