diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index d09ae6d2d..5fcc02eab 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -516,7 +516,6 @@ impl Shuttle { let start_request = StartRequest { deployment_id: id.as_bytes().to_vec(), - service_name, ip: addr.to_string(), }; diff --git a/deployer/src/deployment/run.rs b/deployer/src/deployment/run.rs index b0ce1e3be..c1123005a 100644 --- a/deployer/src/deployment/run.rs +++ b/deployer/src/deployment/run.rs @@ -218,7 +218,6 @@ impl Built { .unwrap(); run( self.id, - self.service_name, runtime_client, address, deployment_updater, @@ -280,7 +279,6 @@ async fn load( #[instrument(skip(runtime_client, deployment_updater, kill_recv, cleanup), fields(state = %State::Running))] async fn run( id: Uuid, - service_name: String, runtime_client: &mut RuntimeClient, address: SocketAddr, deployment_updater: impl DeploymentUpdater, @@ -294,7 +292,6 @@ async fn run( let start_request = tonic::Request::new(StartRequest { deployment_id: id.as_bytes().to_vec(), - service_name: service_name.clone(), ip: address.to_string(), }); @@ -310,10 +307,7 @@ async fn run( while let Ok(kill_id) = kill_recv.recv().await { if kill_id == id { - let stop_request = tonic::Request::new(StopRequest { - deployment_id: id.as_bytes().to_vec(), - service_name: service_name.clone(), - }); + let stop_request = tonic::Request::new(StopRequest {}); response = runtime_client.stop(stop_request).await; break; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index cfa96cd80..b1bb859ed 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -9,6 +9,9 @@ publish = false [[bin]] name = "rocket" +[[bin]] +name = "next" + [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } @@ -23,6 +26,7 @@ tonic = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter", "fmt"] } uuid = { workspace = true, features = ["v4"] } +# TODO: bump these crates to 6.0 when we bump rust to >= 1.66 wasi-common = "4.0.0" wasmtime = "4.0.0" wasmtime-wasi = "4.0.0" @@ -35,7 +39,7 @@ rocket = "0.5.0-rc.2" [dependencies.shuttle-common] workspace = true -features = ["wasm"] +features = ["wasm", "service"] [dependencies.shuttle-proto] workspace = true diff --git a/runtime/Makefile b/runtime/Makefile index 6472a425e..fd4fccbd0 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -3,8 +3,8 @@ all: axum axum: - cd ../tmp/axum-wasm-expanded; cargo build --target wasm32-wasi - cp ../tmp/axum-wasm-expanded/target/wasm32-wasi/debug/shuttle_axum_expanded.wasm axum.wasm + cd tests/resources/axum-wasm-expanded; cargo build --target wasm32-wasi + cp tests/resources/axum-wasm-expanded/target/wasm32-wasi/debug/shuttle_axum_expanded.wasm axum.wasm test: axum cargo test --all-features -- --nocapture diff --git a/runtime/README.md b/runtime/README.md index 5e1f1d910..d7caf894d 100644 --- a/runtime/README.md +++ b/runtime/README.md @@ -30,7 +30,7 @@ make test Load and run: ```bash -cargo run -- --axum --provisioner-address http://localhost:5000 +cargo run --bin next -- --port 6001 ``` In another terminal: @@ -40,24 +40,27 @@ In another terminal: grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic", "path": "/home//runtime/axum.wasm"}' localhost:6001 runtime.Runtime/Load # start -grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic", "deployment_id": "MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAw"}' localhost:6001 runtime.Runtime/Start +grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"deployment_id": "MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAw", "ip": "127.0.0.1:8000"}' localhost:6001 runtime.Runtime/Start -# subscribe to logs (unimplemented) +# subscribe to logs grpcurl -plaintext -import-path ../proto -proto runtime.proto localhost:6001 runtime.Runtime/SubscribeLogs # stop -grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic", "deployment_id": "MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAw"}' localhost:6001 runtime.Runtime/Stop +grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{}' localhost:6001 runtime.Runtime/Stop ``` Curl the service: ```bash -curl localhost:7002/hello +curl localhost:8000/hello -curl localhost:7002/goodbye +curl localhost:8000/goodbye ``` ## shuttle-legacy -This will no loger load a `.so` will the code to start the runtime will be codegened for all services. + +This will no longer load a `.so` file, the code to start the runtime will be +codegened for all services. + An example can be found in `src/bin/rocket.rs` which contains the secrets rocket example at the bottom and the codegen at the top. To test, first start a provisioner from the root directory using: @@ -69,7 +72,7 @@ docker-compose -f docker-compose.rendered.yml up provisioner Then in another shell, start the wrapped runtime using the clap CLI: ```bash -cargo run -- --port 6001 --storage-manager-type working-dir --storage-manager-path ./ +cargo run --bin rocket -- --port 6001 --storage-manager-type working-dir --storage-manager-path ./ ``` Or directly (this is the path hardcoded in `deployer::start`): @@ -87,7 +90,7 @@ Then in another shell, load the service and start it up: grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic", "path": "/home//examples/rocket/hello-world/target/debug/libhello_world.so", "secrets": {"MY_API_KEY": "test"}}' localhost:6001 runtime.Runtime/Load # run (this deployment id is default uuid encoded as base64) -grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic", "deployment_id": "MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAw", "ip": "127.0.0.1:8000"}' localhost:6001 runtime.Runtime/Start +grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"deployment_id": "MDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAw", "ip": "127.0.0.1:8000"}' localhost:6001 runtime.Runtime/Start # subscribe to logs grpcurl -plaintext -import-path ../proto -proto runtime.proto localhost:6001 runtime.Runtime/SubscribeLogs diff --git a/runtime/src/bin/next.rs b/runtime/src/bin/next.rs new file mode 100644 index 000000000..554cb882e --- /dev/null +++ b/runtime/src/bin/next.rs @@ -0,0 +1,40 @@ +use std::{ + net::{Ipv4Addr, SocketAddr}, + time::Duration, +}; + +use clap::Parser; +use shuttle_proto::runtime::runtime_server::RuntimeServer; +use shuttle_runtime::{AxumWasm, NextArgs}; +use tonic::transport::Server; +use tracing::trace; +use tracing_subscriber::{fmt, prelude::*, EnvFilter}; + +#[tokio::main(flavor = "multi_thread")] +async fn main() { + let args = NextArgs::parse(); + + // TODO: replace with tracing helper from main branch + let fmt_layer = fmt::layer(); + let filter_layer = EnvFilter::try_from_default_env() + .or_else(|_| EnvFilter::try_new("info")) + .unwrap(); + + tracing_subscriber::registry() + .with(filter_layer) + .with(fmt_layer) + .init(); + + trace!(args = ?args, "parsed args"); + + let addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), args.port); + + let mut server_builder = + Server::builder().http2_keepalive_interval(Some(Duration::from_secs(60))); + + let axum = AxumWasm::default(); + let svc = RuntimeServer::new(axum); + let router = server_builder.add_service(svc); + + router.serve(addr).await.unwrap(); +} diff --git a/runtime/src/args.rs b/runtime/src/legacy/args.rs similarity index 77% rename from runtime/src/args.rs rename to runtime/src/legacy/args.rs index 9f0215970..77af08cbd 100644 --- a/runtime/src/args.rs +++ b/runtime/src/legacy/args.rs @@ -14,14 +14,6 @@ pub struct Args { #[arg(long, default_value = "http://localhost:5000")] pub provisioner_address: Endpoint, - /// Is this runtime for a legacy service - #[arg(long, conflicts_with("axum"))] - pub legacy: bool, - - /// Is this runtime for an axum-wasm service - #[arg(long, conflicts_with("legacy"))] - pub axum: bool, - /// Type of storage manager to start #[arg(long, value_enum)] pub storage_manager_type: StorageManagerType, diff --git a/runtime/src/legacy/mod.rs b/runtime/src/legacy/mod.rs index d5fe5ab8b..ea042a856 100644 --- a/runtime/src/legacy/mod.rs +++ b/runtime/src/legacy/mod.rs @@ -36,7 +36,11 @@ use tonic::{ use tracing::{error, instrument, trace}; use uuid::Uuid; -use crate::{provisioner_factory::ProvisionerFactory, Args}; +use crate::provisioner_factory::ProvisionerFactory; + +use self::args::Args; + +mod args; pub async fn start( loader: impl Loader> + Send + 'static, diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 62fedf7f3..9d241f933 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1,9 +1,8 @@ -mod args; -mod axum; mod legacy; +mod next; mod provisioner_factory; -pub use args::{Args, StorageManagerType}; -pub use axum::AxumWasm; pub use legacy::{start, Legacy}; +pub use next::AxumWasm; +pub use next::NextArgs; pub use provisioner_factory::ProvisionerFactory; diff --git a/runtime/src/main.rs b/runtime/src/main.rs deleted file mode 100644 index 8a3a5f803..000000000 --- a/runtime/src/main.rs +++ /dev/null @@ -1,66 +0,0 @@ -use std::{ - net::{Ipv4Addr, SocketAddr}, - time::Duration, -}; - -use clap::Parser; -use shuttle_common::storage_manager::{ArtifactsStorageManager, WorkingDirStorageManager}; -use shuttle_proto::runtime::runtime_server::RuntimeServer; -use shuttle_runtime::{Args, AxumWasm, Legacy, StorageManagerType}; -use tonic::transport::Server; -use tracing::trace; -use tracing_subscriber::{fmt, prelude::*, EnvFilter}; - -#[tokio::main(flavor = "multi_thread")] -async fn main() { - let args = Args::parse(); - - let fmt_layer = fmt::layer(); - let filter_layer = EnvFilter::try_from_default_env() - .or_else(|_| EnvFilter::try_new("info")) - .unwrap(); - - tracing_subscriber::registry() - .with(filter_layer) - .with(fmt_layer) - .init(); - - trace!(args = ?args, "parsed args"); - - let addr = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), args.port); - - let provisioner_address = args.provisioner_address; - let mut server_builder = - Server::builder().http2_keepalive_interval(Some(Duration::from_secs(60))); - - let router = if args.legacy { - match args.storage_manager_type { - StorageManagerType::Artifacts => { - let legacy = Legacy::new( - provisioner_address, - ArtifactsStorageManager::new(args.storage_manager_path), - ); - - let svc = RuntimeServer::new(legacy); - server_builder.add_service(svc) - } - StorageManagerType::WorkingDir => { - let legacy = Legacy::new( - provisioner_address, - WorkingDirStorageManager::new(args.storage_manager_path), - ); - - let svc = RuntimeServer::new(legacy); - server_builder.add_service(svc) - } - } - } else if args.axum { - let axum = AxumWasm::default(); - let svc = RuntimeServer::new(axum); - server_builder.add_service(svc) - } else { - panic!("No runtime was selected"); - }; - - router.serve(addr).await.unwrap(); -} diff --git a/runtime/src/next/args.rs b/runtime/src/next/args.rs new file mode 100644 index 000000000..ccbb3ac6e --- /dev/null +++ b/runtime/src/next/args.rs @@ -0,0 +1,9 @@ +use clap::Parser; + +#[derive(Parser, Debug)] +#[command(version)] +pub struct NextArgs { + /// Port to start runtime on + #[arg(long)] + pub port: u16, +} diff --git a/runtime/src/axum/mod.rs b/runtime/src/next/mod.rs similarity index 99% rename from runtime/src/axum/mod.rs rename to runtime/src/next/mod.rs index 5bc798964..ccd30e321 100644 --- a/runtime/src/axum/mod.rs +++ b/runtime/src/next/mod.rs @@ -30,6 +30,10 @@ use wasmtime::{Engine, Linker, Module, Store}; use wasmtime_wasi::sync::net::UnixStream as WasiUnixStream; use wasmtime_wasi::{WasiCtx, WasiCtxBuilder}; +mod args; + +pub use self::args::NextArgs; + extern crate rmp_serde as rmps; const LOGS_FD: u32 = 20; @@ -94,9 +98,7 @@ impl Runtime for AxumWasm { &self, request: tonic::Request, ) -> Result, Status> { - let StartRequest { - deployment_id, ip, .. - } = request.into_inner(); + let StartRequest { deployment_id, ip } = request.into_inner(); let address = SocketAddr::from_str(&ip) .context("invalid socket address")