From ff2ba8a6db4ea9488c1ad64e083acbd5684b0b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oddbj=C3=B8rn=20Gr=C3=B8dem?= <29732646+oddgrd@users.noreply.github.com> Date: Tue, 14 Mar 2023 18:22:27 +0000 Subject: [PATCH] refactor: rename legacy runtime to alpha (#713) * refactor: rename legacy runtime to alpha --- cargo-shuttle/src/lib.rs | 2 +- deployer/src/deployment/queue.rs | 6 +++--- deployer/src/deployment/run.rs | 6 +++--- deployer/src/runtime_manager.rs | 12 ++++++------ runtime/README.md | 10 +++++----- runtime/src/{legacy => alpha}/args.rs | 0 runtime/src/{legacy => alpha}/mod.rs | 16 ++++++++-------- runtime/src/lib.rs | 4 ++-- runtime/tests/integration/helpers.rs | 2 +- service/src/builder.rs | 6 +++--- service/tests/integration/build_crate.rs | 2 +- 11 files changed, 33 insertions(+), 33 deletions(-) rename runtime/src/{legacy => alpha}/args.rs (100%) rename runtime/src/{legacy => alpha}/mod.rs (97%) diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 20e6195c0..058a0eca5 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -457,7 +457,7 @@ impl Shuttle { let (is_wasm, executable_path) = match runtime { Runtime::Next(path) => (true, path), - Runtime::Legacy(path) => (false, path), + Runtime::Alpha(path) => (false, path), }; let provisioner = LocalProvisioner::new()?; diff --git a/deployer/src/deployment/queue.rs b/deployer/src/deployment/queue.rs index c48a20306..0087531be 100644 --- a/deployer/src/deployment/queue.rs +++ b/deployer/src/deployment/queue.rs @@ -397,7 +397,7 @@ async fn run_pre_deploy_tests( } /// This will store the path to the executable for each runtime, which will be the users project with -/// an embedded runtime for legacy, and a .wasm file for shuttle-next. +/// an embedded runtime for alpha, and a .wasm file for shuttle-next. #[instrument(skip(storage_manager, runtime, id))] async fn store_executable( storage_manager: &ArtifactsStorageManager, @@ -406,7 +406,7 @@ async fn store_executable( ) -> Result<()> { let executable_path = match runtime { Runtime::Next(path) => path, - Runtime::Legacy(path) => path, + Runtime::Alpha(path) => path, }; let new_executable_path = storage_manager.deployment_executable_path(id)?; @@ -559,7 +559,7 @@ ff0e55bda1ff01000000000000000000e0079c01ff12a55500280000", let build_p = storage_manager.builds_path().unwrap(); let executable_path = build_p.join("xyz"); - let runtime = Runtime::Legacy(executable_path.clone()); + let runtime = Runtime::Alpha(executable_path.clone()); let id = Uuid::new_v4(); fs::write(&executable_path, "barfoo").await.unwrap(); diff --git a/deployer/src/deployment/run.rs b/deployer/src/deployment/run.rs index aeff36140..b98d59416 100644 --- a/deployer/src/deployment/run.rs +++ b/deployer/src/deployment/run.rs @@ -182,7 +182,7 @@ impl Built { kill_old_deployments: impl futures::Future>, cleanup: impl FnOnce(SubscribeStopResponse) + Send + 'static, ) -> Result<()> { - // For legacy this is the path to the users project with an embedded runtime. + // For alpha this is the path to the users project with an embedded runtime. // For shuttle-next this is the path to the compiled .wasm file, which will be // used in the load request. let executable_path = storage_manager.deployment_executable_path(&self.id)?; @@ -198,7 +198,7 @@ impl Built { let address = SocketAddr::new(Ipv4Addr::LOCALHOST.into(), port); - let legacy_runtime_path = if self.is_next { + let alpha_runtime_path = if self.is_next { // The runtime client for next is the installed shuttle-next bin None } else { @@ -208,7 +208,7 @@ impl Built { let runtime_client = runtime_manager .lock() .await - .get_runtime_client(self.id, legacy_runtime_path.clone()) + .get_runtime_client(self.id, alpha_runtime_path.clone()) .await .map_err(Error::Runtime)?; diff --git a/deployer/src/runtime_manager.rs b/deployer/src/runtime_manager.rs index 529228032..5eaed5c6e 100644 --- a/deployer/src/runtime_manager.rs +++ b/deployer/src/runtime_manager.rs @@ -40,24 +40,24 @@ impl RuntimeManager { pub async fn get_runtime_client( &mut self, id: Uuid, - legacy_runtime_path: Option, + alpha_runtime_path: Option, ) -> anyhow::Result> { trace!("making new client"); let port = portpicker::pick_unused_port().context("failed to find available port")?; - let is_next = legacy_runtime_path.is_none(); + let is_next = alpha_runtime_path.is_none(); let get_runtime_executable = || { - if let Some(legacy_runtime) = legacy_runtime_path { + if let Some(alpha_runtime) = alpha_runtime_path { debug!( - "Starting legacy runtime at: {}", - legacy_runtime + "Starting alpha runtime at: {}", + alpha_runtime .clone() .into_os_string() .into_string() .unwrap_or_default() ); - legacy_runtime + alpha_runtime } else { if cfg!(debug_assertions) { debug!("Installing shuttle-next runtime in debug mode from local source"); diff --git a/runtime/README.md b/runtime/README.md index 6299f996a..1939551ca 100644 --- a/runtime/README.md +++ b/runtime/README.md @@ -1,7 +1,7 @@ # How to run ## The easy way -Both the legacy and next examples can be run using the local client: +Both the alpha and next examples can be run using the local client: ``` bash cd path/to/example @@ -56,7 +56,7 @@ curl localhost:8000/hello curl localhost:8000/goodbye ``` -## shuttle-legacy +## shuttle-alpha This will no longer load a `.so` file, the code to start the runtime will be codegened for all services. @@ -86,16 +86,16 @@ cargo build Then in another shell, load the service and start it up: ``` bash -# load +# load the service 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) +# start the service 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 -# stop (the service started in the legacy runtime can't currently be stopped) +# stop the service grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{}' localhost:6001 runtime.Runtime/Stop ``` diff --git a/runtime/src/legacy/args.rs b/runtime/src/alpha/args.rs similarity index 100% rename from runtime/src/legacy/args.rs rename to runtime/src/alpha/args.rs diff --git a/runtime/src/legacy/mod.rs b/runtime/src/alpha/mod.rs similarity index 97% rename from runtime/src/legacy/mod.rs rename to runtime/src/alpha/mod.rs index 521669051..3ff48029f 100644 --- a/runtime/src/legacy/mod.rs +++ b/runtime/src/alpha/mod.rs @@ -56,7 +56,7 @@ pub async fn start(loader: impl Loader + Send + 'static) { Server::builder().http2_keepalive_interval(Some(Duration::from_secs(60))); // We wrap the StorageManager trait object in an Arc rather than a Box, since we need - // to clone it in the `ProvisionerFactory::new` call in the legacy runtime `load` method. + // to clone it in the `ProvisionerFactory::new` call in the alpha runtime `load` method. // We might be able to optimize this by implementing clone for a Box // or by using static dispatch instead. let storage_manager: Arc = match args.storage_manager_type { @@ -69,21 +69,21 @@ pub async fn start(loader: impl Loader + Send + 'static) { }; let router = { - let legacy = Legacy::new( + let alpha = Alpha::new( provisioner_address, loader, storage_manager, Environment::Local, ); - let svc = RuntimeServer::new(legacy); + let svc = RuntimeServer::new(alpha); server_builder.add_service(svc) }; router.serve(addr).await.unwrap(); } -pub struct Legacy { +pub struct Alpha { // Mutexes are for interior mutability logs_rx: Mutex>>, logs_tx: UnboundedSender, @@ -96,7 +96,7 @@ pub struct Legacy { env: Environment, } -impl Legacy { +impl Alpha { pub fn new( provisioner_address: Endpoint, loader: L, @@ -154,7 +154,7 @@ where } #[async_trait] -impl Runtime for Legacy +impl Runtime for Alpha where L: Loader + Send + 'static, S: Service + Send + 'static, @@ -165,7 +165,7 @@ where secrets, service_name, } = request.into_inner(); - trace!(path, "loading legacy project"); + trace!(path, "loading alpha project"); let secrets = BTreeMap::from_iter(secrets.into_iter()); @@ -255,7 +255,7 @@ where &self, request: Request, ) -> Result, Status> { - trace!("legacy starting"); + trace!("alpha starting"); let service = self.service.lock().unwrap().deref_mut().take(); let service = service.unwrap(); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 5509506fa..31c11a7fa 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -214,14 +214,14 @@ //! //! You can also [open an issue or a discussion on GitHub](https://github.com/shuttle-hq/shuttle). //! -mod legacy; +mod alpha; mod logger; #[cfg(feature = "next")] mod next; mod provisioner_factory; +pub use alpha::{start, Alpha}; pub use async_trait::async_trait; -pub use legacy::{start, Legacy}; pub use logger::Logger; #[cfg(feature = "next")] pub use next::{AxumWasm, NextArgs}; diff --git a/runtime/tests/integration/helpers.rs b/runtime/tests/integration/helpers.rs index a894aec06..3b13eff51 100644 --- a/runtime/tests/integration/helpers.rs +++ b/runtime/tests/integration/helpers.rs @@ -42,7 +42,7 @@ pub async fn spawn_runtime(project_path: String, service_name: &str) -> Result (true, path), - Runtime::Legacy(path) => (false, path), + Runtime::Alpha(path) => (false, path), }; start_provisioner(DummyProvisioner, provisioner_address); diff --git a/service/src/builder.rs b/service/src/builder.rs index baf0082d8..5c5265130 100644 --- a/service/src/builder.rs +++ b/service/src/builder.rs @@ -17,7 +17,7 @@ use crate::NEXT_NAME; /// How to run/build the project pub enum Runtime { Next(PathBuf), - Legacy(PathBuf), + Alpha(PathBuf), } /// Given a project directory path, builds the crate @@ -70,7 +70,7 @@ pub async fn build_crate( Ok(if is_next { Runtime::Next(compilation.cdylibs[0].path.clone()) } else { - Runtime::Legacy(compilation.binaries[0].path.clone()) + Runtime::Alpha(compilation.binaries[0].path.clone()) }) } @@ -176,7 +176,7 @@ fn is_next(summary: &Summary) -> bool { .any(|dependency| dependency.package_name() == NEXT_NAME) } -/// Make sure the project is a binary for legacy projects. +/// Make sure the project is a binary for alpha projects. fn ensure_binary(manifest: &Manifest) -> anyhow::Result<()> { if manifest.targets().iter().any(|target| target.is_bin()) { Ok(()) diff --git a/service/tests/integration/build_crate.rs b/service/tests/integration/build_crate.rs index f36a46d5a..3e608fba4 100644 --- a/service/tests/integration/build_crate.rs +++ b/service/tests/integration/build_crate.rs @@ -30,7 +30,7 @@ async fn is_bin() { assert!(matches!( build_crate(Path::new(&project_path), false, tx).await, - Ok(Runtime::Legacy(_)) + Ok(Runtime::Alpha(_)) )); assert!(PathBuf::from(project_path) .join("target/debug/is-bin")