Compare commits

..

3 Commits

Author SHA1 Message Date
9676c6aefb
feat: with module example and api
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-31 22:18:38 +02:00
ac246c2d18
feat: with actual executor
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-31 21:19:07 +02:00
dd80ebb577
feat: with wasm executor
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-28 21:13:50 +02:00
21 changed files with 1928 additions and 1035 deletions

View File

@ -1,2 +0,0 @@
kind: template
load: cuddle-rust-cli-plan.yaml

View File

@ -1,60 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.1.0] - 2024-04-06
### Added
- update
- update
- update stuff
- update
- with drone
- with agent db
- with sled db and capnp
- with sled db
- with basic changelog
- with basic package
- with publish
- with monitoring
- with monitor
- with extra churning repl thingy
- with enroll
- add initial churn
- add simple health check
### Docs
- add notes
### Other
- *(test)* test commit
- *(test)* test commit
- *(test)* test commit
- *(test)* test commit
- Merge pull request 'chore(deps): update all dependencies' (#2) from renovate/all into main
Reviewed-on: https://git.front.kjuulh.io/kjuulh/churn/pulls/2
- *(deps)* update all dependencies
- change to byte slice
- fmt
- fmt
- Add renovate.json
- Release churn-server v0.1.0
- Release churn-agent v0.1.0
- Release churn v0.1.0
- Release churn v0.1.0
- Release churn-domain v0.1.0, churn v0.1.0
- with changelog
- Release churn-domain v0.1.0, churn v0.1.0

2541
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
[workspace] [workspace]
members = ["crates/*"] members = ["crates/*", "examples/*"]
resolver = "2" resolver = "2"
[workspace.package] [workspace.package]
@ -19,19 +19,19 @@ churn-server = { path = "crates/churn-server" }
churn-domain = { path = "crates/churn-domain", version = "0.1.0" } churn-domain = { path = "crates/churn-domain", version = "0.1.0" }
churn-capnp = { path = "crates/churn-capnp", version = "0.1.0" } churn-capnp = { path = "crates/churn-capnp", version = "0.1.0" }
anyhow = { version = "1.0.86" } anyhow = { version = "1.0.71" }
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
tracing = { version = "0.1", features = ["log"] } tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3.18" } tracing-subscriber = { version = "0.3.17" }
clap = { version = "4.5.4", features = ["derive", "env"] } clap = { version = "4.3.4", features = ["derive", "env"] }
dotenv = { version = "0.15.0" } dotenv = { version = "0.15.0" }
axum = { version = "0.7.5", features = ["macros"] } axum = { version = "0.6.18", features = ["macros"] }
async-trait = "*" async-trait = "*"
serde = {version = "1", features = ["derive"]} serde = {version = "1", features = ["derive"]}
serde_json = "1" serde_json = "1"
reqwest = {version = "0.12.4", features = ["json"]} reqwest = {version = "0.11.20", features = ["json"]}
uuid = {version = "1.8.0", features = ["v4", "serde"]} uuid = {version = "1.4.1", features = ["v4", "serde"]}
itertools = {version = "0.13.0"} itertools = {version = "0.11.0"}
sled = "0.34.7" sled = "0.34.7"
chrono = {version = "0.4.38", features = ["serde"]} chrono = {version = "0.4.26", features = ["serde"]}
wasmtime = "12.0.1"

12
adapt.sh Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -e
crate=$1
cargo build -p "$crate" --target wasm32-wasi --release
crate_target=$(echo $crate | sed "s/-/_/g")
#wasm-tools component new ./target/wasm32-wasi/debug/$crate_target.wasm \
# -o $crate_target.wasm #--adapt ./includes/wasi_snapshot_preview1.wasm

View File

@ -7,8 +7,6 @@ version= "0.1.0"
edition.workspace = true edition.workspace = true
publish.workspace = true publish.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
churn-domain.workspace = true churn-domain.workspace = true
@ -22,3 +20,4 @@ axum.workspace = true
serde.workspace = true serde.workspace = true
serde_json.workspace = true serde_json.workspace = true
reqwest.workspace = true reqwest.workspace = true
wasmtime.workspace = true

View File

@ -1,6 +1,6 @@
mod agent; mod agent;
use std::net::SocketAddr; use std::{net::SocketAddr, path::PathBuf};
use agent::AgentService; use agent::AgentService;
use anyhow::Error; use anyhow::Error;
@ -14,7 +14,7 @@ use axum::{
use churn_domain::AgentEnrollReq; use churn_domain::AgentEnrollReq;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use serde_json::json; use serde_json::json;
use tokio::net::TcpListener; use wasmtime::{Caller, Engine, Extern, Func, Linker, Module, Store};
#[derive(Parser)] #[derive(Parser)]
#[command(author, version, about, long_about = None, subcommand_required = true)] #[command(author, version, about, long_about = None, subcommand_required = true)]
@ -41,6 +41,19 @@ enum Commands {
#[arg(env = "CHURN_TOKEN", long)] #[arg(env = "CHURN_TOKEN", long)]
token: String, token: String,
}, },
Execute {
#[arg(env = "CHURN_AGENT_EXE", long)]
exe: PathBuf,
#[command(subcommand)]
commands: Option<ExecuteCommands>,
},
}
#[derive(Subcommand)]
enum ExecuteCommands {
Source,
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]
@ -61,8 +74,8 @@ async fn main() -> anyhow::Result<()> {
} }
async fn handle_command(cmd: Command) -> anyhow::Result<()> { async fn handle_command(cmd: Command) -> anyhow::Result<()> {
match cmd.command { match cmd.command.unwrap() {
Some(Commands::Daemon { host }) => { Commands::Daemon { host } => {
tracing::info!("Starting churn server"); tracing::info!("Starting churn server");
let app = Router::new() let app = Router::new()
@ -71,19 +84,67 @@ async fn handle_command(cmd: Command) -> anyhow::Result<()> {
.with_state(AppState::default()); .with_state(AppState::default());
tracing::info!("churn server listening on {}", host); tracing::info!("churn server listening on {}", host);
let listener = TcpListener::bind(&host).await?; axum::Server::bind(&host)
axum::serve(listener, app.into_make_service()) .serve(app.into_make_service())
.await .await
.unwrap(); .unwrap();
Ok(()) Ok(())
} }
Some(Commands::Connect { Commands::Connect {
host: _, host: _,
token: _, token: _,
agent_name: _, agent_name: _,
}) => todo!(), } => todo!(),
None => todo!(), Commands::Execute { exe, commands } => match commands {
Some(ExecuteCommands::Source) => Ok(()),
None => {
let engine = Engine::default();
let module = Module::from_file(&engine, exe)?;
let mut linker = Linker::new(&engine);
linker.func_wrap(
"$root",
"print",
|mut caller: Caller<'_, ()>, ptr: i32, len: i32| {
// Use our `caller` context to learn about the memory export of the
// module which called this host function.
let mem = match caller.get_export("memory") {
Some(Extern::Memory(mem)) => mem,
_ => panic!("failed to find host memory"),
};
// Use the `ptr` and `len` values to get a subslice of the wasm-memory
// which we'll attempt to interpret as utf-8.
let data = mem
.data(&caller)
.get(ptr as u32 as usize..)
.and_then(|arr| arr.get(..len as u32 as usize));
let string = match data {
Some(data) => match std::str::from_utf8(data) {
Ok(s) => s,
Err(_) => panic!("invalid utf-8"),
},
None => panic!("pointer/length out of bounds"),
};
println!("Got {} from WebAssembly", string);
},
)?;
// All wasm objects operate within the context of a "store". Each
// `Store` has a type parameter to store host-specific data, which in
// this case we're using `4` for.
let mut store = Store::new(&engine, ());
let instance = linker.instantiate(&mut store, &module)?;
let hello = instance.get_typed_func::<(), ()>(&mut store, "run")?;
// And finally we can call the wasm!
hello.call(&mut store, ())?;
Ok(())
}
},
} }
} }

