From 1fa6f98ade280e98979e528e58f8094b74b99b74 Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Mon, 15 May 2023 16:38:27 +0200 Subject: [PATCH] feat(cli): Integrate deploy commands Adds deploy related commands to the CLI: * app * namespace * ssh --- Cargo.lock | 380 +++++++++++++++++++++++++++++++++++++++++++-- lib/cli/Cargo.toml | 11 +- lib/cli/src/cli.rs | 23 ++- 3 files changed, 395 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b12bfb4e3cd..e3db6b23677 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -115,6 +115,9 @@ name = "anyhow" version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +dependencies = [ + "backtrace", +] [[package]] name = "arbitrary" @@ -178,6 +181,19 @@ dependencies = [ "wait-timeout", ] +[[package]] +name = "async-compression" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942c7cd7ae39e91bde4820d74132e9862e62c2f386c3aa90ccf55949f5bad63a" +dependencies = [ + "flate2", + "futures-core", + "memchr", + "pin-project-lite", + "tokio", +] + [[package]] name = "async-trait" version = "0.1.68" @@ -381,6 +397,9 @@ name = "bytesize" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38fcc2979eff34a4b84e1cf9a1e3da42a7d44b3b690a40cdcb23e3d556cfb2e5" +dependencies = [ + "serde", +] [[package]] name = "camino" @@ -436,7 +455,7 @@ dependencies = [ "serde_json", "syn 1.0.109", "tempfile", - "toml", + "toml 0.5.11", ] [[package]] @@ -622,6 +641,18 @@ dependencies = [ "unreachable", ] +[[package]] +name = "comfy-table" +version = "6.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e7b787b0dc42e8111badfdbe4c3059158ccb2db8780352fa1b01e8ccf45cc4d" +dependencies = [ + "crossterm", + "strum", + "strum_macros", + "unicode-width", +] + [[package]] name = "compiler-test-derive" version = "0.0.1" @@ -725,6 +756,15 @@ dependencies = [ "windows-sys 0.33.0", ] +[[package]] +name = "counter" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d458e66999348f56fd3ffcfbb7f7951542075ca8359687c703de6500c1ddccd" +dependencies = [ + "num-traits", +] + [[package]] name = "cpufeatures" version = "0.2.7" @@ -922,6 +962,31 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "crossterm" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" +dependencies = [ + "bitflags", + "crossterm_winapi", + "libc", + "mio", + "parking_lot 0.12.1", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ae1b35a484aa10e07fe0638d02301c5ad24de82d310ccbd2f3693da5f09bf1c" +dependencies = [ + "winapi", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -1013,14 +1078,78 @@ dependencies = [ "syn 2.0.15", ] +[[package]] +name = "cynic" +version = "2.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1afa0591b1021e427e548a1f0f147fe6168f6c7c7f7006bace77f28856051b8" +dependencies = [ + "cynic-proc-macros", + "reqwest", + "serde", + "serde_json", + "static_assertions", + "thiserror", +] + +[[package]] +name = "cynic-codegen" +version = "2.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a1bb05cc554f46079d0fa72abe995a2d32d0737d410a41da75b31e3f7ef768" +dependencies = [ + "counter", + "darling 0.13.4", + "graphql-parser", + "once_cell", + "proc-macro2", + "quote", + "strsim", + "syn 1.0.109", +] + +[[package]] +name = "cynic-proc-macros" +version = "2.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa595c4ed7a5374e0e58c5c34f9d93bd6b7d45062790963bd4b4c3c0bf520c4d" +dependencies = [ + "cynic-codegen", + "syn 1.0.109", +] + +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core 0.13.4", + "darling_macro 0.13.4", +] + [[package]] name = "darling" version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0558d22a7b463ed0241e993f76f09f30b126687447751a8638587b864e4b3944" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.20.1", + "darling_macro 0.20.1", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 1.0.109", ] [[package]] @@ -1036,13 +1165,24 @@ dependencies = [ "syn 2.0.15", ] +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core 0.13.4", + "quote", + "syn 1.0.109", +] + [[package]] name = "darling_macro" version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" dependencies = [ - "darling_core", + "darling_core 0.20.1", "quote", "syn 2.0.15", ] @@ -1279,7 +1419,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93b15496585fddd368466056b314fbb7e826a9ef1cf17b563d30dd2665846be2" dependencies = [ - "darling", + "darling 0.20.1", "proc-macro2", "quote", "syn 2.0.15", @@ -2169,6 +2309,20 @@ dependencies = [ "serde", ] +[[package]] +name = "jsonwebtoken" +version = "8.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" +dependencies = [ + "base64 0.21.0", + "pem", + "ring", + "serde", + "serde_json", + "simple_asn1", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -2592,6 +2746,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6842d8099b88d19a64158a6cfdc3e9ad82c738c041dab98280ef7ba98d64fa" +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -2835,6 +3000,15 @@ dependencies = [ "hmac", ] +[[package]] +name = "pem" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8835c273a76a90455d7344889b0964598e3316e2a79ede8e36f16bdcf2228b8" +dependencies = [ + "base64 0.13.1", +] + [[package]] name = "percent-encoding" version = "2.2.0" @@ -3326,6 +3500,7 @@ version = "0.11.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13293b639a097af28fc8a90f22add145a9c954e49d77da06263d58cf44d5fb91" dependencies = [ + "async-compression", "base64 0.21.0", "bytes", "encoding_rs", @@ -3807,6 +3982,24 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_path_to_error" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7f05c1d5476066defcdfacce1f52fc3cae3af1d3089727100c02ae92e5abbe0" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4" +dependencies = [ + "serde", +] + [[package]] name = "serde_urlencoded" version = "0.7.1" @@ -3916,6 +4109,27 @@ dependencies = [ "dirs", ] +[[package]] +name = "signal-hook" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -3937,6 +4151,18 @@ version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" +[[package]] +name = "simple_asn1" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adc4e5204eb1910f40f9cfa375f6f05b68c3abac4b6fd879c8ff5e7ae8a0a085" +dependencies = [ + "num-bigint", + "num-traits", + "thiserror", + "time 0.3.21", +] + [[package]] name = "slab" version = "0.4.8" @@ -4456,11 +4682,26 @@ dependencies = [ "serde", ] +[[package]] +name = "toml" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b403acf6f2bb0859c93c7f0d967cb4a75a7ac552100f9322faf64dc047669b21" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -4469,6 +4710,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13" dependencies = [ "indexmap", + "serde", + "serde_spanned", "toml_datetime", "winnow", ] @@ -4783,6 +5026,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "uuid" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "345444e32442451b267fc254ae85a209c64be56d2890e601a0c37ff0c3c5ecd2" +dependencies = [ + "getrandom", + "serde", +] + [[package]] name = "validator" version = "0.15.0" @@ -5022,7 +5275,7 @@ dependencies = [ "serde_json", "sha2", "tar", - "toml", + "toml 0.5.11", "tracing", "url", "validator", @@ -5044,7 +5297,7 @@ dependencies = [ "serde_json", "serde_yaml 0.9.21", "thiserror", - "toml", + "toml 0.5.11", ] [[package]] @@ -5303,6 +5556,25 @@ dependencies = [ "winapi", ] +[[package]] +name = "wasmer-api" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5b4926fe6e8d1569da694a0f6b5972ec61b809791fc1ce1ce2531f33c37895" +dependencies = [ + "anyhow", + "cynic", + "futures", + "reqwest", + "serde", + "serde_json", + "time 0.3.21", + "tracing", + "url", + "wasmer-deploy-schema", + "webc", +] + [[package]] name = "wasmer-bin-fuzz" version = "0.0.0" @@ -5419,7 +5691,7 @@ dependencies = [ "tempfile", "thiserror", "tldextract", - "toml", + "toml 0.5.11", "tracing", "tracing-subscriber 0.3.17", "unix_mode", @@ -5435,6 +5707,7 @@ dependencies = [ "wasmer-compiler-cranelift", "wasmer-compiler-llvm", "wasmer-compiler-singlepass", + "wasmer-deploy-cli", "wasmer-emscripten", "wasmer-object", "wasmer-registry 4.5.0", @@ -5553,6 +5826,70 @@ dependencies = [ "wasmer-types", ] +[[package]] +name = "wasmer-deploy-cli" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d2c9d8a5d924f2208f1ace85094a3ff4b1b412398c56244fcb1f68946ba3f9b" +dependencies = [ + "anyhow", + "clap 4.2.7", + "clap-verbosity-flag", + "comfy-table", + "dialoguer", + "futures", + "is-terminal", + "log", + "once_cell", + "regex", + "reqwest", + "semver 1.0.17", + "serde", + "serde_json", + "serde_yaml 0.8.26", + "time 0.3.21", + "tokio", + "toml 0.7.3", + "tracing", + "tracing-subscriber 0.3.17", + "url", + "uuid", + "wasmer-api", + "wasmer-deploy-schema", + "wasmer-deploy-util", + "wasmer-registry 4.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmer-toml", + "webc", +] + +[[package]] +name = "wasmer-deploy-schema" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b57e14e55dce44be4b2d506905fd8fb5fdfb2445c0053f49ea19c8f5a61bcda5" +dependencies = [ + "bytesize", + "jsonwebtoken", + "serde", + "serde_json", + "serde_path_to_error", + "time 0.3.21", + "url", + "uuid", + "wcgi-host", +] + +[[package]] +name = "wasmer-deploy-util" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ead21630e7e411e6be3c95eaadad804327bfb1d0454e706091dcc163d7abb86" +dependencies = [ + "serde", + "wasmer-deploy-schema", + "wasmparser 0.95.0", +] + [[package]] name = "wasmer-derive" version = "3.3.0" @@ -5686,10 +6023,10 @@ dependencies = [ "time 0.3.21", "tldextract", "tokio", - "toml", + "toml 0.5.11", "url", "wasmer-toml", - "wasmer-wasm-interface", + "wasmer-wasm-interface 3.3.0", "wasmparser 0.51.4", "webc", "whoami", @@ -5710,23 +6047,30 @@ dependencies = [ "futures-util", "graphql_client", "hex", + "indexmap", "indicatif", "lazy_static", "log", "lzma-rs", + "minisign", "regex", "reqwest", + "rpassword", + "rusqlite", "semver 1.0.17", "serde", "serde_json", "tar", "tempfile", "thiserror", + "time 0.3.21", "tldextract", "tokio", - "toml", + "toml 0.5.11", "url", "wasmer-toml", + "wasmer-wasm-interface 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmparser 0.51.4", "webc", "whoami", ] @@ -5759,7 +6103,7 @@ dependencies = [ "serde_json", "serde_yaml 0.9.21", "thiserror", - "toml", + "toml 0.5.11", ] [[package]] @@ -5919,6 +6263,18 @@ dependencies = [ "wat", ] +[[package]] +name = "wasmer-wasm-interface" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b31bad82289ef8ca59b098682c562f03a3b1bcd02e2110e4cce64bece47dbfba" +dependencies = [ + "either", + "nom 5.1.3", + "serde", + "wasmparser 0.51.4", +] + [[package]] name = "wasmer-wast" version = "3.3.0" diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 467d583a633..c9e4b9b0d9b 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -25,6 +25,7 @@ doc = false required-features = ["headless"] [dependencies] +# Repo-local dependencies. wasmer = { version = "=3.3.0", path = "../api", default-features = false } wasmer-compiler = { version = "=3.3.0", path = "../compiler", features = ["compiler"], optional = true } wasmer-compiler-cranelift = { version = "=3.3.0", path = "../compiler-cranelift", optional = true } @@ -41,6 +42,14 @@ wasmer-registry = { version = "4.5.0", path = "../registry", features = ["build- wasmer-object = { version = "=3.3.0", path = "../object", optional = true } virtual-fs = { version = "0.2.0", path = "../vfs", default-features = false, features = ["host-fs"] } virtual-net = { version = "0.1.0", path = "../vnet" } + +# Wasmer-owned dependencies. +webc = { version = "5.0" } +wapm-targz-to-pirita = "0.2.1" +wasmer-deploy-cli = { version = "0.1.7" } + +# Third-party dependencies. + atty = "0.2" colored = "2.0" anyhow = "1.0" @@ -64,7 +73,6 @@ regex = "1.6.0" toml = "0.5.9" url = "2.3.1" libc = { version = "^0.2", default-features = false } -webc = { version = "5.0" } isatty = "0.1.9" dialoguer = "0.10.2" tldextract = "0.6.0" @@ -82,7 +90,6 @@ wasm-coredump-builder = { version = "0.1.11", optional = true } tracing = { version = "0.1" } tracing-subscriber = { version = "0.3", features = [ "env-filter", "fmt" ] } clap-verbosity-flag = "2" -wapm-targz-to-pirita = "0.2.1" # NOTE: Must use different features for clap because the "color" feature does not # work on wasi due to the anstream dependency not compiling. diff --git a/lib/cli/src/cli.rs b/lib/cli/src/cli.rs index 33657c7f183..dfcaf117030 100644 --- a/lib/cli/src/cli.rs +++ b/lib/cli/src/cli.rs @@ -164,10 +164,19 @@ enum WasmerCLIOptions { /// (unstable) Run a WebAssembly file or WEBC container. RunUnstable(RunUnstable), + + // DEPLOY commands + #[clap(subcommand)] + App(wasmer_deploy_cli::cmd::app::CmdApp), + Ssh(wasmer_deploy_cli::cmd::ssh::CmdSsh), + #[clap(subcommand)] + Namespace(wasmer_deploy_cli::cmd::namespace::CmdNamespace), } impl WasmerCLIOptions { - fn execute(&self) -> Result<(), anyhow::Error> { + fn execute(self) -> Result<(), anyhow::Error> { + use wasmer_deploy_cli::cmd::CliCommand; + match self { Self::Run(options) => options.execute(), Self::SelfUpdate(options) => options.execute(), @@ -194,6 +203,11 @@ impl WasmerCLIOptions { Self::Whoami(whoami) => whoami.execute(), Self::Add(install) => install.execute(), Self::RunUnstable(run2) => run2.execute(), + + // Deploy commands. + Self::App(apps) => apps.run(), + Self::Ssh(ssh) => ssh.run(), + Self::Namespace(namespace) => namespace.run(), } } } @@ -244,12 +258,11 @@ fn wasmer_main_inner() -> Result<(), anyhow::Error> { let options = if cfg!(target_os = "linux") && binpath.ends_with("wasmer-binfmt-interpreter") { WasmerCLIOptions::Run(Run::from_binfmt_args()) } else { - match command.unwrap_or(&"".to_string()).as_ref() { + match command.unwrap_or(&String::new()).as_ref() { "add" | "cache" | "compile" | "config" | "create-obj" | "create-exe" | "help" | "gen-c-header" | "inspect" | "init" | "run" | "run-unstable" | "self-update" - | "validate" | "wast" | "binfmt" | "list" | "login" | "publish" => { - WasmerCLIOptions::parse() - } + | "validate" | "wast" | "binfmt" | "list" | "login" | "publish" | "app" + | "namespace" | "" => WasmerCLIOptions::parse(), _ => { WasmerCLIOptions::try_parse_from(args.iter()).unwrap_or_else(|e| { match e.kind() {