Skip to content

Commit

Permalink
[Feat] - Migration of Content from Book to Docs - v2 (WasmEdge#131)
Browse files Browse the repository at this point in the history
* 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
Show file tree
Hide file tree
Showing 28 changed files with 15,889 additions and 9,814 deletions.
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ module.exports = {
'plugin:import/warnings',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:md/recommended',
],
overrides: [
{
files: ['*.md'],
parser: 'markdown-eslint-parser',
rules: {
'prettier/prettier': [
'error',
// Important to force prettier to use "markdown" parser - otherwise it wouldn't be able to parse *.md files.
// You also can configure other options supported by prettier here - "prose-wrap" is
// particularly useful for *.md files
{ parser: 'markdown' },
],
},
},
{
files: ['*.md.js'], // Will match js code inside *.md files
rules: {
// Example - disable 2 core eslint rules 'no-unused-vars' and 'no-undef'
'no-unused-vars': 'off',
'no-undef': 'off',
},
},
],
parserOptions: {
ecmaFeatures: {
Expand Down
2 changes: 1 addition & 1 deletion docs/develop/deploy/cri-runtime/containerd-crun.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The args are as follows.
File content is This is in a file
```

Next, you can try to run it in [Kubernetes](../kubernetes/kubernetes-containerd-crun.md#a-simple-webassembly-app)!
Next, you can try to run it in [Kubernetes](../kubernetes/kubernetes-containerd-crun.md#a-simple-webassembly-app))!

## Run a HTTP server app

Expand Down
6 changes: 3 additions & 3 deletions docs/develop/deploy/kubernetes/_category_.json
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."
}
}
2 changes: 1 addition & 1 deletion docs/develop/deploy/kubernetes/knative.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Here we setup crun as a runtimeClass in kubernetes cluster, **rather than replac

## Compile crun

Please refer to the document [crun](../../deploy/oci-runtime/crun) to build and compile crun with WasmEdge support.
Please refer to the document [crun](../../../develop/deploy/oci-runtime/crun) to build and compile crun with WasmEdge support.

```bash
# Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion docs/develop/deploy/kubernetes/kubedge.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ KubeEdge is an open source system for extending native containerized application

<!-- prettier-ignore -->
:::note
This demo is based on [crun's support](../../deploy/oci-runtime/crun)
This demo is based on [crun's support](../../../develop/deploy/oci-runtime/crun)
:::

## 1. Setup Cloud Side (KubeEdge Master Node)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The [GitHub repo](https://github.com/second-state/wasmedge-containers-examples/)

In the rest of this section, we will explain the steps in detail.

We will assume that you have already [installed and configured containerd](../cri-runtime/containerd-crun.md) to work with WasmEdge container images.
We will assume that you have already [installed and configured containerd](../../../develop/deploy/cri-runtime/containerd-crun) to work with WasmEdge container images.

## Install and start Kubernetes

Expand Down
2 changes: 1 addition & 1 deletion docs/develop/deploy/kubernetes/kubernetes-cri-o.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The [WasmEdge Containers Example](https://github.com/second-state/wasmedge-conta
- Simple WebAssembly example [Quick start](https://github.com/second-state/wasmedge-containers-examples/blob/main/kubernetes_crio/README.md) | [Github Actions](https://github.com/second-state/wasmedge-containers-examples/blob/main/.github/workflows/kubernetes-crio.yml)
- WebAssembly-based HTTP service [Quick start](https://github.com/second-state/wasmedge-containers-examples/blob/main/kubernetes_crio/http_server/README.md) | [Github Actions](https://github.com/second-state/wasmedge-containers-examples/blob/main/.github/workflows/kubernetes-crio-server.yml)

In the rest of this section, we will explain the steps in detail. We will assume that you have already [installed and configured CRI-O](../oci-runtime/crun.md) to work with WasmEdge container images.
In the rest of this section, we will explain the steps in detail. We will assume that you have already [installed and configured CRI-O](../../../develop/deploy/oci-runtime/crun) to work with WasmEdge container images.

## Install and start Kubernetes

Expand Down
2 changes: 1 addition & 1 deletion docs/develop/deploy/kubernetes/openyurt.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ systemctl start containerd

#### Install WasmEdge

Use the [simple install script](../../build-and-run/install) to install WasmEdge on your edge node.
Use the [simple install script](../../../develop/build-and-run/install) to install WasmEdge on your edge node.

```bash
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash
Expand Down
11 changes: 10 additions & 1 deletion docs/develop/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ We will cover the following content:
- Develop WebAssembly apps from your programming languages from [Rust](/category/develop-wasm-apps-in-rust), [C/C++](/category/develop-wasm-apps-in-cc), [JavaScript](/category/develop-wasm-apps-in-javascript), [Go](/category/develop-wasm-apps-in-go), and many other languages.
- [Deploy Wasm Apps with the existing container toolings](/category/deploy-wasmedge-apps-in-kubernetes)

Besides this, we also have two more guides for embedding Wasm Functions and contributing to WasmEdge.
# Write a WebAssembly Application

A key value proposition of WebAssembly is that it supports multiple programming languages. WebAssembly is a "managed runtime" for many programming languages including [C/C++](/category/develop-wasm-apps-in-cc), [Rust](/category/develop-wasm-apps-in-rust), [Go](/category/develop-wasm-apps-in-go), and even [JavaScript](/category/develop-wasm-apps-in-javascript) and [Python](/category/develop-wasm-apps-in-python).

- For compiled languages (e.g., C and Rust), WasmEdge WebAssembly provides a safe, secure, isolated, and containerized runtime as opposed to Native Client (NaCl).
- For interpreted or managed languages (e.g., JavaScript and Python), WasmEdge WebAssembly provides a secure, fast, lightweight, and containerized runtime as opposed to Docker + guest OS + native interpreter.

In this chapter, we will discuss how to compile sources into WebAssembly in different languages and run them in WasmEdge.

Besides this, we also have two more guides for [Embedding Wasm Functions](/embed/overview) and [Contributing](/contribute/overview) to WasmEdge.

If you find some issues or have any feedback, you could reach out to us via the following ways.

Expand Down
37 changes: 37 additions & 0 deletions docs/develop/wasmedge/integrations.md
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.
22 changes: 22 additions & 0 deletions docs/embed/use-case/serverless-saas.md
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)
23 changes: 23 additions & 0 deletions docs/embed/use-case/ssr-modern-ui.md
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.
139 changes: 139 additions & 0 deletions docs/embed/use-case/wasm-nginx.md
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
```
14 changes: 14 additions & 0 deletions docs/embed/use-case/wasm-smart-devices.md
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.
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."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Here we setup crun as a runtimeClass in kubernetes cluster, **rather than replac

## Compile crun

Please refer to the document [crun](../../deploy/oci-runtime/crun) to build and compile crun with WasmEdge support.
Please refer to the document [crun](../../../develop/deploy/oci-runtime/crun) to build and compile crun with WasmEdge support.

```bash
# Install dependencies
Expand Down
Loading

0 comments on commit 07182a2

Please sign in to comment.