View File

@ -16,8 +16,8 @@ uuid.workspace = true
anyhow.workspace = true anyhow.workspace = true
chrono.workspace = true chrono.workspace = true
capnp = "0.19.5" capnp = "0.17.2"
[build-dependencies] [build-dependencies]
capnpc = "0.19.0" capnpc = "0.17.2"

View File

@ -1,6 +1,6 @@
use capnp::message::{Builder, HeapAllocator}; use capnp::message::{Builder, HeapAllocator};
use capnp::message::{ReaderOptions, TypedReader}; use capnp::message::{ReaderOptions, TypedReader};
use capnp::serialize::{self, BufferSegments}; use capnp::serialize::{self, SliceSegments};
use capnp::traits::Owned; use capnp::traits::Owned;
use churn_domain::{Agent, Lease, LogEvent}; use churn_domain::{Agent, Lease, LogEvent};
@ -17,7 +17,7 @@ pub trait CapnpPackExt {
serialize::write_message_to_words(builder) serialize::write_message_to_words(builder)
} }
fn string_to_capnp<S>(mut content: &[u8]) -> TypedReader<BufferSegments<&[u8]>, S> fn string_to_capnp<S>(mut content: &[u8]) -> TypedReader<SliceSegments, S>
where where
S: Owned, S: Owned,
{ {
@ -47,9 +47,9 @@ impl CapnpPackExt for LogEvent {
let log_event = log_event.get()?; let log_event = log_event.get()?;
Ok(Self { Ok(Self {
id: uuid::Uuid::parse_str(log_event.get_id()?.to_str()?)?, id: uuid::Uuid::parse_str(log_event.get_id()?)?,
author: log_event.get_author()?.to_string()?, author: log_event.get_author()?.into(),
content: log_event.get_content()?.to_string()?, content: log_event.get_content()?.into(),
timestamp: chrono::DateTime::<chrono::Utc>::from_utc( timestamp: chrono::DateTime::<chrono::Utc>::from_utc(
chrono::NaiveDateTime::from_timestamp_opt(log_event.get_datetime(), 0).unwrap(), chrono::NaiveDateTime::from_timestamp_opt(log_event.get_datetime(), 0).unwrap(),
chrono::Utc, chrono::Utc,
@ -75,7 +75,7 @@ impl CapnpPackExt for Agent {
let item = item.get()?; let item = item.get()?;
Ok(Self { Ok(Self {
name: item.get_name()?.to_string()?, name: item.get_name()?.into(),
}) })
} }
} }
@ -98,8 +98,8 @@ impl CapnpPackExt for Lease {
let item = item.get()?; let item = item.get()?;
Ok(Self { Ok(Self {
id: uuid::Uuid::parse_str(item.get_id()?.to_str()?)?, id: uuid::Uuid::parse_str(item.get_id()?)?,
lease: uuid::Uuid::parse_str(item.get_lease()?.to_str()?)?, lease: uuid::Uuid::parse_str(item.get_lease()?)?,
}) })
} }
} }

View File

@ -128,7 +128,7 @@ pub mod log_event {
} }
} }
impl <'a,> ::capnp::traits::SetterInput<Owned<>> for Reader<'a,> { impl <'a,> ::capnp::traits::SetPointerBuilder for Reader<'a,> {
fn set_pointer_builder(mut pointer: ::capnp::private::layout::PointerBuilder<'_>, value: Self, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) } fn set_pointer_builder(mut pointer: ::capnp::private::layout::PointerBuilder<'_>, value: Self, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) }
} }
@ -151,8 +151,8 @@ pub mod log_event {
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None) ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None)
} }
#[inline] #[inline]
pub fn set_id(&mut self, value: impl ::capnp::traits::SetterInput<::capnp::text::Owned>) { pub fn set_id(&mut self, value: ::capnp::text::Reader<'_>) {
::capnp::traits::SetterInput::set_pointer_builder(self.builder.reborrow().get_pointer_field(0), value, false).unwrap() self.builder.reborrow().get_pointer_field(0).set_text(value);
} }
#[inline] #[inline]
pub fn init_id(self, size: u32) -> ::capnp::text::Builder<'a> { pub fn init_id(self, size: u32) -> ::capnp::text::Builder<'a> {
@ -167,8 +167,8 @@ pub mod log_event {
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None) ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None)
} }
#[inline] #[inline]
pub fn set_author(&mut self, value: impl ::capnp::traits::SetterInput<::capnp::text::Owned>) { pub fn set_author(&mut self, value: ::capnp::text::Reader<'_>) {
::capnp::traits::SetterInput::set_pointer_builder(self.builder.reborrow().get_pointer_field(1), value, false).unwrap() self.builder.reborrow().get_pointer_field(1).set_text(value);
} }
#[inline] #[inline]
pub fn init_author(self, size: u32) -> ::capnp::text::Builder<'a> { pub fn init_author(self, size: u32) -> ::capnp::text::Builder<'a> {
@ -183,8 +183,8 @@ pub mod log_event {
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(2), ::core::option::Option::None) ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(2), ::core::option::Option::None)
} }
#[inline] #[inline]
pub fn set_content(&mut self, value: impl ::capnp::traits::SetterInput<::capnp::text::Owned>) { pub fn set_content(&mut self, value: ::capnp::text::Reader<'_>) {
::capnp::traits::SetterInput::set_pointer_builder(self.builder.reborrow().get_pointer_field(2), value, false).unwrap() self.builder.reborrow().get_pointer_field(2).set_text(value);
} }
#[inline] #[inline]
pub fn init_content(self, size: u32) -> ::capnp::text::Builder<'a> { pub fn init_content(self, size: u32) -> ::capnp::text::Builder<'a> {
@ -309,11 +309,9 @@ pub mod log_event {
encoded_node: &ENCODED_NODE, encoded_node: &ENCODED_NODE,
nonunion_members: NONUNION_MEMBERS, nonunion_members: NONUNION_MEMBERS,
members_by_discriminant: MEMBERS_BY_DISCRIMINANT, members_by_discriminant: MEMBERS_BY_DISCRIMINANT,
members_by_name: MEMBERS_BY_NAME,
}; };
pub static NONUNION_MEMBERS : &[u16] = &[0,1,2,3]; pub static NONUNION_MEMBERS : &[u16] = &[0,1,2,3];
pub static MEMBERS_BY_DISCRIMINANT : &[u16] = &[]; pub static MEMBERS_BY_DISCRIMINANT : &[u16] = &[];
pub static MEMBERS_BY_NAME : &[u16] = &[1,2,3,0];
pub const TYPE_ID: u64 = 0xe78f_0c5b_590e_1932; pub const TYPE_ID: u64 = 0xe78f_0c5b_590e_1932;
} }
} }
@ -423,7 +421,7 @@ pub mod agent {
} }
} }
impl <'a,> ::capnp::traits::SetterInput<Owned<>> for Reader<'a,> { impl <'a,> ::capnp::traits::SetPointerBuilder for Reader<'a,> {
fn set_pointer_builder(mut pointer: ::capnp::private::layout::PointerBuilder<'_>, value: Self, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) } fn set_pointer_builder(mut pointer: ::capnp::private::layout::PointerBuilder<'_>, value: Self, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) }
} }
@ -446,8 +444,8 @@ pub mod agent {
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None) ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None)
} }
#[inline] #[inline]
pub fn set_name(&mut self, value: impl ::capnp::traits::SetterInput<::capnp::text::Owned>) { pub fn set_name(&mut self, value: ::capnp::text::Reader<'_>) {
::capnp::traits::SetterInput::set_pointer_builder(self.builder.reborrow().get_pointer_field(0), value, false).unwrap() self.builder.reborrow().get_pointer_field(0).set_text(value);
} }
#[inline] #[inline]
pub fn init_name(self, size: u32) -> ::capnp::text::Builder<'a> { pub fn init_name(self, size: u32) -> ::capnp::text::Builder<'a> {
@ -515,11 +513,9 @@ pub mod agent {
encoded_node: &ENCODED_NODE, encoded_node: &ENCODED_NODE,
nonunion_members: NONUNION_MEMBERS, nonunion_members: NONUNION_MEMBERS,
members_by_discriminant: MEMBERS_BY_DISCRIMINANT, members_by_discriminant: MEMBERS_BY_DISCRIMINANT,
members_by_name: MEMBERS_BY_NAME,
}; };
pub static NONUNION_MEMBERS : &[u16] = &[0]; pub static NONUNION_MEMBERS : &[u16] = &[0];
pub static MEMBERS_BY_DISCRIMINANT : &[u16] = &[]; pub static MEMBERS_BY_DISCRIMINANT : &[u16] = &[];
pub static MEMBERS_BY_NAME : &[u16] = &[0];
pub const TYPE_ID: u64 = 0xf4a4_cb97_342c_81a0; pub const TYPE_ID: u64 = 0xf4a4_cb97_342c_81a0;
} }
} }
@ -637,7 +633,7 @@ pub mod lease {
} }
} }
impl <'a,> ::capnp::traits::SetterInput<Owned<>> for Reader<'a,> { impl <'a,> ::capnp::traits::SetPointerBuilder for Reader<'a,> {
fn set_pointer_builder(mut pointer: ::capnp::private::layout::PointerBuilder<'_>, value: Self, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) } fn set_pointer_builder(mut pointer: ::capnp::private::layout::PointerBuilder<'_>, value: Self, canonicalize: bool) -> ::capnp::Result<()> { pointer.set_struct(&value.reader, canonicalize) }
} }
@ -660,8 +656,8 @@ pub mod lease {
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None) ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None)
} }
#[inline] #[inline]
pub fn set_id(&mut self, value: impl ::capnp::traits::SetterInput<::capnp::text::Owned>) { pub fn set_id(&mut self, value: ::capnp::text::Reader<'_>) {
::capnp::traits::SetterInput::set_pointer_builder(self.builder.reborrow().get_pointer_field(0), value, false).unwrap() self.builder.reborrow().get_pointer_field(0).set_text(value);
} }
#[inline] #[inline]
pub fn init_id(self, size: u32) -> ::capnp::text::Builder<'a> { pub fn init_id(self, size: u32) -> ::capnp::text::Builder<'a> {
@ -676,8 +672,8 @@ pub mod lease {
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None) ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None)
} }
#[inline] #[inline]
pub fn set_lease(&mut self, value: impl ::capnp::traits::SetterInput<::capnp::text::Owned>) { pub fn set_lease(&mut self, value: ::capnp::text::Reader<'_>) {
::capnp::traits::SetterInput::set_pointer_builder(self.builder.reborrow().get_pointer_field(1), value, false).unwrap() self.builder.reborrow().get_pointer_field(1).set_text(value);
} }
#[inline] #[inline]
pub fn init_lease(self, size: u32) -> ::capnp::text::Builder<'a> { pub fn init_lease(self, size: u32) -> ::capnp::text::Builder<'a> {
@ -761,11 +757,9 @@ pub mod lease {
encoded_node: &ENCODED_NODE, encoded_node: &ENCODED_NODE,
nonunion_members: NONUNION_MEMBERS, nonunion_members: NONUNION_MEMBERS,
members_by_discriminant: MEMBERS_BY_DISCRIMINANT, members_by_discriminant: MEMBERS_BY_DISCRIMINANT,
members_by_name: MEMBERS_BY_NAME,
}; };
pub static NONUNION_MEMBERS : &[u16] = &[0,1]; pub static NONUNION_MEMBERS : &[u16] = &[0,1];
pub static MEMBERS_BY_DISCRIMINANT : &[u16] = &[]; pub static MEMBERS_BY_DISCRIMINANT : &[u16] = &[];
pub static MEMBERS_BY_NAME : &[u16] = &[0,1];
pub const TYPE_ID: u64 = 0xb0d6_0854_c50e_5662; pub const TYPE_ID: u64 = 0xb0d6_0854_c50e_5662;
} }
} }

