forked from WasmEdge/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] - Migration of Content from Book to Docs - v2 (WasmEdge#131)
* Migration of Content from Book to Docs Signed-off-by: Adithya Krishna <[email protected]> * Fixed Lint Issues Signed-off-by: Adithya Krishna <[email protected]> * Fixed Broken Links Signed-off-by: Adithya Krishna <[email protected]> * Fixed Broken Links -v 3 Signed-off-by: Adithya Krishna <[email protected]> * Fixed Broken Links Signed-off-by: Adithya Krishna <[email protected]> * Added Eslint MD Parser Signed-off-by: Adithya Krishna <[email protected]> * Moved Use Cases Signed-off-by: Adithya Krishna <[email protected]> --------- Signed-off-by: Adithya Krishna <[email protected]>
- Loading branch information
Adithya Krishna
authored
Jul 11, 2023
1 parent
033e35f
commit 07182a2
Showing
28 changed files
with
15,889 additions
and
9,814 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
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"label": "Use Cases", | ||
"position": 6, | ||
"label": "Kubernetes Use Cases", | ||
"position": 7, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "In this chapter, we will introduce how to use K8s variations to depoloy Wasm app." | ||
"description": "In this chapter, we will discuss how popular software applications embed WasmEdge to support extended functionalities." | ||
} | ||
} |
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
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
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
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,37 @@ | ||
--- | ||
sidebar_position: 1 | ||
--- | ||
|
||
# WasmEdge Integrations | ||
|
||
WasmEdge is a "serverless" runtime for cloud native and edge computing applications. It allows developers safely embed third-party or "native" functions into a host application or a distributed computing framework. | ||
|
||
## Embed WasmEdge Into A Host Application | ||
|
||
A major use case of WasmEdge is to start a VM instance from a host application. Depending on your host application's programming language, you can use WasmEdge SDKs to start and invoke WasmEdge functions. | ||
|
||
- Embed WasmEdge functions into a `C`-based application using the [WasmEdge C API](/category/c-sdk-for-embedding-wasmedge). Checkout the [quick start guide](/embed/c/intro). | ||
- Embed WasmEdge functions into a `Go` application using the [WasmEdge Go API](/category/go-sdk-for-embedding-wasmedge). Here is a [tutorial](https://www.secondstate.io/articles/extend-golang-app-with-webassembly-rust/) and are some [examples](https://github.com/second-state/WasmEdge-go-examples)! | ||
- Embed WasmEdge functions into a `Rust` application using the [WasmEdge Rust crate](https://crates.io/crates/wasmedge-sdk). | ||
- Embed WasmEdge functions into a `Node.js` application using the `NAPI`. Here is a [tutorial](https://www.secondstate.io/articles/getting-started-with-rust-function/). | ||
- Embed WasmEdge functions into any application by spawning a new process. See examples for [Vercel Serverless Functions](https://www.secondstate.io/articles/vercel-wasmedge-webassembly-rust/) and [AWS Lambda](https://www.cncf.io/blog/2021/08/25/webassembly-serverless-functions-in-aws-lambda/). | ||
|
||
However, the WebAssembly spec only supports very limited data types as input parameters and return values for the WebAssembly bytecode functions. In order to pass complex data types, such as a string of an array, as call arguments into WebAssembly compiled from Rust, you should use the `bindgen` solution provided by the [`wasmedge-bindgen`](https://crates.io/crates/wasmedge-bindgen). We currently support the `wasmedge-bindgen` in the [Rust](/develop/rust/bindgen) and in [Go](/embed/go/bindgen). | ||
|
||
## Use WasmEdge As A Docker-Like Container | ||
|
||
WasmEdge provides an OCI compliant interface. You can use container tools, such as CRI-O, Docker Hub, and Kubernetes, to orchestrate and manage WasmEdge runtimes. | ||
|
||
- [Manage WasmEdge with CRI-O and Docker Hub](https://www.secondstate.io/articles/manage-webassembly-apps-in-wasmedge-using-docker-tools/). | ||
|
||
## Call Native Host Functions From WasmEdge | ||
|
||
A key feature of WasmEdge is its extensibility. WasmEdge APIs allow developers to register "host functions" from the host programming languages into a WasmEdge instance, and then invoke these functions from the WebAssembly program. | ||
|
||
- The WasmEdge C API supports the [C host functions](/embed/c/host_function). | ||
- The WasmEdge Go API supports the [Go host functions](https://github.com/second-state/WasmEdge-go-examples/tree/master/go_HostFunc#wasmedge-go-host-function-example). | ||
- The WasmEdge Rust API supports the [Rust host functions](https://github.com/second-state/wasmedge-rustsdk-examples/blob/main/README.md#host-functions). | ||
|
||
[Here is an example](https://www.secondstate.io/articles/call-native-functions-from-javascript/) of a JavaScript program in WasmEdge calling a C-based host function in the underlying OS. | ||
|
||
The host functions break the Wasm sandbox to access the underly OS or hardware. But the sandbox breaking is done with explicit permission from the system’s operator. |
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 @@ | ||
--- | ||
sidebar_position: 5 | ||
--- | ||
|
||
# Serverless Software-As-A-Service Functions | ||
|
||
WasmEdge can support customized SaaS extensions or applications using serverless functions instead of traditional network APIs. That dramatically improves SaaS users' and developers' productivity. | ||
|
||
- WasmEdge could be embedded into SaaS products to execute user-defined functions. In this scenario, the WasmEdge function API replaces the SaaS web API. The embedded WasmEdge functions are much faster, safer, and easier to use than RPC functions over the web. | ||
- Edge servers could provide WasmEdge-based containers to interact with existing SaaS or PaaS APIs without requiring the user to run his own servers (eg callback servers). The serverless API services can be co-located in the same networks as the SaaS to provide optimal performance and security. | ||
|
||
The examples below showcase how WasmEdge-based serverless functions connect together SaaS APIs from different services, and process data flows across those SaaS APIs according each user's business logic. | ||
|
||
## Slack | ||
|
||
- [Build a serverless chatbot for Slack](http://reactor.secondstate.info/en/docs/user_guideline.html) | ||
|
||
## Lark | ||
|
||
It is also known as `飞书` aka the Chinese Slack. It is created by Byte Dance, the parent company of Tiktok. | ||
|
||
- [Build a serverless chatbot for Lark](http://reactor.secondstate.info/en/docs/user_guideline.html) |
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,23 @@ | ||
--- | ||
sidebar_position: 6 | ||
--- | ||
|
||
# Server Side Rendering Modern Web UI | ||
|
||
Traditional web applications follows the client-server model. In the past era of application servers, the entire UI is dynamically generated from the server. The browser is simply a thin client that displays the rendered web pages at real time. However, as the browser becomes more capable and sophisticated, the client can now take on more workload to improve application UX, performance, and security. | ||
|
||
That gives rise to the era of Jamstack. There is now a clear separation between frontend and backend services. The frontend is a static web site (HTML + JavaScript + WebAssembly) generated from UI frameworks such as React.js, Vue.js, Yew or Percy, and the backend consists of microservices. Yet, as Jamstack gains popularity, the diversity of clients (both browsers and apps) makes it very difficult to achieve great performance across all use cases. | ||
|
||
The solution is server-side rendering (SSR). That is to have edge servers run the "client side" UI code (ie the React generated JavaScript OR Percy generated WebAssembly), and send back the rendered HTML DOM objects to the browser. In this case, the edge server must execute the exact same code (i.e. [JavaScript](../../develop/javascript/hello_world) and WebAssembly) as the browser to render the UI. That is called isomorphic Jamstack applications. The WasmEdge runtime provides a lightweight, high performance, OCI complaint, and polyglot container to run all kinds of SSR functions on edge servers. | ||
|
||
- [React JS SSR function](../../develop/javascript/ssr) | ||
- Vue JS SSR function (coming soon) | ||
- Yew Rust compiled to WebAssembly SSR function (coming soon) | ||
- [Percy Rust compiled to WebAssembly SSR function](../../develop/rust/ssr) | ||
|
||
We also exploring ways to render more complex UI and interactions on WasmEdge-based edge servers, and then stream the rendered results to the client application. Potential examples include | ||
|
||
- Render Unity3D animations on the edge server (based on [WebAssembly rendering of Unity3D](https://docs.unity3d.com/2020.1/Documentation/Manual/webgl-gettingstarted.html)) | ||
- Render interactive video (generated from AI) on the edge server | ||
|
||
Of course, the edge cloud could grow well beyond SSR for UI components. It could also host high-performance microservices for business logic and serverless functions. Read on to the next chapter. |
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,139 @@ | ||
--- | ||
sidebar_position: 3 | ||
--- | ||
|
||
# wasm-nginx-module | ||
|
||
The wasm-nginx-module is an Nginx module built upon OpenResty. By implementing the [Proxy Wasm ABI](https://github.com/proxy-wasm/spec), any Wasm program written with Proxy Wasm SDK can be run inside it. Hence, you can write Go or Rust code, compile them into Wasm, then load & execute it in Nginx. | ||
|
||
> The wasm-nginx-module is already used in APISIX and allows it to [run Wasm plugin like Lua plugin](https://github.com/apache/apisix/blob/master/docs/en/latest/wasm.md). | ||
In order to follow along the tutorials in this chapter, you will need to first [build your Nginx with wasm-nginx-module included and WasmEdge shared library installed in the right path](https://github.com/api7/wasm-nginx-module#install-dependencies). | ||
|
||
Once you have Nginx installed, let me show you a real world example - using Wasm to inject custom responses in Nginx. | ||
|
||
## Inject Custom Response via Go in Nginx, Step by Step | ||
|
||
### Go Step 1: Write code based on proxy-wasm-go-sdk | ||
|
||
The implementation code (including `go.mod` and others) can be found at [here](https://github.com/apache/apisix/tree/master/t/wasm). | ||
|
||
It should be explained that although the proxy-wasm-go-sdk project carries the Go name, it actually uses tinygo instead of native Go, which has some problems supporting WASI (which you can think of as a non-browser WASM runtime interface), see [here](https://github.com/tetratelabs/proxy-wasm-go-sdk/blob/main/doc/OVERVIEW.md#tinygo-vs-the-official-go-compiler) for more details. | ||
|
||
We also provide a Rust version (including Cargo.toml and others) [there](https://github.com/api7/wasm-nginx-module/tree/main/t/testdata/rust/fault-injection). | ||
|
||
### Go Step 2: Build the corresponding Wasm file | ||
|
||
```shell | ||
tinygo build -o ./fault-injection/main.go.wasm -scheduler=none -target=wasi ./fault-injection/main.go | ||
``` | ||
|
||
### Go Step 3: Load and execute the Wasm file | ||
|
||
Then, start Nginx with the configuration below: | ||
|
||
```conf | ||
worker_processes 1; | ||
error_log /tmp/error.log warn; | ||
events { | ||
worker_connections 10240; | ||
} | ||
http { | ||
wasm_vm wasmedge; | ||
init_by_lua_block { | ||
local wasm = require("resty.proxy-wasm") | ||
package.loaded.plugin = assert(wasm.load("fault_injection", | ||
"/path/to/fault-injection/main.go.wasm")) | ||
} | ||
server { | ||
listen 1980; | ||
location / { | ||
content_by_lua_block { | ||
local wasm = require("resty.proxy-wasm") | ||
local ctx = assert(wasm.on_configure(package.loaded.plugin, | ||
'{"http_status": 403, "body": "powered by wasm-nginx-module"}')) | ||
assert(wasm.on_http_request_headers(ctx)) | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
This configuration loads the Wasm file we just built, executes it with the configuration `{"http_status": 403, "body": "powered by wasm-nginx-module"}`. | ||
|
||
### Go Step 4: verify the result | ||
|
||
After Nginx starts, we can use `curl http://127.0.0.1:1980/ -i` to verify the execution result of the Wasm. | ||
|
||
It is expected to see the output: | ||
|
||
```bash | ||
HTTP/1.1 403 Forbidden | ||
... | ||
|
||
powered by wasm-nginx-module | ||
``` | ||
|
||
## Inject Custom Response via Rust in Nginx, Step by Step | ||
|
||
### Rust Step 1: Write code based on proxy-wasm-rust-sdk | ||
|
||
We also provide a Rust version (including Cargo.toml and others) [here](https://github.com/api7/wasm-nginx-module/tree/main/t/testdata/rust/fault-injection). | ||
|
||
### Rust Step 2: Build the corresponding Wasm file | ||
|
||
```shell | ||
cargo build --target=wasm32-wasi | ||
``` | ||
|
||
### Rust Step 3: Load and execute the Wasm file | ||
|
||
Then, start Nginx with the configuration below: | ||
|
||
```conf | ||
worker_processes 1; | ||
error_log /tmp/error.log warn; | ||
events { | ||
worker_connections 10240; | ||
} | ||
http { | ||
wasm_vm wasmedge; | ||
init_by_lua_block { | ||
local wasm = require("resty.proxy-wasm") | ||
package.loaded.plugin = assert(wasm.load("fault_injection", | ||
"/path/to/fault-injection/target/wasm32-wasi/debug/fault_injection.wasm")) | ||
} | ||
server { | ||
listen 1980; | ||
location / { | ||
content_by_lua_block { | ||
local wasm = require("resty.proxy-wasm") | ||
local ctx = assert(wasm.on_configure(package.loaded.plugin, | ||
'{"http_status": 403, "body": "powered by wasm-nginx-module"}')) | ||
assert(wasm.on_http_request_headers(ctx)) | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
This configuration loads the Wasm file we just built, executes it with the configuration `{"http_status": 403, "body": "powered by wasm-nginx-module"}`. | ||
|
||
### Rust Step 4: verify the result | ||
|
||
After Nginx starts, we can use `curl http://127.0.0.1:1980/ -i` to verify the execution result of the Wasm. | ||
|
||
It is expected to see the output: | ||
|
||
```bash | ||
HTTP/1.1 403 Forbidden | ||
... | ||
|
||
powered by wasm-nginx-module | ||
``` |
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 @@ | ||
--- | ||
sidebar_position: 3 | ||
--- | ||
|
||
# WasmEdge On Smart Devices | ||
|
||
Smart device apps could embed WasmEdge as a middleware runtime to render interactive content on the UI, connect to native device drivers, and access specialized hardware features (i.e, the GPU for AI inference). The benefits of the WasmEdge runtime over native-compiled machine code include security, safety, portability, manageability, OTA upgradability, and developer productivity. WasmEdge runs on the following device OSes. | ||
|
||
- [Android](/category/build-and-run-wasmedge-on-android) | ||
- [OpenHarmony](/contribute/source/os/openharmony) | ||
- [Raspberry Pi](/contribute/source/os/raspberrypi) | ||
- [The seL4 RTOS](/contribute/source/os/sel4) | ||
|
||
With WasmEdge on both the device and the edge server, we can support [isomorphic Server-Side Rendering (SSR)](/develop/rust/ssr) and [microservices](/develop/build-and-run/docker_wasm#deploy-the-microservice-example) for rich-client mobile applications that is both portable and upgradable. |
6 changes: 3 additions & 3 deletions
6
i18n/zh/docusaurus-plugin-content-docs/current/develop/deploy/kubernetes/_category_.json
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,8 +1,8 @@ | ||
{ | ||
"label": "Use Cases", | ||
"position": 6, | ||
"label": "Kubernetes Use Cases", | ||
"position": 7, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "In this chapter, we will introduce how to use K8s variations to depoloy Wasm app." | ||
"description": "In this chapter, we will discuss how popular software applications embed WasmEdge to support extended functionalities." | ||
} | ||
} |
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
Oops, something went wrong.