churn/crates/churning/src/main.rs
kjuulh 8c41e1004c
feat: with enroll
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-26 18:46:56 +02:00

70 lines
2.1 KiB
Rust

use std::{path::PathBuf, sync::Arc};
use dagger_rust::build::{RustVersion, SlimImage};
use dagger_sdk::Query;
#[tokio::main]
async fn main() -> eyre::Result<()> {
let client = dagger_sdk::connect().await?;
let agent = build_container(client.clone(), "churn-agent").await?;
let agent = agent
.with_exec(vec!["churn-agent", "daemon", "--host", "0.0.0.0:3000"])
.with_exposed_port(3000);
let cli = build_container(client.clone(), "churn").await?;
let server = build_container(client.clone(), "churn-server").await?;
let server = server
.with_exec(vec!["churn-server", "serve", "--host", "0.0.0.0:3000"])
.with_exposed_port(3000);
let churning = cli
.with_service_binding("churn-agent", agent.id().await?)
.with_service_binding("churn-server", server.id().await?)
.with_exec(vec![
"churn",
"health",
"--server",
"http://churn-server:3000",
"--agent",
"http://churn-agent:3000",
]);
let stdout = churning.stdout().await?;
println!("{stdout}");
let stderr = churning.stderr().await?;
println!("{stderr}");
churning.exit_code().await?;
Ok(())
}
async fn build_container(
client: Arc<Query>,
bin_name: &str,
) -> eyre::Result<dagger_sdk::Container> {
let crates = &["crates/*", "ci"];
let debian_deps = &["libssl-dev", "pkg-config", "openssl", "git", "jq"];
let debian_image = "debian:bullseye".to_string();
let images = dagger_rust::build::RustBuild::new(client.clone())
.build_release(
None::<PathBuf>,
RustVersion::Nightly,
crates,
debian_deps,
vec![SlimImage::Debian {
image: debian_image,
deps: debian_deps
.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>(),
architecture: dagger_rust::build::BuildArchitecture::Amd64,
}],
&bin_name,
)
.await?;
Ok(images.first().take().unwrap().clone())
}