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

feat: update examples wasmtime 17 p2 #1518

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 4 additions & 5 deletions examples/golang/actors/http-echo-tinygo/wadm.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# This is a full example of how to run the kvcounter actor exposed with an HTTP server.
# This is a full example of how to run the kvcounter actor exposed with an HTTP server.
#
# Using this example requires you to have a Redis server running locally
# (though the linkdef can be modified to use a Redis server you have running elsewhere).
#
# You also need to have WADM running:
# https://github.com/wasmCloud/wadm/tree/main/wadm.
# https://github.com/wasmCloud/wadm/tree/main/wadm.
#
# You can deploy this example with a simple command:
# `wash app deploy wadm.yaml`
Expand All @@ -22,8 +22,7 @@ spec:
- name: http-echo-tinygo
type: actor
properties:
# TODO: you must replace the path below to match your genreated code in build
image: file:///the/absolute/path/to/build/http-echo-tinygo-component_s.wasm
image: file://./build/http-echo-tinygo-component_s.wasm
traits:
# Govern the spread/scheduling of the actor
- type: spreadscaler
Expand All @@ -37,7 +36,7 @@ spec:
values:
ADDRESS: 127.0.0.1:8081

# Add a capability provider that mediates HTTP access
# Add a capability provider that mediates HTTP access
- name: httpserver
type: capability
properties:
Expand Down
12 changes: 8 additions & 4 deletions examples/golang/actors/http-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ This is a simple TinyGo Wasm example that responds with a "Hello World" message

