Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get runtime binary from cargo install #578

Merged
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ jobs:
- restore-cargo-cache
- install-protoc
- run: cargo fmt --all --check
- run: cargo install cargo-sort
# TODO: this is incompatible with workspace inheritance, uncomment when
# https://github.com/DevinR528/cargo-sort/pull/29 is merged
# - run: cargo install cargo-sort
# - run: cargo sort --check --workspace
- run: cargo check --workspace --all-targets
- save-cargo-cache
Expand Down Expand Up @@ -185,9 +185,9 @@ jobs:
- install-protoc
- apply-patches
- run: cargo fmt --all --check --manifest-path << parameters.path >>/Cargo.toml
- run: cargo install cargo-sort
# TODO: this is incompatible with workspace inheritance, uncomment when
# https://github.com/DevinR528/cargo-sort/pull/29 is merged
# - run: cargo install cargo-sort
# - run: cargo sort --check << parameters.path >>
- run: |
cargo clippy --tests \
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ COPY --from=cache /build/ /usr/src/shuttle/
FROM shuttle-common
ARG folder
COPY ${folder}/prepare.sh /prepare.sh
RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v21.9/protoc-21.9-linux-x86_64.zip &&\
oddgrd marked this conversation as resolved.
Show resolved Hide resolved
unzip -o protoc-21.9-linux-x86_64.zip -d /usr bin/protoc &&\
unzip -o protoc-21.9-linux-x86_64.zip -d /usr/ 'include/*' &&\
rm -f protoc-21.9-linux-x86_64.zip
RUN /prepare.sh
COPY --from=builder /build/target/debug/shuttle-${folder} /usr/local/bin/service
ARG RUSTUP_TOOLCHAIN
Expand Down
17 changes: 0 additions & 17 deletions cargo-shuttle/build.rs

This file was deleted.

3 changes: 0 additions & 3 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ use uuid::Uuid;
use crate::args::{DeploymentCommand, ProjectCommand};
use crate::client::Client;

const BINARY_BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/release/shuttle-runtime"));

pub struct Shuttle {
ctx: RequestContext,
}
Expand Down Expand Up @@ -412,7 +410,6 @@ impl Shuttle {
run_args.port + 1,
));
let (mut runtime, mut runtime_client) = runtime::start(
BINARY_BYTES,
is_wasm,
runtime::StorageManagerType::WorkingDir(working_directory.to_path_buf()),
&format!("http://localhost:{}", run_args.port + 1),
Expand Down
17 changes: 0 additions & 17 deletions deployer/build.rs

This file was deleted.

3 changes: 3 additions & 0 deletions deployer/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

# Install the shuttle runtime
cargo install shuttle-runtime --path "/usr/src/shuttle/runtime"

# Make future crates requests to our own mirror
echo '
[source.shuttle-crates-io-mirror]
Expand Down
3 changes: 0 additions & 3 deletions deployer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use tracing::{error, trace};
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

const BINARY_BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/release/shuttle-runtime"));

// The `multi_thread` is needed to prevent a deadlock in shuttle_service::loader::build_crate() which spawns two threads
// Without this, both threads just don't start up
#[tokio::main(flavor = "multi_thread")]
Expand Down Expand Up @@ -41,7 +39,6 @@ async fn main() {
.init();

let (mut runtime, mut runtime_client) = runtime::start(
BINARY_BYTES,
false,
runtime::StorageManagerType::Artifacts(args.artifacts_path.clone()),
&args.provisioner_address.uri().to_string(),
Expand Down
1 change: 1 addition & 0 deletions proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ publish = false
[dependencies]
anyhow = { workspace = true }
chrono = { workspace = true }
home = "0.5.4"
prost = "0.11.2"
prost-types = "0.11.0"
tokio = { version = "1.22.0", features = ["process"] }
Expand Down
58 changes: 34 additions & 24 deletions proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ pub mod provisioner {

pub mod runtime {
use std::{
env::temp_dir,
fs::OpenOptions,
io::Write,
path::PathBuf,
process::Command,
time::{Duration, SystemTime},
};

Expand Down Expand Up @@ -240,7 +238,6 @@ pub mod runtime {
}

pub async fn start(
binary_bytes: &[u8],
wasm: bool,
storage_manager_type: StorageManagerType,
provisioner_address: &str,
Expand All @@ -252,7 +249,7 @@ pub mod runtime {
StorageManagerType::WorkingDir(path) => ("working-dir", path),
};

let runtime_executable = get_runtime_executable(binary_bytes);
let runtime_executable = get_runtime_executable();

let runtime = process::Command::new(runtime_executable)
.args([
Expand Down Expand Up @@ -283,27 +280,40 @@ pub mod runtime {
Ok((runtime, runtime_client))
}

fn get_runtime_executable(binary_bytes: &[u8]) -> PathBuf {
let tmp_dir = temp_dir();

let path = tmp_dir.join("shuttle-runtime");
let mut open_options = OpenOptions::new();
open_options.write(true).create(true).truncate(true);

#[cfg(target_family = "unix")]
{
use std::os::unix::prelude::OpenOptionsExt;

open_options.mode(0o755);
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 cargo-shuttle
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 mut file = open_options
.open(&path)
.expect("to create runtime executable file");

file.write_all(binary_bytes)
.expect("to write out binary file");
let cargo_home = home::cargo_home().expect("failed to find cargo home directory");

path
cargo_home.join("bin/shuttle-runtime")
}
}