Run
In the first getting started guide of wasmCloud you deployed a component using wadm via the wash app deploy
command.
Now, we're going to start the component "the long way" so that you can get a feel for all of the moving parts of the process. Our tooling documentation should help you get components started more easily, once you've been through this guide.
We assume you've already installed wash, the wasmCloud host, and necessary prerequisites.
Build the component
Building the component is as easy as running wash build
in the project's root directory. The previous Build page has more details on the build process.
Start the component
If you don't have a host running, you can start one with wash up
.
The simplest way to get a component running is by starting it from a locally built file. wasmCloud has support for starting built and signed components from absolute paths in addition to starting from OCI registries.
The wash build
output will include the path to the locally built component. You can then use wash
to start the component.
# wash start component <path-to-component> <component-id>
wash start component file:///Users/wasmcloud/hello/build/http_hello_world_s.wasm hello
If you're running the wasmCloud dashboard with wash ui
, you can take a look at your running component by visiting localhost:3000 in your browser. Alternatively, you can use wash
to query the inventory of your running hosts:
wash get inventory
➜ wash get inventory
Host Inventory (NBPDHEE4FT75YJ7DLY2Y6W6WA2Z26ISRHSO5X3XBFBPAV53EI3GCPBHV)
hostcore.os macos
hostcore.arch aarch64
hostcore.osfamily unix
Component ID Name Image Reference
hello http-hello-world file:///Users/wasmcloud/hello/build/http_hello_world_s.wasm
Start the web server
We know our new component needs a web server, so let's start the HTTP server capability provider.
wash start provider ghcr.io/wasmcloud/http-server:0.22.0 http-server
Add a link
> wash inspect --wit ./build/http_hello_world_s.wasm
package root:component;
world root {
# ..imports
export wasi:http/incoming-handler@0.2.0;
}
With both the provider and the component running, the next step is to link the two. Our component implements the function wasi:http/incoming-handler.handle
, and the wasmCloud HTTP server provider is configured to call that function whenever it receives an HTTP request on the specified port.
First, create a named configuration for the HTTP server capability provider:
wash config put hello-listen-address address=0.0.0.0:8085
Then, link the provider to the component and pass the configuration to the provider (the source of the link):
# wash link put <source> <target> <namespace> <package> --source-config <config> --interface <interface>
wash link put http-server hello wasi http --source-config hello-listen-address --interface incoming-handler
At this point your HTTP server capability provider has been notified that a link definition was created, and it started the corresponding web server listening on port 8087
. You can now hit that endpoint and exercise the code you just wrote:
curl localhost:8085
and you should get the response:
Hello from Rust!
This page took you through the process of imperatively starting a component and a capability provider, and then linking them together. You can use these commands as you develop to work with running resources, or just use wash app to deploy the same resources declaratively.
Let's make a slight modification to the code, so you can see what it's like to go through a development iteration to compile and update the running code. Don't worry - this will be pretty quick.