-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
wabt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kubectl get nodes -o wide | ||
kubectl describe node aks-mywasipool-41740949-vmss000000 | ||
kubectl describe node aks-mywasipool-41740949-vmss000000 | grep spin | ||
|
||
cd AKS/spin-workload | ||
kubectl apply -f spin.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: node.k8s.io/v1 | ||
kind: RuntimeClass | ||
metadata: | ||
name: "wasmtime-spin-v1" | ||
handler: "spin" | ||
scheduling: | ||
nodeSelector: | ||
"kubernetes.azure.com/wasmtime-spin-v1": "true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: wasm-spin | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: wasm-spin | ||
template: | ||
metadata: | ||
labels: | ||
app: wasm-spin | ||
spec: | ||
runtimeClassName: wasmtime-spin-v1 | ||
containers: | ||
- name: testwasm | ||
image: docker.io/rstropek/fractal_tree_spin:latest | ||
command: ["/"] | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: wasm-spin | ||
spec: | ||
type: LoadBalancer | ||
ports: | ||
- protocol: TCP | ||
port: 80 | ||
targetPort: 80 | ||
selector: | ||
app: wasm-spin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
[workspace] | ||
members = [ | ||
"fractal_tree", | ||
"fractal_tree_wasm_lib", | ||
"fractal_tree_cli", | ||
"fractal_tree_spin", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM scratch | ||
COPY ./fractal_tree_spin.wasm . | ||
COPY ./spin.toml . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
spin_version = "1" | ||
authors = ["Rainer <[email protected]>"] | ||
description = "Factal Tree with Spin" | ||
name = "fractal_tree_spin" | ||
trigger = { type = "http", base = "/" } | ||
version = "0.1.0" | ||
|
||
[[component]] | ||
id = "fractal-tree-spin" | ||
source = "fractal_tree_spin.wasm" | ||
[component.trigger] | ||
route = "/..." | ||
[component.build] | ||
command = "cargo build --target wasm32-wasi --release" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build] | ||
target = "wasm32-wasi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[package] | ||
name = "fractal-tree-spin" | ||
authors = ["Rainer <[email protected]>"] | ||
description = "Factal Tree with Spin" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = [ "cdylib" ] | ||
|
||
[dependencies] | ||
# Useful crate to handle errors. | ||
anyhow = "1" | ||
# Crate to simplify working with bytes. | ||
bytes = "1" | ||
# General-purpose crate with common HTTP types. | ||
http = "0.2" | ||
# The Spin SDK. | ||
spin-sdk = { git = "https://github.com/fermyon/spin", tag = "v0.6.0" } | ||
# Crate that generates Rust Wasm bindings from a WebAssembly interface. | ||
wit-bindgen-rust = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "cb871cfa1ee460b51eb1d144b175b9aab9c50aba" } | ||
fractal_tree = { path = "../fractal_tree", default-features = false, features = ["svg"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
spin_version = "1" | ||
authors = ["Rainer <[email protected]>"] | ||
description = "Factal Tree with Spin" | ||
name = "fractal_tree_spin" | ||
trigger = { type = "http", base = "/" } | ||
version = "0.1.0" | ||
|
||
[[component]] | ||
id = "fractal-tree-spin" | ||
source = "../target/wasm32-wasi/release/fractal_tree_spin.wasm" | ||
[component.trigger] | ||
route = "/..." | ||
[component.build] | ||
command = "cargo build --target wasm32-wasi --release" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use anyhow::Result; | ||
use spin_sdk::{ | ||
http::{Request, Response}, | ||
http_component, | ||
}; | ||
|
||
mod parameters; | ||
|
||
#[http_component] | ||
fn fractal_tree_spin(_req: Request) -> Result<Response> { | ||
let params = parameters::extract_parameters(&_req); | ||
|
||
let buffer = fractal_tree::tree_svg(params.seed, params.depth, params.trunk_length); | ||
|
||
Ok(http::Response::builder() | ||
.status(200) | ||
.header("content-type", "image/svg+xml") | ||
.body(Some(buffer.into()))?) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use spin_sdk::{ | ||
http::Request, | ||
}; | ||
|
||
pub struct Parameters { | ||
pub seed: String, | ||
pub depth: usize, | ||
pub trunk_length: f64, | ||
} | ||
|
||
impl Default for Parameters { | ||
fn default() -> Self { | ||
Self { | ||
seed: "Hello WASM".to_string(), | ||
depth: 13usize, | ||
trunk_length: 100f64, | ||
} | ||
} | ||
} | ||
|
||
pub fn extract_parameters(req: &Request) -> Parameters { | ||
let query = req.uri().query().unwrap_or(""); | ||
let mut params = Parameters::default(); | ||
|
||
for pair in query.split('&').filter(|s| !s.is_empty()) { | ||
let mut parts = pair.split('='); | ||
let key = parts.next().unwrap(); | ||
let value = parts.next().unwrap(); | ||
|
||
match key { | ||
"seed" => params.seed = value.to_string(), | ||
"depth" => params.depth = value.parse().unwrap_or(params.depth), | ||
"trunk" => params.trunk_length = value.parse().unwrap_or(params.trunk_length), | ||
_ => {}, | ||
} | ||
} | ||
|
||
params | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
GET http://localhost:3000 | ||
|
||
### | ||
GET http://127.0.0.1:3000/?seed=Hello%20WASM&depth=10&trunk=150 | ||
|
||
### | ||
GET http://20.238.176.25 |