2023-08-24 17:22:45 +02:00
|
|
|
use std::{path::PathBuf, sync::Arc};
|
|
|
|
|
|
|
|
use dagger_rust::build::{RustVersion, SlimImage};
|
2023-08-26 19:31:54 +02:00
|
|
|
use dagger_sdk::{Config, Query};
|
|
|
|
use tokio::io::{AsyncBufReadExt, AsyncWriteExt};
|
2023-08-24 17:22:45 +02:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> eyre::Result<()> {
|
2023-08-26 19:31:54 +02:00
|
|
|
let mut config = Config::default();
|
|
|
|
config.logger = None;
|
|
|
|
|
|
|
|
println!("Building churning...");
|
|
|
|
|
2023-08-26 22:32:38 +02:00
|
|
|
//let client = dagger_sdk::connect_opts(config).await?;
|
|
|
|
let client = dagger_sdk::connect().await?;
|
2023-08-24 17:22:45 +02:00
|
|
|
|
|
|
|
let cli = build_container(client.clone(), "churn").await?;
|
|
|
|
let server = build_container(client.clone(), "churn-server").await?;
|
|
|
|
let server = server
|
2023-08-27 18:15:25 +02:00
|
|
|
.with_env_variable("CHURN_DATABASE", "sled")
|
|
|
|
.with_env_variable("CHURN_SLED_PATH", "/mnt/sled")
|
|
|
|
.with_mounted_cache("/mnt/sled", client.cache_volume("sled").id().await?)
|
2023-08-24 17:22:45 +02:00
|
|
|
.with_exec(vec!["churn-server", "serve", "--host", "0.0.0.0:3000"])
|
|
|
|
.with_exposed_port(3000);
|
|
|
|
|
2023-08-26 22:32:38 +02:00
|
|
|
let server_id = server.id().await?;
|
|
|
|
|
|
|
|
let agent = build_container(client.clone(), "churn-agent").await?;
|
|
|
|
let agent = agent
|
|
|
|
.with_service_binding("churn-server", server_id.clone())
|
|
|
|
.with_exec(vec!["churn-agent", "daemon", "--host", "0.0.0.0:3000"])
|
|
|
|
.with_exposed_port(3000);
|
|
|
|
|
2023-08-25 21:52:28 +02:00
|
|
|
let churning = cli
|
|
|
|
.with_service_binding("churn-agent", agent.id().await?)
|
2023-08-26 22:32:38 +02:00
|
|
|
.with_service_binding("churn-server", server_id)
|
|
|
|
.with_env_variable("CHURN_SERVER", "http://churn-server:3000")
|
|
|
|
.with_env_variable("CHURN_SERVER_TOKEN", "something")
|
|
|
|
.with_env_variable("CHURN_AGENT", "http://churn-agent:3000")
|
|
|
|
.with_env_variable("CHURN_AGENT_NAME", "churn-agent")
|
2023-08-24 17:22:45 +02:00
|
|
|
.with_exec(vec![
|
|
|
|
"churn",
|
|
|
|
"health",
|
|
|
|
"--server",
|
2023-08-25 21:52:28 +02:00
|
|
|
"http://churn-server:3000",
|
2023-08-24 17:22:45 +02:00
|
|
|
"--agent",
|
2023-08-25 21:52:28 +02:00
|
|
|
"http://churn-agent:3000",
|
|
|
|
]);
|
|
|
|
|
|
|
|
let stdout = churning.stdout().await?;
|
|
|
|
println!("{stdout}");
|
|
|
|
let stderr = churning.stderr().await?;
|
|
|
|
println!("{stderr}");
|
|
|
|
|
|
|
|
churning.exit_code().await?;
|
2023-08-26 19:31:54 +02:00
|
|
|
println!("Finished building churning...");
|
|
|
|
|
|
|
|
repl(churning).await?; //.with_entrypoint(vec!["churn"])).await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn repl(container: dagger_sdk::Container) -> eyre::Result<()> {
|
|
|
|
loop {
|
2023-08-26 22:32:38 +02:00
|
|
|
let stdin = tokio::io::stdin();
|
2023-08-26 19:31:54 +02:00
|
|
|
let mut stdout = tokio::io::stdout();
|
|
|
|
|
|
|
|
stdout.write_all(b"> ").await?;
|
|
|
|
stdout.flush().await?;
|
|
|
|
|
|
|
|
let mut input = String::new();
|
|
|
|
|
|
|
|
let mut stdin = tokio::io::BufReader::new(stdin);
|
|
|
|
|
|
|
|
stdin.read_line(&mut input).await?;
|
|
|
|
|
|
|
|
let input = input.trim();
|
|
|
|
if input == "q" {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-08-27 19:42:33 +02:00
|
|
|
let container = container.with_exec(input.split(' ').collect());
|
2023-08-26 19:31:54 +02:00
|
|
|
|
|
|
|
match container.stdout().await {
|
|
|
|
Ok(stdout) => {
|
|
|
|
println!("{stdout}");
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
eprintln!("{}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match container.exit_code().await {
|
|
|
|
Ok(_) => {}
|
|
|
|
Err(_e) => {
|
|
|
|
//eprintln!("encountred error: {}", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-08-24 17:22:45 +02:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn build_container(
|
|
|
|
client: Arc<Query>,
|
|
|
|
bin_name: &str,
|
|
|
|
) -> eyre::Result<dagger_sdk::Container> {
|
|
|
|
let crates = &["crates/*", "ci"];
|
2023-08-27 18:15:25 +02:00
|
|
|
let debian_deps = &[
|
|
|
|
"libssl-dev",
|
|
|
|
"pkg-config",
|
|
|
|
"openssl",
|
|
|
|
"git",
|
|
|
|
"jq",
|
|
|
|
"capnproto",
|
|
|
|
];
|
2023-08-24 17:22:45 +02:00
|
|
|
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<_>>(),
|
2023-08-26 18:46:56 +02:00
|
|
|
architecture: dagger_rust::build::BuildArchitecture::Amd64,
|
2023-08-24 17:22:45 +02:00
|
|
|
}],
|
2023-08-26 22:32:38 +02:00
|
|
|
bin_name,
|
2023-08-24 17:22:45 +02:00
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(images.first().take().unwrap().clone())
|
|
|
|
}
|