From 8e600ba3b6c03f19c2b8c1816deb33e848a67196 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Sun, 12 Mar 2023 16:26:15 -0700 Subject: [PATCH] Rename the project to Synchronik --- Cargo.toml | 7 ++++--- README.adoc | 13 +++++++------ api-description.yml | 8 ++++---- apidocs/api-description.json | 2 +- ci.janky.yml => ci.synchronik.yml | 2 +- examples/server.yml | 14 +++++++------- src/agent/main.rs | 6 +++--- src/server/config.rs | 8 ++++---- src/server/main.rs | 15 ++++++++------- src/server/routes.rs | 14 +++++++------- views/_navbar.hbs | 2 +- views/index.hbs | 2 +- 12 files changed, 48 insertions(+), 45 deletions(-) rename ci.janky.yml => ci.synchronik.yml (69%) diff --git a/Cargo.toml b/Cargo.toml index 4c35ce2..8ee11a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,14 @@ [package] -name = "janky" +name = "synchronik" version = "0.1.0" edition = "2021" [[bin]] -name = "janky-server" +name = "synchronik-server" path = "src/server/main.rs" [[bin]] -name = "janky-agent" +name = "synchronik-agent" path = "src/agent/main.rs" [dependencies] @@ -30,6 +30,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1" serde_yaml = "0.9" sqlx = { version = "~0.6", features = ["chrono", "json", "migrate", "offline", "sqlite", "uuid", "runtime-async-std-rustls"] } +subprocess = "0.2" tide = "0" uuid = { version = "1", features = ["v4", "serde"]} url = "2" diff --git a/README.adoc b/README.adoc index 5e652c2..48ab706 100644 --- a/README.adoc +++ b/README.adoc @@ -1,14 +1,15 @@ -= Janky CI += Synchronik -Janky is a simple CI system built in Rust. This is performative coding and not -intended to be a production system you can actually use. +Synchronik is a simple task execution system built in Rust. This is +performative coding and not intended to be a production system you can actually +use. * Two binaries: - * `janky-server` + * `synchronik-server` * Listens HTTP - * Does web shit + * Does web things * Interacts with agents - * `janky-agent`: + * `synchronik-agent`: * Run workloads * Listen HTTP * executes commands diff --git a/api-description.yml b/api-description.yml index b9a15f5..62c021e 100644 --- a/api-description.yml +++ b/api-description.yml @@ -2,11 +2,11 @@ openapi: "3.0.0" info: description: | - Janky API v1 defintion + Synchronik API v1 defintion version: "1.0.0" - title: Janky APIs + title: Synchronik APIs contact: - email: "rtyler+janky@brokenco.de" + email: "rtyler+synchronik@brokenco.de" license: name: "AGPL v3.0" url: "https://www.gnu.org/licenses/agpl-3.0.en.html" @@ -33,7 +33,7 @@ paths: - in: path name: name required: true - example: 'janky' + example: 'synchronik' schema: type: string responses: diff --git a/apidocs/api-description.json b/apidocs/api-description.json index 2a72072..90eff5e 100644 --- a/apidocs/api-description.json +++ b/apidocs/api-description.json @@ -1 +1 @@ -{"openapi":"3.0.0","info":{"description":"Janky API v1 defintion\n","version":"1.0.0","title":"Janky APIs","contact":{"email":"rtyler+janky@brokenco.de"},"license":{"name":"AGPL v3.0","url":"https://www.gnu.org/licenses/agpl-3.0.en.html"}},"servers":[{"url":"http://localhost:8000","description":"Local dev server"},{"url":"http://localhost:9000","description":"Local dev agent"}],"tags":[{"name":"agent","description":"Agent APIs"},{"name":"server","description":"Server APIs"}],"paths":{"/api/v1/projects/{name}":{"post":{"tags":["server"],"summary":"Trigger execution for this project","description":null,"parameters":[{"in":"path","name":"name","required":true,"example":"janky","schema":{"type":"string"}}],"responses":{"404":{"summary":"No project configured by that name"},"200":{"summary":"Execution has been triggered"}}}},"/api/v1/capabilities":{"get":{"tags":["agent"],"summary":"Retrieve a list of capabilities of this agent","description":null,"responses":{"200":{"description":"Getting capabilities","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CapsResponse"}}}}}}},"/api/v1/execute":{"put":{"tags":["agent"],"summary":"Execute a series of commands on this agent","description":null,"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CommandRequest"},"example":{"commands":[{"script":"echo \"Hi\""}]}}}},"responses":{"201":{"description":"Successfully accepted the commands for execution","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CommandResponse"}}}},"409":{"description":"Returned when the agent is busy with another series of commands"}}}}},"components":{"schemas":{"CapsResponse":{"type":"object","properties":{"caps":{"type":"array","items":{"$ref":"#/components/schemas/Capability"}}}},"Capability":{"type":"object","properties":{"name":{"type":"string"},"path":{"type":"string"},"data":{"type":"object"}}},"Command":{"type":"object","properties":{"script":{"type":"string","description":"A script that can be exec()'d on the agent"}}},"CommandRequest":{"type":"object","properties":{"commands":{"type":"array","items":{"$ref":"#/components/schemas/Command"}}}},"CommandResponse":{"type":"object","properties":{"uuid":{"type":"string","format":"uuid"},"stream":{"description":"URL to streaming WebSockets logs","type":"string","format":"url"},"task":{"description":"URL to the task metadata","type":"string","format":"url"},"log":{"description":"URL to the raw log of the task run","type":"string","format":"url"}}}}}} +{"openapi":"3.0.0","info":{"description":"Synchronik API v1 defintion\n","version":"1.0.0","title":"Synchronik APIs","contact":{"email":"rtyler+synchronik@brokenco.de"},"license":{"name":"AGPL v3.0","url":"https://www.gnu.org/licenses/agpl-3.0.en.html"}},"servers":[{"url":"http://localhost:8000","description":"Local dev server"},{"url":"http://localhost:9000","description":"Local dev agent"}],"tags":[{"name":"agent","description":"Agent APIs"},{"name":"server","description":"Server APIs"}],"paths":{"/api/v1/projects/{name}":{"post":{"tags":["server"],"summary":"Trigger execution for this project","description":null,"parameters":[{"in":"path","name":"name","required":true,"example":"synchronik","schema":{"type":"string"}}],"responses":{"404":{"summary":"No project configured by that name"},"200":{"summary":"Execution has been triggered"}}}},"/api/v1/capabilities":{"get":{"tags":["agent"],"summary":"Retrieve a list of capabilities of this agent","description":null,"responses":{"200":{"description":"Getting capabilities","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CapsResponse"}}}}}}},"/api/v1/execute":{"put":{"tags":["agent"],"summary":"Execute a series of commands on this agent","description":null,"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CommandRequest"},"example":{"commands":[{"script":"echo \"Hi\""}]}}}},"responses":{"201":{"description":"Successfully accepted the commands for execution","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CommandResponse"}}}},"409":{"description":"Returned when the agent is busy with another series of commands"}}}}},"components":{"schemas":{"CapsResponse":{"type":"object","properties":{"caps":{"type":"array","items":{"$ref":"#/components/schemas/Capability"}}}},"Capability":{"type":"object","properties":{"name":{"type":"string"},"path":{"type":"string"},"data":{"type":"object"}}},"Command":{"type":"object","properties":{"script":{"type":"string","description":"A script that can be exec()'d on the agent"}}},"CommandRequest":{"type":"object","properties":{"commands":{"type":"array","items":{"$ref":"#/components/schemas/Command"}}}},"CommandResponse":{"type":"object","properties":{"uuid":{"type":"string","format":"uuid"},"stream":{"description":"URL to streaming WebSockets logs","type":"string","format":"url"},"task":{"description":"URL to the task metadata","type":"string","format":"url"},"log":{"description":"URL to the raw log of the task run","type":"string","format":"url"}}}}}} diff --git a/ci.janky.yml b/ci.synchronik.yml similarity index 69% rename from ci.janky.yml rename to ci.synchronik.yml index e3a82dc..750221a 100644 --- a/ci.janky.yml +++ b/ci.synchronik.yml @@ -1,5 +1,5 @@ --- -# This is a Janky formatted YAML file. Using YAML for now to make hacking on +# This is a Synchronik formatted YAML file. Using YAML for now to make hacking on # this quicker and easier needs: diff --git a/examples/server.yml b/examples/server.yml index 54df98d..cfd9f52 100644 --- a/examples/server.yml +++ b/examples/server.yml @@ -5,22 +5,22 @@ agents: 'Duplicate Local': url: 'http://localhost:9000' projects: - 'janky': + 'synchronik': description: | - Self-hosted Janky project - filename: 'ci.janky.yml' + Self-hosted project + filename: 'ci.synchronik.yml' scm: github: owner: 'rtyler' - repo: 'janky' + repo: 'synchronik' ref: 'main' - 'janky with spaces': + 'with spaces': description: A test configuration with spaces in the name - filename: 'ci.janky.yml' + filename: 'ci.synchronik.yml' scm: github: owner: 'rtyler' - repo: 'janky' + repo: 'synchronik' ref: 'main' # The filetype Git is not yet supported #- type: 'git' diff --git a/src/agent/main.rs b/src/agent/main.rs index e3f183a..d20560c 100644 --- a/src/agent/main.rs +++ b/src/agent/main.rs @@ -5,8 +5,8 @@ use std::path::PathBuf; use async_std::channel::{bounded, Receiver, Sender}; use dotenv::dotenv; -use janky::CommandRequest; use log::*; +use synchronik::CommandRequest; use uuid::Uuid; const AGENT_LOGS_DIR: &str = "agent-logs"; @@ -20,13 +20,13 @@ mod routes { * GET / */ pub async fn index(_req: Request) -> Result { - Ok("Hello World from the Janky Agent".into()) + Ok("Hello World from the Synchronik Agent".into()) } pub mod api { use crate::caps::*; use crate::*; - use janky::{CommandRequest, CommandResponse}; + use synchronik::{CommandRequest, CommandResponse}; use tide::{Body, Request, Response, StatusCode}; use uuid::Uuid; diff --git a/src/server/config.rs b/src/server/config.rs index ee0ef9f..90a5871 100644 --- a/src/server/config.rs +++ b/src/server/config.rs @@ -6,10 +6,10 @@ use url::Url; use crate::AppState; /* - * Representation of the Janky YAML format + * Representation of the Synchronik YAML format */ #[derive(Clone, Debug, Deserialize)] -pub struct JankyYml { +pub struct Yml { pub needs: Vec, pub commands: Vec, } @@ -44,11 +44,11 @@ pub struct Project { pub struct Agent { pub name: String, pub url: Url, - pub capabilities: Vec, + pub capabilities: Vec, } impl Agent { - pub fn new(name: String, url: Url, capabilities: Vec) -> Self { + pub fn new(name: String, url: Url, capabilities: Vec) -> Self { Self { name, url, diff --git a/src/server/main.rs b/src/server/main.rs index 7167bd2..53da272 100644 --- a/src/server/main.rs +++ b/src/server/main.rs @@ -1,5 +1,5 @@ /* - * This is the main Janky entrypoint for the server" + * This is the main Synchronik entrypoint for the server */ #[macro_use] @@ -93,7 +93,7 @@ async fn main() -> Result<(), tide::Error> { let database_url = std::env::var("DATABASE_URL").unwrap_or(":memory:".to_string()); let pool = SqlitePool::connect(&database_url).await?; - /* If janky-server is running in memory, make sure the database is set up properly */ + /* If synchronik-server is running in memory, make sure the database is set up properly */ if database_url == ":memory:" { sqlx::migrate!().run(&pool).await?; } @@ -118,10 +118,11 @@ async fn main() -> Result<(), tide::Error> { for (name, agent) in config.agents.iter() { debug!("Requesting capabilities from agent: {:?}", agent); - let response: janky::CapsResponse = reqwest::get(agent.url.join("/api/v1/capabilities")?) - .await? - .json() - .await?; + let response: synchronik::CapsResponse = + reqwest::get(agent.url.join("/api/v1/capabilities")?) + .await? + .json() + .await?; state.agents.push(Agent::new( name.to_string(), agent.url.clone(), @@ -177,7 +178,7 @@ async fn main() -> Result<(), tide::Error> { #[cfg(test)] mod tests { use super::*; - use janky::*; + use synchronik::*; #[test] fn agent_can_meet_false() { diff --git a/src/server/routes.rs b/src/server/routes.rs index a2c43bc..55cc92f 100644 --- a/src/server/routes.rs +++ b/src/server/routes.rs @@ -46,7 +46,7 @@ pub async fn project(req: Request>) -> Result { } pub mod api { - use crate::config::{JankyYml, Scm}; + use crate::config::{Scm, Yml}; use crate::AppState; use log::*; use serde::Deserialize; @@ -88,18 +88,18 @@ pub mod api { &project.filename, ) .await?; - let jankyfile: JankyYml = serde_yaml::from_str(&res.text().await?)?; - debug!("text: {:?}", jankyfile); + let config_file: Yml = serde_yaml::from_str(&res.text().await?)?; + debug!("text: {:?}", config_file); for agent in &state.agents { - if agent.can_meet(&jankyfile.needs) { + if agent.can_meet(&config_file.needs) { debug!("agent: {:?} can meet our needs", agent); - let commands: Vec = jankyfile + let commands: Vec = config_file .commands .iter() - .map(|c| janky::Command::with_script(c)) + .map(|c| synchronik::Command::with_script(c)) .collect(); - let commands = janky::CommandRequest { commands }; + let commands = synchronik::CommandRequest { commands }; let client = reqwest::Client::new(); let _res = client .put( diff --git a/views/_navbar.hbs b/views/_navbar.hbs index 260465f..da2f9c1 100644 --- a/views/_navbar.hbs +++ b/views/_navbar.hbs @@ -1,6 +1,6 @@