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
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.
Use wash build -o json
to get the absolute path to the locally built component. You can then use wash
to start the component.
# Replace the path below with the path to your component
wash start component file:///Users/wasmcloud/hello/build/hello_s.wasm
If you're running the wasmCloud dashboard, 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
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 wasmcloud.azurecr.io/httpserver:0.19.1
Add a link definition
With both the provider and the component running, the next step is to link the two. This provides a set of configuration values that is unique for each component's use of a provider. To link your component, you'll need the component's public key. You can get that by inspecting your local component file and making note of the Component
key in the output (yours will be different from the output below).
wash inspect ./build/hello_s.wasm
hello - Component
Account ACVKDPI2B3GFBAKURMYXBBDDTMJR3UQ7QLMAGE5Z6NNMTLAR276MZ2WF
Component MDLP5JLL7XMHGAYBUHGRBZHDVE4FIQLB6ONC2ZZG6HPNHPX6HZJ7EAJD
Expires never
Can Be Used immediately
Version 0.1.0 (0)
Call Alias (Not set)
Capabilities
HTTP Server
Tags
None
Once you've got the component's public key, you can export a HELLO_COMPONENT_ID
environment variable with that value and copy-and-paste the link command:
- Unix
- Powershell
# Paste your component ID after the `=` below (with no space after the `=`)
export HELLO_COMPONENT_ID=
wash link put ${HELLO_COMPONENT_ID} VAG3QITQQ2ODAOWB5TTQSDJ53XK3SHBEIFNK4AYJ5RKAX2UNSCAPHA5M wasmcloud:httpserver address=0.0.0.0:8087
# Paste your component ID after the `=` below (with a space after the `=`)
$env:HELLO_COMPONENT_ID =
wash link put $env:HELLO_COMPONENT_ID VAG3QITQQ2ODAOWB5TTQSDJ53XK3SHBEIFNK4AYJ5RKAX2UNSCAPHA5M wasmcloud:httpserver address=0.0.0.0:8087
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:8087
and you should get the response:
Hello World
The component accepts an optional parameter name
, and uses it to change the greeting. (Notice the quotes around the url below).
curl "localhost:8087?name=Carol"
The response should be
Hello Carol
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.