View File

@ -21,7 +21,6 @@ use event::EventService;
use lease::LeaseService; use lease::LeaseService;
use serde::Deserialize; use serde::Deserialize;
use serde_json::json; use serde_json::json;
use tokio::net::TcpListener;
use crate::db::Db; use crate::db::Db;
@ -95,8 +94,8 @@ async fn main() -> anyhow::Result<()> {
}); });
tracing::info!("churn server listening on {}", host); tracing::info!("churn server listening on {}", host);
let listener = TcpListener::bind(&host).await?; axum::Server::bind(&host)
axum::serve(listener, app.into_make_service()) .serve(app.into_make_service())
.await .await
.unwrap(); .unwrap();
} }

View File

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
dagger-sdk = "0.11.0" dagger-sdk = "0.2.2"
dagger-rust = {git = "https://git.front.kjuulh.io/kjuulh/dagger-components.git", ref = "main"} dagger-rust = "0.2.0"
tokio.workspace = true tokio.workspace = true
eyre = "*" eyre = "*"

View File

@ -19,22 +19,21 @@ async fn main() -> eyre::Result<()> {
let server = server let server = server
.with_env_variable("CHURN_DATABASE", "sled") .with_env_variable("CHURN_DATABASE", "sled")
.with_env_variable("CHURN_SLED_PATH", "/mnt/sled") .with_env_variable("CHURN_SLED_PATH", "/mnt/sled")
.with_mounted_cache("/mnt/sled", client.cache_volume("sled")) .with_mounted_cache("/mnt/sled", client.cache_volume("sled").id().await?)
.with_exec(vec!["churn-server", "serve", "--host", "0.0.0.0:3000"]) .with_exec(vec!["churn-server", "serve", "--host", "0.0.0.0:3000"])
.with_exposed_port(3000); .with_exposed_port(3000);
let server_service = server.as_service(); let server_id = server.id().await?;
let agent = build_container(client.clone(), "churn-agent").await?; let agent = build_container(client.clone(), "churn-agent").await?;
let agent = agent let agent = agent
.with_service_binding("churn-server", server_service.clone()) .with_service_binding("churn-server", server_id.clone())
.with_exec(vec!["churn-agent", "daemon", "--host", "0.0.0.0:3000"]) .with_exec(vec!["churn-agent", "daemon", "--host", "0.0.0.0:3000"])
.with_exposed_port(3000); .with_exposed_port(3000);
let agent_service = agent.as_service();
let churning = cli let churning = cli
.with_service_binding("churn-agent", agent_service) .with_service_binding("churn-agent", agent.id().await?)
.with_service_binding("churn-server", server_service) .with_service_binding("churn-server", server_id)
.with_env_variable("CHURN_SERVER", "http://churn-server:3000") .with_env_variable("CHURN_SERVER", "http://churn-server:3000")
.with_env_variable("CHURN_SERVER_TOKEN", "something") .with_env_variable("CHURN_SERVER_TOKEN", "something")
.with_env_variable("CHURN_AGENT", "http://churn-agent:3000") .with_env_variable("CHURN_AGENT", "http://churn-agent:3000")
@ -53,7 +52,7 @@ async fn main() -> eyre::Result<()> {
let stderr = churning.stderr().await?; let stderr = churning.stderr().await?;
println!("{stderr}"); println!("{stderr}");
churning.sync().await?; churning.exit_code().await?;
println!("Finished building churning..."); println!("Finished building churning...");
repl(churning).await?; //.with_entrypoint(vec!["churn"])).await?; repl(churning).await?; //.with_entrypoint(vec!["churn"])).await?;
@ -91,7 +90,7 @@ async fn repl(container: dagger_sdk::Container) -> eyre::Result<()> {
} }
} }
match container.sync().await { match container.exit_code().await {
Ok(_) => {} Ok(_) => {}
Err(_e) => { Err(_e) => {
//eprintln!("encountred error: {}", e); //eprintln!("encountred error: {}", e);
@ -102,8 +101,11 @@ async fn repl(container: dagger_sdk::Container) -> eyre::Result<()> {
Ok(()) Ok(())
} }
async fn build_container(client: Query, bin_name: &str) -> eyre::Result<dagger_sdk::Container> { async fn build_container(
let crates = &["crates/*", "ci"]; client: Arc<Query>,
bin_name: &str,
) -> eyre::Result<dagger_sdk::Container> {
let crates = &["crates/*", "ci", "examples/*"];
let debian_deps = &[ let debian_deps = &[
"libssl-dev", "libssl-dev",
"pkg-config", "pkg-config",

View File

@ -1,24 +1,7 @@
# yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json # yaml-language-server: $schema=https://git.front.kjuulh.io/kjuulh/cuddle/raw/branch/main/schemas/base.json
base: "git@git.front.kjuulh.io:kjuulh/cuddle-rust-cli-plan.git" base: "git@git.front.kjuulh.io:kjuulh/cuddle-base.git"
vars: vars:
service: "churn" service: "churn"
registry: kasperhermansen registry: kasperhermansen
please:
project:
owner: kjuulh
repository: churn
branch: main
settings:
api_url: https://git.front.kjuulh.io
components:
packages:
debian:
dev:
- capnproto
release:
- capnproto

View File

@ -0,0 +1,2 @@
[build]
target = "wasm32-wasi"

View File

@ -0,0 +1,15 @@
[package]
name = "agent-ping"
repository.workspace = true
description.workspace = true
readme.workspace = true
license-file.workspace = true
authors.workspace = true
version.workspace = true
edition.workspace = true
[lib]
crate-type = ["cdylib"]
[dependencies]
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", tag = "wit-bindgen-0.10.0" }

View File

@ -0,0 +1,15 @@
wit_bindgen::generate!({
world: "host",
exports: {
world: MyHost,
},
});
struct MyHost;
impl Host for MyHost {
fn run() {
print("Hello, world!");
}
}

View File

@ -0,0 +1,7 @@
package example:host
world host {
import print: func(msg: string)
export run: func()
}

View File

@ -0,0 +1,16 @@
[package]
name = "example-module"
repository.workspace = true
description.workspace = true
readme.workspace = true
license-file.workspace = true
authors.workspace = true
version.workspace = true
edition.workspace = true
[lib]
crate-type = ["cdylib"]
[dependencies]

View File

@ -0,0 +1,85 @@
use std::any::Any;
pub struct Orchestrator {}
impl Orchestrator {
pub fn cron(&self, cron: impl AsRef<str>) -> Scheduler {
Scheduler {}
}
pub fn query(&self, query: Query) -> Response {
Response::Tags { list: Vec::new() }
}
pub fn api<A: Any>(&self, request: A) -> Response {
Response::Tags { list: Vec::new() }
}
}
pub enum Query {
Tags(String),
}
pub enum Response {
Tags { list: Vec<String> },
}
#[derive(Clone)]
pub struct Scheduler {}
pub trait Ensure {
type EnsureInput;
type EnsureOutput;
fn ensure(&self, input: Self::EnsureInput) -> Self::EnsureOutput;
}
pub trait Action {
type Input;
type Output;
fn call(&self, input: Self::Input) -> Self::Output;
}
impl Scheduler {
pub fn schedule<A: Action>(&self, action: A) -> Scheduler {
return self.clone();
}
pub async fn apply(&self) {}
}
pub struct DebianPkg {}
impl DebianPkg {
pub fn require<'a>(pkgs: impl Into<Vec<&'a str>>) -> Self {
Self {}
}
}
impl Ensure for DebianPkg {
type EnsureInput = ();
type EnsureOutput = ();
fn ensure(&self, input: Self::EnsureInput) -> Self::EnsureOutput {}
}
impl Action for DebianPkg {
type Input = ();
type Output = ();
fn call(&self, input: Self::Input) -> Self::Output {}
}
pub async fn handle(orchestrator: Orchestrator) {
orchestrator
.cron("* * * * *")
.schedule(DebianPkg::require(vec!["openssl", "git"]))
.apply()
.await;
orchestrator
.cron("* * * * *")
.schedule(DebianPkg::require(vec!["openssl", "git"]))
.apply()
.await;
}

Binary file not shown.