- `go` 1.21.1
- `tinygo` 0.30
- `wash` 0.25.0
- `wasmtime` 16.0.0 (if running with wasmtime)
- [`wash`](https://wasmcloud.com/docs/installation) 0.26.0
- `wasmtime` 17.0.0 (if running with wasmtime)

## Building

Expand All @@ -17,10 +17,10 @@ wash build

## Running with wasmtime

You must have wasmtime 16.0.0 for this to work. Make sure to follow the build step above first.
You must have wasmtime 17.0.0 for this to work. Make sure to follow the build step above first.

```bash
wasmtime serve -Scommon ./build/http-hello-world_s.wasm
wasmtime serve -Scommon ./build/http_hello_world_s.wasm
```

## Running with wasmCloud
Expand All @@ -32,3 +32,7 @@ wash up -d
wash app deploy ./wadm.yaml
curl http://localhost:8080
```

## Adding Capabilities

To learn how to extend this example with additional capabilities, see the [Adding Capabilities](https://wasmcloud.com/docs/tour/adding-capabilities?lang=tinygo) section of the wasmCloud documentation.
10 changes: 5 additions & 5 deletions examples/golang/actors/http-hello-world/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import (
)

// Helper type aliases to make code more readable
type HttpRequest = http.ExportsWasiHttp0_2_0_rc_2023_12_05_IncomingHandlerIncomingRequest
type HttpResponseWriter = http.ExportsWasiHttp0_2_0_rc_2023_12_05_IncomingHandlerResponseOutparam
type HttpOutgoingResponse = http.WasiHttp0_2_0_rc_2023_12_05_TypesOutgoingResponse
type HttpError = http.WasiHttp0_2_0_rc_2023_12_05_TypesErrorCode
type HttpRequest = http.ExportsWasiHttp0_2_0_IncomingHandlerIncomingRequest
type HttpResponseWriter = http.ExportsWasiHttp0_2_0_IncomingHandlerResponseOutparam
type HttpOutgoingResponse = http.WasiHttp0_2_0_TypesOutgoingResponse
type HttpError = http.WasiHttp0_2_0_TypesErrorCode

type HttpServer struct{}

func init() {
httpserver := HttpServer{}
// Set the incoming handler struct to HttpServer
http.SetExportsWasiHttp0_2_0_rc_2023_12_05_IncomingHandler(httpserver)
http.SetExportsWasiHttp0_2_0_IncomingHandler(httpserver)
}

func (h HttpServer) Handle(request HttpRequest, responseWriter HttpResponseWriter) {
Expand Down
6 changes: 2 additions & 4 deletions examples/golang/actors/http-hello-world/wadm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ metadata:
experimental: true
spec:
components:
- name: http-echo-tinygo
- name: http-hello-world
type: actor
properties:
# TODO: you must replace the path below to match your genreated code in build
# Try using `wash build -o json` and use the `actor_path` field, prepended with `file://`
image: file:///the/absolute/path/to/build/http-echo-tinygo-component_s.wasm
image: file://./build/http_hello_world_s.wasm
traits:
# Govern the spread/scheduling of the actor
- type: spreadscaler
Expand Down
4 changes: 1 addition & 3 deletions examples/golang/actors/http-hello-world/wasmcloud.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ type = "actor"
version = "0.1.0"

[actor]
claims = [
"wasmcloud:httpserver",
]
wit_world = "hello"
wasm_target = "wasm32-wasi-preview2"
destination = "build/http_hello_world_s.wasm"
14 changes: 9 additions & 5 deletions examples/python/actors/http-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ This is a simple Python Wasm example that responds with a "Hello World" message

- `python` 3.10 or greater
- `pip`
- `componentize-py` 0.9.2
- `wash` 0.25.0
- `wasmtime` 16.0.0 (if running with wasmtime)
- `componentize-py` 0.11.0
- `wash` 0.26.0
- `wasmtime` 17.0.0 (if running with wasmtime)

## Installing componentize-py

After installing Python and pip, run the following command to install `componentize-py`:

```bash
pip install componentize-py==0.9.2
pip install componentize-py
```

## Building
Expand All @@ -26,7 +26,7 @@ wash build

## Running with wasmtime

You must have wasmtime 16.0.0 for this to work. Make sure to follow the build step above first.
You must have wasmtime 17.0.0 for this to work. Make sure to follow the build step above first.

```bash
wasmtime serve -Scommon ./build/http_hello_world_s.wasm
Expand All @@ -41,3 +41,7 @@ wash up -d
wash app deploy ./wadm.yaml
curl http://localhost:8080
```

## Adding Capabilities

To learn how to extend this example with additional capabilities, see the [Adding Capabilities](https://wasmcloud.com/docs/tour/adding-capabilities?lang=python) section of the wasmCloud documentation.
4 changes: 1 addition & 3 deletions examples/python/actors/http-hello-world/wadm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ spec:
- name: python-http
type: actor
properties:
# TODO: you must replace the path below to match your genreated code in build
# Try using `wash build -o json` and use the `actor_path` field, prepended with `file://`
image: file:///Users/brooks/github.com/wasmcloud/wasmCloud/examples/python/actors/http-hello-world/build/http_hello_world_s.wasm
image: file://./build/http_hello_world_s.wasm
traits:
# Govern the spread/scheduling of the actor
- type: spreadscaler
Expand Down
4 changes: 1 addition & 3 deletions examples/python/actors/http-hello-world/wasmcloud.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name = "python-http-hello-world"
# TODO: fix language once https://github.com/wasmCloud/wasmCloud/pull/1295 merges
language = "rust"
language = "python"
type = "actor"
version = "0.1.0"

[actor]
claims = ["wasmcloud:httpserver", "wasmcloud:builtin:logging", "wasmcloud:keyvalue"]
build_command = "componentize-py -d ./wit -w hello componentize app -o build/http_hello_world.wasm"
build_artifact = "build/http_hello_world.wasm"
destination = "build/http_hello_world_s.wasm"
19 changes: 12 additions & 7 deletions examples/rust/actors/http-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ This is a simple Rust Wasm example that responds with a "Hello World" message fo

## Prerequisites

- `cargo` 1.74
- `wash` 0.25.0
- `wasmtime` 16.0.0 (if running with wasmtime)
- `cargo` 1.75
- [`wash`](https://wasmcloud.com/docs/installation) 0.26.0
- `wasmtime` 17.0.0 (if running with wasmtime)

## Building

Expand All @@ -16,18 +16,23 @@ wash build

## Running with wasmtime

You must have wasmtime 16.0.0 for this to work. Make sure to follow the build step above first.
You must have wasmtime 17.0.0 for this to work. Make sure to follow the build step above first.

```bash
wasmtime serve -Scommon ./build/http_hello_world_s.wasm
```

## Running with wasmCloud

Make sure to follow the build steps above, and replace the file path in [the wadm manifest](./wadm.yaml) with the absolute path to your local built component.
Ensuring you've built your component with `wash build`, you can launch wasmCloud and deploy the full hello world application with the following commands. Once the application reports as **Deployed** in the application list, you can use `curl` to send a request to the running HTTP server.

```
```shell
wash up -d
wash app deploy ./wadm.yaml
curl http://localhost:8081
wash app list
curl http://localhost:8080
```

## Adding Capabilities

To learn how to extend this example with additional capabilities, see the [Adding Capabilities](https://wasmcloud.com/docs/tour/adding-capabilities?lang=rust) section of the wasmCloud documentation.
8 changes: 3 additions & 5 deletions examples/rust/actors/http-hello-world/wadm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ spec:
- name: http-hello-world
type: actor
properties:
# TODO: you must replace the path below to match your genreated code in build
# Try using `wash build -o json` and use the `actor_path` field, prepended with `file://`
image: file:///the/absolute/path/to/build/http_hello_world_s.wasm
image: file://./build/http_hello_world_s.wasm
traits:
# Govern the spread/scheduling of the actor
- type: spreadscaler
properties:
replicas: 1
# Link the HTTP server, and inform it to listen on port 8081
# Link the HTTP server, and inform it to listen on port 8080
# on the local machine
- type: linkdef
properties:
target: httpserver
values:
ADDRESS: 127.0.0.1:8081
ADDRESS: 127.0.0.1:8080

# Add a capability provider that mediates HTTP access
- name: httpserver
Expand Down
3 changes: 0 additions & 3 deletions examples/rust/actors/http-hello-world/wasmcloud.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ type = "actor"
version = "0.1.0"

[actor]
claims = [
"wasmcloud:httpserver",
]
wit_world = "hello"
wasm_target = "wasm32-wasi-preview2"
27 changes: 9 additions & 18 deletions examples/typescript/actors/http-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This component:

- Uses Typescript for it's implementation
- Uses the [`wasi:http`][wasi-http] standard WIT definitions
- Relies on the [`httpserver` capability provider][httpserver-provider] (which exposes the [`wasmcloud:httpserver` interface][httpserver-interface])
- Relies on the [`httpserver` capability provider][httpserver-provider] (which exposes the [`wasmcloud:httpserver` interface][httpserver-interface])
- Return `"hello from Typescript"` to all HTTP requests
- Can be declaratively provisioned with [`wadm`][wadm]

Expand All @@ -20,11 +20,11 @@ This component:

This relies on the following installed software:

| Name | Description |
|--------|-------------------------------------------------------------------------------------------------|
| Name | Description |
| ------ | ------------------------------------------------------------------------------------------------------- |
| `wash` | [Wasmcloud Shell][wash] controls your [wasmcloud][wasmcloud] host instances and enables building actors |
| `npm` | [Node Package Manager (NPM)][npm] which manages packages for for the NodeJS ecosystem |
| `node` | [NodeJS runtime][nodejs] (see `.nvmrc` for version) |
| `npm` | [Node Package Manager (NPM)][npm] which manages packages for for the NodeJS ecosystem |
| `node` | [NodeJS runtime][nodejs] (see `.nvmrc` for version) |

[wash]: https://github.com/wasmCloud/wasmCloud/tree/main/crates/wash-cli
[node]: https://nodejs.org
Expand Down Expand Up @@ -70,19 +70,6 @@ This will build and sign the actor and place a signed [WebAssembly component][wa
[wasm-component]: https://component-model.bytecodealliance.org/
[jco]: https://github.com/bytecodealliance/jco

## Update WADM manifest with the built actor path

Before we can start the actor, we need to edit our declarative configuration to reflect the path to the built WebAssembly component in `typescript-http-hello-world.wadm.yaml`:

```yaml
properties:
# TODO: you must replace the path below to match your genreated code in build
image: file:///the/absolute/path/to/build/index_s.wasm
```

Replace the `the/absolute/path/...` above with the path to `build/index_s.wasm`.


## Start the actor along with the HTTP server provider

To start the actor, HTTP server provider and everything we need to run:
Expand Down Expand Up @@ -114,3 +101,7 @@ To quickly reload your application after changing the code in `index.ts`:
```console
npm run reload
```

## Adding Capabilities

To learn how to extend this example with additional capabilities, see the [Adding Capabilities](https://wasmcloud.com/docs/tour/adding-capabilities?lang=typescript) section of the wasmCloud documentation.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function handle(req: IncomingRequest, resp: ResponseOutparam) {
let outputStream = outgoingBody.write();
// // Write hello world to the response stream
outputStream.blockingWriteAndFlush(
new Uint8Array(new TextEncoder().encode("hello from Typescript"))
new Uint8Array(new TextEncoder().encode("Hello from Typescript!\n"))
);

// Set the status code for the response
Expand Down
6 changes: 3 additions & 3 deletions examples/typescript/actors/http-hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "ts-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"main": "http-hello-world.js",
"scripts": {
"build:tsc": "tsc",
"build:component": "jco componentize -w wit -o dist/index.wasm dist/index.js",
"build:component": "jco componentize -w wit -o dist/http-hello-world.wasm dist/http-hello-world.js",
"build:actor": "wash build --sign-only --config-path wasmcloud.toml",
"build": "npm run build:tsc && npm run build:component && npm run build:actor",
"actor:start": "wash start actor file://$(realpath dist/index_s.wasm) --auction-timeout-ms 10000 --timeout-ms 10000",
"actor:start": "wash start actor file://$(realpath dist/http_hello_world_s.wasm) --auction-timeout-ms 10000 --timeout-ms 10000",
"actor:stop": "wash stop actor typescript-http-hello-world",
"wadm:start": "wash app deploy wadm.yaml",
"wadm:stop": "wash app delete typescript-http-hello-world v0.0.1",
Expand Down
7 changes: 3 additions & 4 deletions examples/typescript/actors/http-hello-world/wadm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ spec:
- name: typescript-http-hello-world
type: actor
properties:
# TODO: you must replace the path below to match your genreated code in build
image: file:///the/absolute/path/to/build/index_s.wasm
image: file://./build/http_hello_world_s.wasm
traits:
# Govern the spread/scheduling of the actor
- type: spreadscaler
properties:
replicas: 1

# Link the HTTP server, and inform it to listen on port 8081
# Link the HTTP server, and inform it to listen on port 8080
# on the local machine
- type: linkdef
properties:
target: httpserver
values:
ADDRESS: 127.0.0.1:8081
ADDRESS: 127.0.0.1:8080
11 changes: 3 additions & 8 deletions examples/typescript/actors/http-hello-world/wasmcloud.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
name = "typescript-http-hello-world"
#language = "typescript"
# TODO: fix language once https://github.com/wasmCloud/wasmCloud/pull/1295 merges
language = "rust"
language = "typescript"
type = "actor"
version = "0.1.0"

[actor]
claims = [
"wasmcloud:httpserver"
]
wit_world = "hello"
wasm_target = "wasm32-wasi-preview2"

build_command = "npm run build"
build_artifact = "dist/index.wasm"
destination = "build/index_s.wasm"
build_artifact = "dist/http-hello-world.wasm"
destination = "build/http_hello_world_s.wasm"
Loading
Loading