From f7f6b0639e249c8e11d7ff73ebef07bb05f5459d Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Mon, 24 Jul 2023 11:02:37 +0200 Subject: [PATCH 1/3] docs(wasm): support http(s) fetch of Wasm files Signed-off-by: Edoardo Vacchi --- .../supported-bindings/wasm.md | 25 ++++++++++++++++--- .../supported-middleware/middleware-wasm.md | 5 +++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md b/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md index 0ca9a69d4..e7af9ed7b 100644 --- a/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md +++ b/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md @@ -36,6 +36,9 @@ Wasm binaries are loaded from a URL. For example, the URL `file://rewrite.wasm` loads `rewrite.wasm` from the current directory of the process. On Kubernetes, see [How to: Mount Pod volumes to the Dapr sidecar]({{< ref kubernetes-volume-mounts.md >}}) to configure a filesystem mount that can contain Wasm binaries. +It is also possible to fetch the wasm binary from a remote URL. In this case, +the URL must point exactly to one wasm binary, e.g.: +`http://example.com/rewrite.wasm` or `https://example.com/rewrite.wasm`. Dapr uses [wazero](https://wazero.io) to run these binaries, because it has no dependencies. This allows use of WebAssembly with no installation process @@ -64,7 +67,7 @@ spec: | Field | Details | Required | Example | |-------|----------------------------------------------------------------|----------|----------------| -| url | The URL of the resource including the Wasm binary to instantiate. The supported schemes include `file://`. The path of a `file://` URL is relative to the Dapr process unless it begins with `/`. | true | `file://hello.wasm` | +| url | The URL of the resource including the Wasm binary to instantiate. The supported schemes include `file://`, `http://`, and `https://`. The path of a `file://` URL is relative to the Dapr process unless it begins with `/`. | true | `file://hello.wasm`, `https://example.com/hello.wasm` | ## Binding support @@ -80,9 +83,23 @@ pass metadata properties with each request: - `args` any CLI arguments, comma-separated. This excludes the program name. -For example, if the binding `url` was a Ruby interpreter, such as from -[webassembly-language-runtimes](https://github.com/vmware-labs/webassembly-language-runtimes/releases/tag/ruby%2F3.2.0%2B20230215-1349da9), -the following request would respond back with "Hello, salaboy": +For example, consider binding the `url` to a Ruby interpreter, such as from +[webassembly-language-runtimes](https://github.com/vmware-labs/webassembly-language-runtimes/releases/tag/ruby%2F3.2.0%2B20230215-1349da9): + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: wasm +spec: + type: bindings.wasm + version: v1 + metadata: + - name: url + value: "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/ruby%2F3.2.0%2B20230215-1349da9/ruby-3.2.0-slim.wasm" +``` + +Then, the following request would respond back with "Hello, salaboy": ```json { diff --git a/daprdocs/content/en/reference/components-reference/supported-middleware/middleware-wasm.md b/daprdocs/content/en/reference/components-reference/supported-middleware/middleware-wasm.md index 51d75b0b8..ecee02008 100644 --- a/daprdocs/content/en/reference/components-reference/supported-middleware/middleware-wasm.md +++ b/daprdocs/content/en/reference/components-reference/supported-middleware/middleware-wasm.md @@ -21,6 +21,9 @@ Wasm binaries are loaded from a URL. For example, the URL `file://rewrite.wasm` loads `rewrite.wasm` from the current directory of the process. On Kubernetes, see [How to: Mount Pod volumes to the Dapr sidecar]({{< ref kubernetes-volume-mounts.md >}}) to configure a filesystem mount that can contain Wasm modules. +It is also possible to fetch the wasm binary from a remote URL. In this case, +the URL must point exactly to one wasm binary, e.g.: +`http://example.com/rewrite.wasm` or `https://example.com/rewrite.wasm`. ## Component format @@ -44,7 +47,7 @@ How to compile this is described later. | Field | Details | Required | Example | |-------|----------------------------------------------------------------|----------|----------------| -| url | The URL of the resource including the Wasm binary to instantiate. The supported schemes include `file://`. The path of a `file://` URL is relative to the Dapr process unless it begins with `/`. | true | `file://hello.wasm` | +| url | The URL of the resource including the Wasm binary to instantiate. The supported schemes include `file://`, `http://`, and `https://`. The path of a `file://` URL is relative to the Dapr process unless it begins with `/`. | true | `file://hello.wasm`, `https://example.com/hello.wasm` | ## Dapr configuration From 3dbf63f7b45f8a36b78c9455a9b56da20f7236bd Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Mon, 24 Jul 2023 18:04:20 +0200 Subject: [PATCH 2/3] Update docs for bindings Signed-off-by: Edoardo Vacchi --- .../supported-bindings/wasm.md | 22 +++++++++++++------ .../supported-middleware/middleware-wasm.md | 7 +++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md b/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md index e7af9ed7b..e909f95bb 100644 --- a/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md +++ b/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md @@ -36,9 +36,10 @@ Wasm binaries are loaded from a URL. For example, the URL `file://rewrite.wasm` loads `rewrite.wasm` from the current directory of the process. On Kubernetes, see [How to: Mount Pod volumes to the Dapr sidecar]({{< ref kubernetes-volume-mounts.md >}}) to configure a filesystem mount that can contain Wasm binaries. -It is also possible to fetch the wasm binary from a remote URL. In this case, -the URL must point exactly to one wasm binary, e.g.: -`http://example.com/rewrite.wasm` or `https://example.com/rewrite.wasm`. +It is also possible to fetch the Wasm binary from a remote URL. In this case, +the URL must point exactly to one Wasm binary. For example: +- `http://example.com/rewrite.wasm`, or +- `https://example.com/rewrite.wasm`. Dapr uses [wazero](https://wazero.io) to run these binaries, because it has no dependencies. This allows use of WebAssembly with no installation process @@ -99,16 +100,23 @@ spec: value: "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/ruby%2F3.2.0%2B20230215-1349da9/ruby-3.2.0-slim.wasm" ``` -Then, the following request would respond back with "Hello, salaboy": +Assuming that you started your Wasm Binding at port 3500, you'd run: -```json +``` +$ dapr run --app-id wasm --dapr-http-port 3500 --resources-path components +``` + +The following request responds `Hello "salaboy"`: + +```sh +$ curl -X POST http://localhost:3500/v1.0/bindings/wasm -d' { "operation": "execute", "metadata": { - "args": "-ne,'print \"Hello, \"; print'" + "args": "-ne,print \"Hello \"; print" }, "data": "salaboy" -} +}' ``` ## Related links diff --git a/daprdocs/content/en/reference/components-reference/supported-middleware/middleware-wasm.md b/daprdocs/content/en/reference/components-reference/supported-middleware/middleware-wasm.md index ecee02008..053d6f715 100644 --- a/daprdocs/content/en/reference/components-reference/supported-middleware/middleware-wasm.md +++ b/daprdocs/content/en/reference/components-reference/supported-middleware/middleware-wasm.md @@ -21,9 +21,10 @@ Wasm binaries are loaded from a URL. For example, the URL `file://rewrite.wasm` loads `rewrite.wasm` from the current directory of the process. On Kubernetes, see [How to: Mount Pod volumes to the Dapr sidecar]({{< ref kubernetes-volume-mounts.md >}}) to configure a filesystem mount that can contain Wasm modules. -It is also possible to fetch the wasm binary from a remote URL. In this case, -the URL must point exactly to one wasm binary, e.g.: -`http://example.com/rewrite.wasm` or `https://example.com/rewrite.wasm`. +It is also possible to fetch the Wasm binary from a remote URL. In this case, +the URL must point exactly to one Wasm binary. For example: +- `http://example.com/rewrite.wasm`, or +- `https://example.com/rewrite.wasm`. ## Component format From d36bc06368c3d3856880e045468997423b7378ba Mon Sep 17 00:00:00 2001 From: Edoardo Vacchi Date: Thu, 3 Aug 2023 09:40:49 +0200 Subject: [PATCH 3/3] Apply suggestions Signed-off-by: Edoardo Vacchi --- .../reference/components-reference/supported-bindings/wasm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md b/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md index 630249066..c19c8b904 100644 --- a/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md +++ b/daprdocs/content/en/reference/components-reference/supported-bindings/wasm.md @@ -102,7 +102,7 @@ spec: value: "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/ruby%2F3.2.0%2B20230215-1349da9/ruby-3.2.0-slim.wasm" ``` -Assuming that you started your Wasm Binding at port 3500, you'd run: +Assuming that you wanted to start your Dapr at port 3500 with the Wasm Binding, you'd run: ``` $ dapr run --app-id wasm --dapr-http-port 3500 --resources-path components