From 84976cf2a041295be8618b7210e5d8216981ae2e Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Tue, 17 Jan 2023 15:10:09 +0100 Subject: [PATCH 01/10] feat: build our images with the release profile Currently our containerfile builds images with the default debug profile, which means when `get_runtime_executable` is called it will try to install from a checked out local version of `shuttle-runtime`. --- Containerfile | 4 ++-- proto/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Containerfile b/Containerfile index 015bfae3f..00a0766c5 100644 --- a/Containerfile +++ b/Containerfile @@ -25,7 +25,7 @@ COPY --from=planner /build/recipe.json recipe.json RUN cargo chef cook --recipe-path recipe.json COPY --from=cache /build . ARG folder -RUN cargo build --bin shuttle-${folder} +RUN cargo build --bin shuttle-${folder} --release ARG RUSTUP_TOOLCHAIN FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-common @@ -43,7 +43,7 @@ FROM shuttle-common ARG folder COPY ${folder}/prepare.sh /prepare.sh RUN /prepare.sh -COPY --from=builder /build/target/debug/shuttle-${folder} /usr/local/bin/service +COPY --from=builder /build/target/release/shuttle-${folder} /usr/local/bin/service ARG RUSTUP_TOOLCHAIN ENV RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN} ENTRYPOINT ["/usr/local/bin/service"] diff --git a/proto/src/lib.rs b/proto/src/lib.rs index 122a2cb0c..549acb432 100644 --- a/proto/src/lib.rs +++ b/proto/src/lib.rs @@ -287,7 +287,7 @@ pub mod runtime { // When this library is compiled in debug mode with `cargo run --bin cargo-shuttle`, // install the checked-out local version of `shuttle-runtime if cfg!(debug_assertions) { - // Path to cargo-shuttle + // Path to calling crate root let manifest_dir = env!("CARGO_MANIFEST_DIR"); // Canonicalized path to shuttle-runtime From 22f54de67a15a73f696ccce93c767b1f75b3537c Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:38:15 +0100 Subject: [PATCH 02/10] feat: add build arg for cargo profile --- Containerfile | 7 +++-- Makefile | 3 ++ proto/src/lib.rs | 72 +++++++++++++++++++++++++++++------------------- 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/Containerfile b/Containerfile index 00a0766c5..58b5aee5c 100644 --- a/Containerfile +++ b/Containerfile @@ -25,7 +25,9 @@ COPY --from=planner /build/recipe.json recipe.json RUN cargo chef cook --recipe-path recipe.json COPY --from=cache /build . ARG folder -RUN cargo build --bin shuttle-${folder} --release +ARG CARGO_PROFILE +# if the PROD env isn't set, use default debug profile +RUN cargo build --bin shuttle-${folder} $(if [ "$CARGO_PROFILE" = "release" ]; then echo --${CARGO_PROFILE}; fi) ARG RUSTUP_TOOLCHAIN FROM rust:${RUSTUP_TOOLCHAIN}-buster as shuttle-common @@ -43,7 +45,8 @@ FROM shuttle-common ARG folder COPY ${folder}/prepare.sh /prepare.sh RUN /prepare.sh -COPY --from=builder /build/target/release/shuttle-${folder} /usr/local/bin/service +ARG CARGO_PROFILE +COPY --from=builder /build/target/${CARGO_PROFILE}/shuttle-${folder} /usr/local/bin/service ARG RUSTUP_TOOLCHAIN ENV RUSTUP_TOOLCHAIN=${RUSTUP_TOOLCHAIN} ENTRYPOINT ["/usr/local/bin/service"] diff --git a/Makefile b/Makefile index e57ba12b4..2f1f715b6 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,7 @@ CONTAINER_REGISTRY=public.ecr.aws/shuttle DD_ENV=production # make sure we only ever go to production with `--tls=enable` USE_TLS=enable +CARGO_PROFILE=release else DOCKER_COMPOSE_FILES=-f docker-compose.yml -f docker-compose.dev.yml STACK?=shuttle-dev @@ -57,6 +58,7 @@ DB_FQDN=db.unstable.shuttle.rs CONTAINER_REGISTRY=public.ecr.aws/shuttle-dev DD_ENV=unstable USE_TLS?=disable +CARGO_PROFILE=debug endif POSTGRES_EXTRA_PATH?=./extras/postgres @@ -112,6 +114,7 @@ shuttle-%: ${SRC} Cargo.lock docker buildx build \ --build-arg folder=$(*) \ --build-arg RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) \ + --build-arg CARGO_PROFILE=$(CARGO_PROFILE) \ --tag $(CONTAINER_REGISTRY)/$(*):$(COMMIT_SHA) \ --tag $(CONTAINER_REGISTRY)/$(*):$(TAG) \ --tag $(CONTAINER_REGISTRY)/$(*):latest \ diff --git a/proto/src/lib.rs b/proto/src/lib.rs index 7f2865f43..56af1fc8f 100644 --- a/proto/src/lib.rs +++ b/proto/src/lib.rs @@ -287,36 +287,50 @@ pub mod runtime { Ok((runtime, runtime_client)) } + /// If the calling crate is cargo-shuttle, try to install shuttle-runtime from + /// a local version if this library is compiled in debug mode or from the production + /// branch of the shuttle repo if it's compiled in release mode. + /// + /// If the calling crate is deployer, use the version of shuttle-runtime installed in + /// deployer/prepare.sh. + /// + /// **Important:** When called by deployer, this function expects that shuttle-runtime + /// was installed in prepare.sh. fn get_runtime_executable() -> PathBuf { - // When this library is compiled in debug mode with `cargo run --bin cargo-shuttle`, - // install the checked-out local version of `shuttle-runtime - if cfg!(debug_assertions) { - // Path to calling crate root - let manifest_dir = env!("CARGO_MANIFEST_DIR"); - - // Canonicalized path to shuttle-runtime - let path = std::fs::canonicalize(format!("{manifest_dir}/../runtime")) - .expect("failed to canonicalize path to runtime"); - - Command::new("cargo") - .arg("install") - .arg("shuttle-runtime") - .arg("--path") - .arg(path) - .output() - .expect("failed to install the shuttle runtime"); - // When this library is compiled in release mode with `cargo install cargo-shuttle`, - // install the latest released `shuttle-runtime` - } else { - Command::new("cargo") - .arg("install") - .arg("shuttle-runtime") - .arg("--git") - .arg("https://github.com/shuttle-hq/shuttle") - .arg("--branch") - .arg("production") - .output() - .expect("failed to install the shuttle runtime"); + let current_crate = env!("CARGO_PKG_NAME"); + + if current_crate == "cargo-shuttle" { + // When this library is compiled in debug mode with `cargo run --bin cargo-shuttle`, + // install the checked-out local version of `shuttle-runtime + if cfg!(debug_assertions) { + // Path to calling crate root + let manifest_dir = env!("CARGO_MANIFEST_DIR"); + + // Canonicalized path to shuttle-runtime for dev to work on windows + let path = std::fs::canonicalize(format!("{manifest_dir}/../runtime")) + .expect("path to shuttle-runtime does not exist or is invalid"); + + Command::new("cargo") + .arg("install") + .arg("shuttle-runtime") + .arg("--path") + .arg(path) + .output() + .expect("failed to install the shuttle runtime"); + + // When this library is compiled in release mode with `cargo install cargo-shuttle`, + // install the latest released `shuttle-runtime` + } else { + Command::new("cargo") + .arg("install") + .arg("shuttle-runtime") + .arg("--git") + .arg("https://github.com/shuttle-hq/shuttle") + .arg("--branch") + .arg("production") + .output() + .expect("failed to install the shuttle runtime"); + } } let cargo_home = home::cargo_home().expect("failed to find cargo home directory"); From 4436db81a2bb86b405364e7990063b35001ceaba Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Thu, 19 Jan 2023 12:40:09 +0100 Subject: [PATCH 03/10] refactor: update comment --- Containerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Containerfile b/Containerfile index 58b5aee5c..c34e174b0 100644 --- a/Containerfile +++ b/Containerfile @@ -26,7 +26,7 @@ RUN cargo chef cook --recipe-path recipe.json COPY --from=cache /build . ARG folder ARG CARGO_PROFILE -# if the PROD env isn't set, use default debug profile +# if CARGO_PROFILE is release, pass --release, else use default debug profile RUN cargo build --bin shuttle-${folder} $(if [ "$CARGO_PROFILE" = "release" ]; then echo --${CARGO_PROFILE}; fi) ARG RUSTUP_TOOLCHAIN From 4ac3a20b0c3dccc48218f9e0e8f94450a970a141 Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Thu, 19 Jan 2023 14:10:17 +0100 Subject: [PATCH 04/10] fix: broken codegen/axum test --- codegen/src/next/mod.rs | 4 +++- runtime/tests/resources/axum-wasm-expanded/src/lib.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/codegen/src/next/mod.rs b/codegen/src/next/mod.rs index 4548652f8..e03cfd858 100644 --- a/codegen/src/next/mod.rs +++ b/codegen/src/next/mod.rs @@ -307,7 +307,9 @@ pub(crate) fn wasi_bindings(app: App) -> proc_macro2::TokenStream { let (parts, mut body) = res.into_parts(); // wrap and serialize response parts as rmp - let response_parts = shuttle_next::ResponseWrapper::from(parts).into_rmp(); + let response_parts = shuttle_next::ResponseWrapper::from(parts) + .into_rmp() + .expect("failed to serialize response parts"); // write response parts parts_fd.write_all(&response_parts).unwrap(); diff --git a/runtime/tests/resources/axum-wasm-expanded/src/lib.rs b/runtime/tests/resources/axum-wasm-expanded/src/lib.rs index b4cbe2407..017cdda38 100644 --- a/runtime/tests/resources/axum-wasm-expanded/src/lib.rs +++ b/runtime/tests/resources/axum-wasm-expanded/src/lib.rs @@ -92,7 +92,9 @@ pub extern "C" fn __SHUTTLE_Axum_call( let (parts, mut body) = res.into_parts(); // wrap and serialize response parts as rmp - let response_parts = shuttle_next::ResponseWrapper::from(parts).into_rmp(); + let response_parts = shuttle_next::ResponseWrapper::from(parts) + .into_rmp() + .expect("failed to serialize response parts"); // write response parts parts_fd.write_all(&response_parts).unwrap(); From 913cbf712950b43549837638c077285f934e4bff Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Fri, 20 Jan 2023 10:16:28 +0100 Subject: [PATCH 05/10] feat: install wasm32-wasi target in deploy.sh --- deployer/prepare.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/deployer/prepare.sh b/deployer/prepare.sh index 119b2e834..571aa8cb6 100755 --- a/deployer/prepare.sh +++ b/deployer/prepare.sh @@ -15,6 +15,9 @@ shuttle-shared-db = { path = "/usr/src/shuttle/resources/shared-db" } shuttle-secrets = { path = "/usr/src/shuttle/resources/secrets" } shuttle-static-folder = { path = "/usr/src/shuttle/resources/static-folder" }' > $CARGO_HOME/config.toml +# Add the wasm32-wasi target +rustup target add wasm32-wasi + # Install the shuttle runtime cargo install shuttle-runtime --path "/usr/src/shuttle/runtime" From 560b625b987f4c0936f811e68027b8e9c50c67fa Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Fri, 20 Jan 2023 12:10:41 +0100 Subject: [PATCH 06/10] feat: build deps in `CARGO_PROFILE` --- Containerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Containerfile b/Containerfile index c34e174b0..5c98301e1 100644 --- a/Containerfile +++ b/Containerfile @@ -22,7 +22,7 @@ RUN cargo chef prepare --recipe-path recipe.json FROM shuttle-build AS builder COPY --from=planner /build/recipe.json recipe.json -RUN cargo chef cook --recipe-path recipe.json +RUN cargo chef cook $(if [ "$CARGO_PROFILE" = "release" ]; then echo --${CARGO_PROFILE}; fi) --recipe-path recipe.json COPY --from=cache /build . ARG folder ARG CARGO_PROFILE From 437927af30ac89f1a9d549a967e5e11441f91d9b Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Mon, 23 Jan 2023 10:09:02 +0100 Subject: [PATCH 07/10] feat: use closure to determine shuttle-runtime path --- Cargo.lock | 22 ++++----- cargo-shuttle/Cargo.toml | 1 + cargo-shuttle/src/lib.rs | 80 +++++++++++++++++++++++++++++++++ deployer/Cargo.toml | 1 + deployer/src/runtime_manager.rs | 24 ++++++++++ proto/src/lib.rs | 53 +--------------------- runtime/src/args.rs | 1 + 7 files changed, 120 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45e8e21b7..cb8b4de40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1438,7 +1438,7 @@ dependencies = [ "percent-encoding", "rustc-workspace-hack", "rustfix", - "semver 1.0.14", + "semver 1.0.16", "serde", "serde_ignored", "serde_json", @@ -1475,7 +1475,7 @@ dependencies = [ "native-tls", "pathdiff", "regex", - "semver 1.0.14", + "semver 1.0.16", "serde", "serde_derive", "serde_json", @@ -1517,6 +1517,7 @@ dependencies = [ "futures", "git2", "headers", + "home", "ignore", "indicatif", "indoc", @@ -1581,7 +1582,7 @@ checksum = "982a0cf6a99c350d7246035613882e376d58cebe571785abc5da4f648d53ac0a" dependencies = [ "camino", "cargo-platform", - "semver 1.0.14", + "semver 1.0.16", "serde", "serde_json", "thiserror", @@ -2065,7 +2066,7 @@ dependencies = [ "num_cpus", "rayon", "rustc-hash", - "semver 1.0.14", + "semver 1.0.16", "serde", "serde_derive", "serde_json", @@ -5673,7 +5674,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.14", + "semver 1.0.16", ] [[package]] @@ -5939,9 +5940,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.14" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" +checksum = "58bc9567378fc7690d6b2addae4e60ac2eeea07becb2c64b9f218b53865cba2a" dependencies = [ "serde", ] @@ -6267,6 +6268,7 @@ dependencies = [ "fqdn", "futures", "hex 0.4.3", + "home", "hyper", "hyper-reverse-proxy 0.5.2-dev (git+https://github.com/chesedo/hyper-reverse-proxy?branch=master)", "once_cell", @@ -8487,13 +8489,13 @@ dependencies = [ [[package]] name = "which" -version = "4.2.5" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" +checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" dependencies = [ "either", - "lazy_static", "libc", + "once_cell", ] [[package]] diff --git a/cargo-shuttle/Cargo.toml b/cargo-shuttle/Cargo.toml index 4d484c8e3..ce36c87dc 100644 --- a/cargo-shuttle/Cargo.toml +++ b/cargo-shuttle/Cargo.toml @@ -24,6 +24,7 @@ dirs = "4.0.0" flate2 = "1.0.25" futures = "0.3.25" git2 = "0.14.2" +home = "0.5.4" headers = "0.3.8" indicatif = "0.17.2" ignore = "0.4.18" diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index e12b43d6c..3027ee13f 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -4,6 +4,7 @@ pub mod config; mod init; mod provisioner_server; +use cargo::util::ToSemver; use shuttle_common::project::ProjectName; use shuttle_proto::runtime::{self, LoadRequest, StartRequest, SubscribeLogsRequest}; use std::collections::HashMap; @@ -40,6 +41,9 @@ use crate::args::{DeploymentCommand, ProjectCommand}; use crate::client::Client; use crate::provisioner_server::LocalProvisioner; +const VERSION: &str = env!("CARGO_PKG_VERSION"); +const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); + pub struct Shuttle { ctx: RequestContext, } @@ -410,11 +414,53 @@ impl Shuttle { Ipv4Addr::LOCALHOST.into(), run_args.port + 1, )); + + let get_runtime_executable = || { + let runtime_path = home::cargo_home() + .expect("failed to find cargo home dir") + .join("bin/shuttle-runtime"); + + if cfg!(debug_assertions) { + // Canonicalized path to shuttle-runtime for dev to work on windows + let path = std::fs::canonicalize(format!("{MANIFEST_DIR}/../runtime")) + .expect("path to shuttle-runtime does not exist or is invalid"); + + std::process::Command::new("cargo") + .arg("install") + .arg("shuttle-runtime") + .arg("--path") + .arg(path) + .output() + .expect("failed to install the shuttle runtime"); + } else { + // If the version of cargo-shuttle is different from shuttle-runtime, + // or it isn't installed, try to install shuttle-runtime from the production + // branch. + if let Err(err) = check_version(&runtime_path) { + trace!("{}", err); + + trace!("installing shuttle-runtime"); + std::process::Command::new("cargo") + .arg("install") + .arg("shuttle-runtime") + .arg("--git") + .arg("https://github.com/shuttle-hq/shuttle") + .arg("--branch") + .arg("production") + .output() + .expect("failed to install the shuttle runtime"); + }; + }; + + runtime_path + }; + let (mut runtime, mut runtime_client) = runtime::start( is_wasm, runtime::StorageManagerType::WorkingDir(working_directory.to_path_buf()), &format!("http://localhost:{}", run_args.port + 1), run_args.port + 2, + get_runtime_executable, ) .await .map_err(|err| { @@ -772,6 +818,40 @@ impl Shuttle { } } +fn check_version(runtime_path: &PathBuf) -> Result<()> { + let valid_version = VERSION.to_semver().unwrap(); + + if !runtime_path.try_exists()? { + bail!("shuttle-runtime is not installed"); + } + + // Get runtime version from shuttle-runtime cli + let runtime_version = std::process::Command::new("cargo") + .arg("shuttle-runtime") + .arg("--version") + .output() + .context("failed to check the shuttle-runtime version")? + .stdout; + + // Parse the version, splitting the version from the name and + // and pass it to `to_semver()`. + let runtime_version = std::str::from_utf8(&runtime_version) + .expect("shuttle-runtime version should be valid utf8") + .split_once(' ') + .expect("shuttle-runtime version should be in the `name version` format") + .1 + .to_semver() + .context("failed to convert runtime version to semver")?; + + if runtime_version == valid_version { + Ok(()) + } else { + Err(anyhow!( + "shuttle-runtime and cargo-shuttle are not the same version" + )) + } +} + pub enum CommandOutcome { Ok, DeploymentFailure, diff --git a/deployer/Cargo.toml b/deployer/Cargo.toml index 21672f357..4dad73991 100644 --- a/deployer/Cargo.toml +++ b/deployer/Cargo.toml @@ -19,6 +19,7 @@ crossbeam-channel = "0.5.6" flate2 = "1.0.25" fqdn = "0.2.3" futures = "0.3.25" +home = "0.5.4" hyper = { version = "0.14.23", features = ["client", "http1", "http2", "tcp" ] } # not great, but waiting for WebSocket changes to be merged hyper-reverse-proxy = { git = "https://github.com/chesedo/hyper-reverse-proxy", branch = "master" } diff --git a/deployer/src/runtime_manager.rs b/deployer/src/runtime_manager.rs index 4952ba9dd..be10eff20 100644 --- a/deployer/src/runtime_manager.rs +++ b/deployer/src/runtime_manager.rs @@ -8,6 +8,8 @@ use tracing::{info, instrument, trace}; use crate::deployment::deploy_layer; +const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); + #[derive(Clone)] pub struct RuntimeManager { legacy: Option>, @@ -80,11 +82,33 @@ impl RuntimeManager { Ok(runtime_client) } else { trace!("making new client"); + + let get_runtime_executable = || { + if cfg!(debug_assertions) { + // Canonicalized path to shuttle-runtime for dev to work on windows + let path = std::fs::canonicalize(format!("{MANIFEST_DIR}/../runtime")) + .expect("path to shuttle-runtime does not exist or is invalid"); + + std::process::Command::new("cargo") + .arg("install") + .arg("shuttle-runtime") + .arg("--path") + .arg(path) + .output() + .expect("failed to install the local version of shuttle-runtime"); + }; + + home::home_dir() + .expect("failed to find path to cargo home") + .join("bin/shuttle-runtime") + }; + let (process, runtime_client) = runtime::start( is_next, runtime::StorageManagerType::Artifacts(artifacts_path), provisioner_address, port, + get_runtime_executable, ) .await .context("failed to start shuttle runtime")?; diff --git a/proto/src/lib.rs b/proto/src/lib.rs index 56af1fc8f..a4d51a522 100644 --- a/proto/src/lib.rs +++ b/proto/src/lib.rs @@ -98,7 +98,6 @@ pub mod runtime { use std::{ convert::TryFrom, path::PathBuf, - process::Command, time::{Duration, SystemTime}, }; @@ -246,6 +245,7 @@ pub mod runtime { storage_manager_type: StorageManagerType, provisioner_address: &str, port: u16, + get_runtime_executable: impl FnOnce() -> PathBuf, ) -> anyhow::Result<(process::Child, runtime_client::RuntimeClient)> { let runtime_flag = if wasm { "--axum" } else { "--legacy" }; @@ -286,55 +286,4 @@ pub mod runtime { Ok((runtime, runtime_client)) } - - /// If the calling crate is cargo-shuttle, try to install shuttle-runtime from - /// a local version if this library is compiled in debug mode or from the production - /// branch of the shuttle repo if it's compiled in release mode. - /// - /// If the calling crate is deployer, use the version of shuttle-runtime installed in - /// deployer/prepare.sh. - /// - /// **Important:** When called by deployer, this function expects that shuttle-runtime - /// was installed in prepare.sh. - fn get_runtime_executable() -> PathBuf { - let current_crate = env!("CARGO_PKG_NAME"); - - if current_crate == "cargo-shuttle" { - // When this library is compiled in debug mode with `cargo run --bin cargo-shuttle`, - // install the checked-out local version of `shuttle-runtime - if cfg!(debug_assertions) { - // Path to calling crate root - let manifest_dir = env!("CARGO_MANIFEST_DIR"); - - // Canonicalized path to shuttle-runtime for dev to work on windows - let path = std::fs::canonicalize(format!("{manifest_dir}/../runtime")) - .expect("path to shuttle-runtime does not exist or is invalid"); - - Command::new("cargo") - .arg("install") - .arg("shuttle-runtime") - .arg("--path") - .arg(path) - .output() - .expect("failed to install the shuttle runtime"); - - // When this library is compiled in release mode with `cargo install cargo-shuttle`, - // install the latest released `shuttle-runtime` - } else { - Command::new("cargo") - .arg("install") - .arg("shuttle-runtime") - .arg("--git") - .arg("https://github.com/shuttle-hq/shuttle") - .arg("--branch") - .arg("production") - .output() - .expect("failed to install the shuttle runtime"); - } - } - - let cargo_home = home::cargo_home().expect("failed to find cargo home directory"); - - cargo_home.join("bin/shuttle-runtime") - } } diff --git a/runtime/src/args.rs b/runtime/src/args.rs index 57e78eced..9f0215970 100644 --- a/runtime/src/args.rs +++ b/runtime/src/args.rs @@ -4,6 +4,7 @@ use clap::{Parser, ValueEnum}; use tonic::transport::Endpoint; #[derive(Parser, Debug)] +#[command(version)] pub struct Args { /// Port to start runtime on #[arg(long)] From e112d74f9a7aa9fca1f6ec1f762100cc763d7728 Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:19:09 +0100 Subject: [PATCH 08/10] fix: path to runtime in docker deployer, clippy --- cargo-shuttle/src/lib.rs | 2 +- deployer/src/runtime_manager.rs | 38 +++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 3027ee13f..d09ae6d2d 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -818,7 +818,7 @@ impl Shuttle { } } -fn check_version(runtime_path: &PathBuf) -> Result<()> { +fn check_version(runtime_path: &Path) -> Result<()> { let valid_version = VERSION.to_semver().unwrap(); if !runtime_path.try_exists()? { diff --git a/deployer/src/runtime_manager.rs b/deployer/src/runtime_manager.rs index be10eff20..1364e1c76 100644 --- a/deployer/src/runtime_manager.rs +++ b/deployer/src/runtime_manager.rs @@ -85,22 +85,28 @@ impl RuntimeManager { let get_runtime_executable = || { if cfg!(debug_assertions) { - // Canonicalized path to shuttle-runtime for dev to work on windows - let path = std::fs::canonicalize(format!("{MANIFEST_DIR}/../runtime")) - .expect("path to shuttle-runtime does not exist or is invalid"); - - std::process::Command::new("cargo") - .arg("install") - .arg("shuttle-runtime") - .arg("--path") - .arg(path) - .output() - .expect("failed to install the local version of shuttle-runtime"); - }; - - home::home_dir() - .expect("failed to find path to cargo home") - .join("bin/shuttle-runtime") + // If we're running deployer natively, use the version of runtime from + // the repo. + let path = std::fs::canonicalize(format!("{MANIFEST_DIR}/../runtime")); + + if let Ok(path) = path { + std::process::Command::new("cargo") + .arg("install") + .arg("shuttle-runtime") + .arg("--path") + .arg(path) + .output() + .expect("failed to install the local version of shuttle-runtime"); + + return home::home_dir() + .expect("failed to find path to cargo home") + .join("bin/shuttle-runtime"); + } + } + + // If we're in a deployer built with the containerfile, use the runtime installed + // in deploy.sh + PathBuf::from("/usr/local/cargo/bin/shuttle-runtime") }; let (process, runtime_client) = runtime::start( From 70398a6c7b068388f6467ba493263065e8025ccd Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Mon, 23 Jan 2023 11:46:57 +0100 Subject: [PATCH 09/10] fix: incorrect function for cargo home --- deployer/src/runtime_manager.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployer/src/runtime_manager.rs b/deployer/src/runtime_manager.rs index 1364e1c76..b09c5020b 100644 --- a/deployer/src/runtime_manager.rs +++ b/deployer/src/runtime_manager.rs @@ -98,7 +98,7 @@ impl RuntimeManager { .output() .expect("failed to install the local version of shuttle-runtime"); - return home::home_dir() + return home::cargo_home() .expect("failed to find path to cargo home") .join("bin/shuttle-runtime"); } From dd652213c31fb867b4fdf838bde3dbfabe7de6ae Mon Sep 17 00:00:00 2001 From: oddgrd <29732646+oddgrd@users.noreply.github.com> Date: Mon, 23 Jan 2023 12:06:07 +0100 Subject: [PATCH 10/10] refactor: always use cargo_home for path to runtime in deployer --- deployer/src/runtime_manager.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/deployer/src/runtime_manager.rs b/deployer/src/runtime_manager.rs index b09c5020b..1693fa0c9 100644 --- a/deployer/src/runtime_manager.rs +++ b/deployer/src/runtime_manager.rs @@ -85,10 +85,12 @@ impl RuntimeManager { let get_runtime_executable = || { if cfg!(debug_assertions) { - // If we're running deployer natively, use the version of runtime from - // the repo. + // If we're running deployer natively, install shuttle-runtime using the + // version of runtime from the calling repo. let path = std::fs::canonicalize(format!("{MANIFEST_DIR}/../runtime")); + // The path will not be valid if we are in a deployer container, in which + // case we don't try to install and use the one installed in deploy.sh. if let Ok(path) = path { std::process::Command::new("cargo") .arg("install") @@ -97,16 +99,14 @@ impl RuntimeManager { .arg(path) .output() .expect("failed to install the local version of shuttle-runtime"); - - return home::cargo_home() - .expect("failed to find path to cargo home") - .join("bin/shuttle-runtime"); } } - // If we're in a deployer built with the containerfile, use the runtime installed - // in deploy.sh - PathBuf::from("/usr/local/cargo/bin/shuttle-runtime") + // If we're in a deployer built with the containerfile, the runtime will have + // been installed in deploy.sh. + home::cargo_home() + .expect("failed to find path to cargo home") + .join("bin/shuttle-runtime") }; let (process, runtime_client) = runtime::start(