diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 3525995bd..1e2845da2 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -28,5 +28,29 @@ "cwd": "${workspaceFolder}/core" }, }, + { + "type": "cargo", + "command": "run", + "label": "run periphery", + "options": { + "cwd": "${workspaceFolder}/periphery" + }, + }, + { + "type": "cargo", + "command": "run", + "label": "run core", + "options": { + "cwd": "${workspaceFolder}/core" + }, + }, + { + "type": "cargo", + "command": "run", + "label": "run cli", + "options": { + "cwd": "${workspaceFolder}/cli" + }, + } ] } \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 2a2bcafd4..d15a9ad86 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,9 +30,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.65" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" [[package]] name = "async-trait" @@ -209,6 +209,24 @@ dependencies = [ "uuid 1.1.2", ] +[[package]] +name = "builder" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "docker_client", + "dotenv", + "envy", + "git_client", + "mungos", + "serde", + "serde_derive", + "thiserror", + "tokio", + "types", +] + [[package]] name = "bumpalo" version = "3.11.0" @@ -304,6 +322,16 @@ dependencies = [ "clap", ] +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -379,6 +407,15 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" +[[package]] +name = "db_client" +version = "0.1.0" +dependencies = [ + "anyhow", + "mungos", + "types", +] + [[package]] name = "derivative" version = "2.2.0" @@ -401,12 +438,31 @@ dependencies = [ "subtle", ] +[[package]] +name = "docker_client" +version = "0.1.0" +dependencies = [ + "anyhow", + "bollard", + "thiserror", + "types", +] + [[package]] name = "dotenv" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if", +] + [[package]] name = "enum-as-inner" version = "0.4.0" @@ -419,6 +475,24 @@ dependencies = [ "syn", ] +[[package]] +name = "envy" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f47e0157f2cb54f5ae1bd371b30a2ae4311e1c028f575cd4e81de7353215965" +dependencies = [ + "serde", +] + +[[package]] +name = "fastrand" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +dependencies = [ + "instant", +] + [[package]] name = "flate2" version = "1.0.24" @@ -435,6 +509,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.1.0" @@ -554,6 +643,10 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "git_client" +version = "0.1.0" + [[package]] name = "h2" version = "0.3.14" @@ -694,6 +787,19 @@ dependencies = [ "want", ] +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "hyperlocal" version = "0.8.0" @@ -757,6 +863,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "ipconfig" version = "0.3.0" @@ -766,7 +881,7 @@ dependencies = [ "socket2", "widestring", "winapi", - "winreg", + "winreg 0.7.0", ] [[package]] @@ -970,12 +1085,15 @@ version = "0.1.0" dependencies = [ "axum", "axum-extra", - "bollard", + "docker_client", "dotenv", + "envy", + "git_client", "mungos", "serde", "serde_derive", "serde_json", + "slack_client_rs", "tokio", "tower", "tower-http", @@ -1010,6 +1128,24 @@ dependencies = [ "serde_json", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -1054,6 +1190,51 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" +[[package]] +name = "openssl" +version = "0.10.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "os_info" version = "3.5.1" @@ -1140,6 +1321,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkg-config" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + [[package]] name = "ppv-lite86" version = "0.2.16" @@ -1233,6 +1420,52 @@ dependencies = [ "bitflags", ] +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "reqwest" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg 0.10.1", +] + [[package]] name = "resolv-conf" version = "0.7.0" @@ -1310,6 +1543,16 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +[[package]] +name = "schannel" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +dependencies = [ + "lazy_static", + "windows-sys", +] + [[package]] name = "scopeguard" version = "1.1.0" @@ -1326,6 +1569,29 @@ dependencies = [ "untrusted", ] +[[package]] +name = "security-framework" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "0.9.0" @@ -1456,6 +1722,21 @@ dependencies = [ "autocfg", ] +[[package]] +name = "slack_client_rs" +version = "0.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "920a08baac5050ace95378c15984e2ee5552fdcd193302e0f80e294190b8c148" +dependencies = [ + "anyhow", + "reqwest", + "serde", + "serde_derive", + "serde_json", + "strum", + "strum_macros", +] + [[package]] name = "smallvec" version = "1.9.0" @@ -1548,6 +1829,20 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + [[package]] name = "termcolor" version = "1.1.3" @@ -1659,6 +1954,16 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.23.4" @@ -1945,6 +2250,12 @@ dependencies = [ "serde", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.4" @@ -1998,6 +2309,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.83" @@ -2145,6 +2468,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + [[package]] name = "zstd" version = "0.11.2+zstd.1.5.2" diff --git a/Cargo.toml b/Cargo.toml index 276d4bf7e..8ac4cf19f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,9 @@ members = [ "cli", "core", "periphery", - "types" + "builder", + "types", + "docker_client", + "git_client", + "db_client" ] \ No newline at end of file diff --git a/builder/Cargo.toml b/builder/Cargo.toml new file mode 100644 index 000000000..91777e9f0 --- /dev/null +++ b/builder/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "builder" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +docker = { package = "docker_client", path = "../docker_client" } +git = { package = "git_client", path = "../git_client" } +types = { path = "../types" } +tokio = { version = "1.21", features = ["full"] } +axum = { version = "0.5", features = ["ws"] } +serde = "1.0" +serde_derive = "1.0" +mungos = "0.2.24" +anyhow = "1.0" +thiserror = "1.0" +envy = "0.4" +dotenv = "0.15" \ No newline at end of file diff --git a/builder/src/config.rs b/builder/src/config.rs new file mode 100644 index 000000000..9db97a420 --- /dev/null +++ b/builder/src/config.rs @@ -0,0 +1,22 @@ +use std::{net::SocketAddr, str::FromStr}; + +use dotenv::dotenv; +use mungos::Deserialize; + +#[derive(Deserialize)] +struct Env { + port: u16, +} + +pub fn load() { + pub fn load() -> (SocketAddr) { + dotenv().ok(); + + let env = envy::from_env::().unwrap(); + + let socket_addr = SocketAddr::from_str(&format!("0.0.0.0:{}", env.port)) + .expect("failed to parse socket addr"); + + (socket_addr) + } +} diff --git a/builder/src/main.rs b/builder/src/main.rs new file mode 100644 index 000000000..922b1885b --- /dev/null +++ b/builder/src/main.rs @@ -0,0 +1,6 @@ +mod config; + +#[tokio::main] +async fn main() { + let (socket_addr) = config::load(); +} diff --git a/core/Cargo.toml b/core/Cargo.toml index f481c8182..678e81215 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -6,15 +6,18 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +docker = { package = "docker_client", path = "../docker_client" } +git = { package = "git_client", path = "../git_client" } types = { path = "../types" } tokio = { version = "1.21", features = ["full"] } axum = { version = "0.5", features = ["ws"] } axum-extra = { version = "0.3", features = ["spa"] } tower = { version = "0.4", features = ["full"] } tower-http = { version = "0.3", features = ["cors"] } +slack = { package = "slack_client_rs", version = "0.0.7" } mungos = "0.2.24" dotenv = "0.15" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" -bollard = "0.13" \ No newline at end of file +envy = "0.4" \ No newline at end of file diff --git a/core/src/api/mod.rs b/core/src/api/mod.rs new file mode 100644 index 000000000..4e38923e2 --- /dev/null +++ b/core/src/api/mod.rs @@ -0,0 +1,5 @@ +use axum::Router; + +pub fn router() -> Router { + Router::new() +} diff --git a/core/src/config.rs b/core/src/config.rs new file mode 100644 index 000000000..5d045d72f --- /dev/null +++ b/core/src/config.rs @@ -0,0 +1,29 @@ +use std::{ + net::{IpAddr, SocketAddr}, + str::FromStr, + time::Duration, +}; + +use dotenv::dotenv; +use mungos::{Deserialize, Mungos}; + +#[derive(Deserialize, Debug)] +struct Env { + port: u16, + mongo_uri: String, +} + +pub async fn load() -> (SocketAddr, Mungos) { + dotenv().ok(); + + let env = envy::from_env::().unwrap(); + + let socket_addr = SocketAddr::from_str(&format!("0.0.0.0:{}", env.port)) + .expect("failed to parse socket addr"); + + let mungos = Mungos::new(&env.mongo_uri, "monitor_core", Duration::from_secs(3), None) + .await + .expect("failed to connect to mongo"); + + (socket_addr, mungos) +} diff --git a/core/src/main.rs b/core/src/main.rs index 7f755fb76..a614bf553 100644 --- a/core/src/main.rs +++ b/core/src/main.rs @@ -1,2 +1,21 @@ +use axum::Router; +use docker::DockerClient; + +mod api; +mod config; + #[tokio::main] -async fn main() {} +async fn main() { + let docker_client = DockerClient::new().unwrap(); + let containers = docker_client.list_containers().await.unwrap(); + println!("{containers:#?}"); + + let (socket_addr, mungos) = config::load().await; + + let app = Router::new().nest("/api", api::router()); + + axum::Server::bind(&socket_addr) + .serve(app.into_make_service()) + .await + .expect("server crashed"); +} diff --git a/db_client/Cargo.toml b/db_client/Cargo.toml new file mode 100644 index 000000000..517411270 --- /dev/null +++ b/db_client/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "db_client" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +types = { path = "../types" } +mungos = "0.2.24" +anyhow = "1.0" \ No newline at end of file diff --git a/db_client/src/collections.rs b/db_client/src/collections.rs new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/db_client/src/collections.rs @@ -0,0 +1 @@ + diff --git a/db_client/src/lib.rs b/db_client/src/lib.rs new file mode 100644 index 000000000..f3d21151a --- /dev/null +++ b/db_client/src/lib.rs @@ -0,0 +1,21 @@ +use std::time::Duration; + +use mungos::{Collection, Mungos}; +use types::{Build, Deployment, Server, Update, User}; + +mod collections; + +pub struct DbClient { + pub users: Collection, + pub servers: Collection, + pub deployments: Collection, + pub builds: Collection, + pub updates: Collection, +} + +impl DbClient { + pub async fn new(mongo_uri: &str, app_name: &str) -> anyhow::Result { + let mungos = Mungos::new(mongo_uri, app_name, Duration::from_secs(3), None).await?; + todo!() + } +} diff --git a/docker_client/Cargo.toml b/docker_client/Cargo.toml new file mode 100644 index 000000000..b3f64df82 --- /dev/null +++ b/docker_client/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "docker_client" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +types = { path = "../types" } +bollard = "0.13" +anyhow = "1.0" +thiserror = "1.0" \ No newline at end of file diff --git a/docker_client/src/build.rs b/docker_client/src/build.rs new file mode 100644 index 000000000..db3bf519a --- /dev/null +++ b/docker_client/src/build.rs @@ -0,0 +1,9 @@ +use types::Build; + +use crate::DockerClient; + +impl DockerClient { + pub async fn build(&self, build: Build) -> anyhow::Result<()> { + todo!() + } +} diff --git a/docker_client/src/deploy.rs b/docker_client/src/deploy.rs new file mode 100644 index 000000000..d98894ba9 --- /dev/null +++ b/docker_client/src/deploy.rs @@ -0,0 +1,9 @@ +use types::Deployment; + +use crate::DockerClient; + +impl DockerClient { + pub async fn deploy(&self, deployment: Deployment) -> anyhow::Result<()> { + todo!() + } +} diff --git a/docker_client/src/lib.rs b/docker_client/src/lib.rs new file mode 100644 index 000000000..8d6e3fe53 --- /dev/null +++ b/docker_client/src/lib.rs @@ -0,0 +1,44 @@ +use anyhow::anyhow; +use bollard::{container::ListContainersOptions, Docker}; +use types::BasicContainerInfo; + +mod build; +mod deploy; + +pub struct DockerClient { + client: Docker, +} + +impl DockerClient { + pub fn new() -> anyhow::Result { + Ok(DockerClient { + client: Docker::connect_with_local_defaults()?, + }) + } + + pub async fn list_containers(&self) -> anyhow::Result> { + let res = self + .client + .list_containers(Some(ListContainersOptions:: { + all: true, + ..Default::default() + })) + .await? + .into_iter() + .map(|s| { + let info = BasicContainerInfo { + name: s + .names + .ok_or(anyhow!("no names on container"))? + .pop() + .ok_or(anyhow!("no names on container (empty vec)"))? + .replace("/", ""), + state: s.state.unwrap().parse().unwrap(), + status: s.status, + }; + Ok::<_, anyhow::Error>(info) + }) + .collect::>>()?; + Ok(res) + } +} diff --git a/git_client/Cargo.toml b/git_client/Cargo.toml new file mode 100644 index 000000000..86fa65e6f --- /dev/null +++ b/git_client/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "git_client" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/git_client/src/lib.rs b/git_client/src/lib.rs new file mode 100644 index 000000000..4626bc912 --- /dev/null +++ b/git_client/src/lib.rs @@ -0,0 +1,3 @@ +pub struct GitClient; + +impl GitClient {} diff --git a/types/src/lib.rs b/types/src/lib.rs index a2f1e9b31..467c05849 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -4,7 +4,11 @@ use mungos::ObjectId; use serde::{Deserialize, Serialize}; use strum_macros::{Display, EnumString}; -pub type PermissionsMap = HashMap; +pub type PermissionsMap = HashMap; + +pub type ServerId = String; +pub type DeploymentId = String; +pub type BuildId = String; #[derive(Serialize, Deserialize, Debug, Clone, Default)] #[serde(rename_all = "camelCase")] @@ -76,13 +80,13 @@ pub struct Deployment { #[serde(rename = "_id", skip_serializing_if = "Option::is_none")] pub id: Option, pub name: String, // must be formatted to be compat with docker - pub server_id: String, + pub server_id: ServerId, pub permissions: PermissionsMap, pub docker_run_args: DockerRunArgs, #[serde(skip_serializing_if = "Option::is_none")] pub is_core: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub build_id: Option, + pub build_id: Option, } #[derive(Serialize, Deserialize, Debug, Clone, Default)] @@ -151,38 +155,26 @@ pub struct DockerBuildArgs { pub dockerfile_path: Option, } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone, Default)] #[serde(rename_all = "camelCase")] pub struct DockerRunArgs { - #[serde(skip_serializing_if = "Option::is_none")] pub image: Option, pub ports: Vec, pub volumes: Vec, pub environment: Vec, - pub network: String, - pub restart: String, - #[serde(skip_serializing_if = "Option::is_none")] + pub network: Option, + pub restart: RestartMode, pub post_image: Option, - #[serde(skip_serializing_if = "Option::is_none")] pub container_user: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub docker_account: Option, + pub docker_account: Option, // the username of the dockerhub account } -impl Default for DockerRunArgs { - fn default() -> Self { - Self { - image: None, - ports: Vec::new(), - volumes: Vec::new(), - environment: Vec::new(), - network: "bridge".to_string(), - restart: "no".to_string(), - post_image: None, - container_user: None, - docker_account: None, - } - } +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(rename_all = "camelCase")] +pub struct BasicContainerInfo { + pub name: String, + pub state: ContainerState, + pub status: Option, } #[derive(Serialize, Deserialize, Debug, Clone, Default)] @@ -223,6 +215,13 @@ pub struct EnvironmentVar { pub value: String, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct Permission { + pub entity_type: EntityType, + pub id: String, + pub level: PermissionLevel, +} + #[derive(Serialize, Deserialize, Debug, Display, EnumString, PartialEq, Hash, Eq, Clone, Copy)] #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] @@ -252,3 +251,42 @@ pub enum Operation { PullDeployment, RecloneDeployment, } + +#[derive(Serialize, Deserialize, Debug, Display, EnumString, PartialEq, Hash, Eq, Clone, Copy)] +#[serde(rename_all = "snake_case")] +#[strum(serialize_all = "snake_case")] +pub enum PermissionLevel { + Read, + Write, +} + +#[derive(Serialize, Deserialize, Debug, Display, EnumString, PartialEq, Hash, Eq, Clone, Copy)] +#[serde(rename_all = "snake_case")] +#[strum(serialize_all = "snake_case")] +pub enum ContainerState { + Created, + Restarting, + Running, + Removing, + Paused, + Exited, + Dead, +} + +#[derive(Serialize, Deserialize, Debug, Display, EnumString, PartialEq, Hash, Eq, Clone, Copy)] +pub enum RestartMode { + #[serde(rename = "no")] + NoRestart, + #[serde(rename = "on-failure")] + OnFailure, + #[serde(rename = "always")] + Always, + #[serde(rename = "unless-stopped")] + UnlessStopped, +} + +impl Default for RestartMode { + fn default() -> RestartMode { + RestartMode::NoRestart + } +}