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

[WIP] feat(shuttle-next): POC of axum wasm router #472

Merged
merged 19 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 101 additions & 55 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cap-std = "0.26.0"
clap ={ version = "4.0.18", features = ["derive"] }
serenity = { version = "0.11.5", default-features = false, features = ["client", "gateway", "rustls_backend", "model"] }
thiserror = "1.0.37"
hyper = { version = "0.14.23", features = ["full"] }
tokio = { version = "=1.20.1", features = ["full"] }
tokio-stream = "0.1.11"
tonic = "0.8.2"
Expand All @@ -21,6 +22,7 @@ uuid = { version = "1.1.2", features = ["v4"] }
wasi-common = "2.0.0"
wasmtime = "2.0.0"
wasmtime-wasi = "2.0.0"
rmp-serde = { version = "1.1.1" }

[dependencies.shuttle-common]
version = "0.7.0"
Expand All @@ -35,3 +37,11 @@ version = "0.7.0"
default-features = false
features = ["loader"]
path = "../service"

[dependencies.shuttle-axum-utils]
path = "../tmp/utils"
optional = true

[features]
shuttle-axum = ["shuttle-axum-utils"]

4 changes: 4 additions & 0 deletions runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ wasm:
cd ../tmp/wasm; cargo build --target wasm32-wasi
cp ../tmp/wasm/target/wasm32-wasi/debug/shuttle_serenity.wasm bot.wasm

axum:
cd ../tmp/axum-wasm; cargo build --target wasm32-wasi
cp ../tmp/axum-wasm/target/wasm32-wasi/debug/shuttle_axum.wasm axum.wasm

test: wasm
cargo test -- --nocapture

Expand Down
55 changes: 47 additions & 8 deletions runtime/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## How to run
# How to run

## shuttle-next
```bash
$ make wasm
$ DISCORD_TOKEN=xxx cargo run
Expand All @@ -8,9 +9,47 @@ $ DISCORD_TOKEN=xxx cargo run
In another terminal:

``` bash
grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic", "path": "runtime/bot.wasm"}' localhost:8000 runtime.Runtime/Load
grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic"}' localhost:8000 runtime.Runtime/Start
grpcurl -plaintext -import-path ../proto -proto runtime.proto localhost:8000 runtime.Runtime/SubscribeLogs
grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic", "path": "runtime/bot.wasm"}' localhost:6001 runtime.Runtime/Load
grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic"}' localhost:6001 runtime.Runtime/Start
grpcurl -plaintext -import-path ../proto -proto runtime.proto localhost:6001 runtime.Runtime/SubscribeLogs
```

## axum-wasm

Compile the wasm axum router:

```bash
make axum
```

Run the test:

```bash
cargo test axum --features shuttle-axum -- --nocapture
```

Load and run:

```bash
cargo run --features shuttle-axum -- --axum --provisioner-address http://localhost:8000
```

In another terminal:

``` bash
# a full, absolute path from home was needed for me in the load request
grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic", "path": "runtime/axum.wasm"}' localhost:6001 runtime.Runtime/Load

grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic"}' localhost:6001 runtime.Runtime/Start

# grpcurl -plaintext -import-path ../proto -proto runtime.proto localhost:6001 runtime.Runtime/SubscribeLogs
```

Curl the service:
```bash
curl localhost:7002/hello

curl localhost:7002/goodbye
```
## shuttle-legacy

Expand All @@ -33,16 +72,16 @@ Or directly (this is the path hardcoded in `deployer::start`):
# first, make sure the shuttle-runtime binary is built
cargo build
# then
/home/<path to shuttle repo>/target/debug/shuttle-runtime --legacy --provisioner-address http://localhost:8000
/home/<path to shuttle repo>/target/debug/shuttle-runtime --legacy --provisioner-address http://localhost:6001
```

Pass the path to `deployer::start`
Then in another shell, load a `.so` file and start it up:

``` bash
grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic", "path": "examples/rocket/hello-world/target/debug/libhello_world.so"}' localhost:8000 runtime.Runtime/Load
grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic"}' localhost:8000 runtime.Runtime/Start
grpcurl -plaintext -import-path ../proto -proto runtime.proto localhost:8000 runtime.Runtime/SubscribeLogs
grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic", "path": "examples/rocket/hello-world/target/debug/libhello_world.so"}' localhost:6001 runtime.Runtime/Load
grpcurl -plaintext -import-path ../proto -proto runtime.proto -d '{"service_name": "Tonic"}' localhost:6001 runtime.Runtime/Start
grpcurl -plaintext -import-path ../proto -proto runtime.proto localhost:6001 runtime.Runtime/SubscribeLogs
```

## Running the tests
Expand Down
6 changes: 5 additions & 1 deletion runtime/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ pub struct Args {
pub provisioner_address: Endpoint,

/// Is this runtime for a legacy service
#[clap(long)]
#[clap(long, conflicts_with("axum"))]
pub legacy: bool,

/// Is this runtime for an axum-wasm service
#[clap(long, conflicts_with("legacy"))]
pub axum: bool,
}
Loading