WasmCloud is a platform that aims to help developers create secure, portable, and reusable components (called actors). It leverages WebAssembly for extreme portability so you can secure, deploy, maintain, observe, and upgrade software, all while reducing the amount of boilerplate that must be copied and pasted.
WasmCloud was designed, from the ground up, around these five core ideas:
- Enterprise-grade security
If you’re just now hearing about WebAssembly, make sure to first read the following pieces: What Is WebAssembly and Why Do You Need It?, Build a WebAssembly App with Rust, and How to Compile C code into WebAssembly with Emscripten.
To finish up out series on WebAssembly, we’re going to walk through the first steps of using wasmCloud.
I’ll be demonstrating on Ubuntu Server 20.01, but you should be able to follow along with any Debian-based distribution, any Linux distribution that supports snap, Fedora, or macOS (but not M1 macs).
With that said, let’s get to the installation.
Before we install wasmCloud, let’s first install Rust. It’s not an absolute dependency, but it is recommended. Log into your Linux server, open a terminal window, and install Rust with the command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
When prompted, type 1 for Proceed with installation (default) and hit Enter on your keyboard. The installation of Rust should complete without any errors. When the installation is finished, you’ll then need to source the environment variables for Rust with the command:
At that point, Rust is installed and ready to go.
Now we can install wasmCloud. The first thing to be done is to add the necessary repository for the software. To do that, go back to your terminal window and issue the command:
curl -s https://packagecloud.io/install/repositories/wasmcloud/core/script.deb.sh | sudo bash
That command should also update apt for you. If it doesn’t, you can do it manually with the command:
sudo apt-get update
Once apt has been successfully updated, install the necessary wasmCloud software with the command:
sudo apt-get install wasmcloud wash -y
Getting Started with wasmCloud
With wasmCloud installed, you’re ready to fire up your first wasmCloud host. Do this with the command:
Your terminal will be split into four panes (Figure 1).
This is a preconfigured wasmCloud host. Your terminal window should be sized to a minimum of 250×50 characters, otherwise, you’ll have to deal with line wrap, which will make everything a bit confusing. It’s also important, as you deploy your actors and providers, that you make note of the IDs of each (found in the bottom right pane) as they deploy. Retrieving those IDs after the fact can be challenging, as they will be truncated.
To view the running hosts, issue the command:
ctl get hosts
The output of the command should list a single host ID and the uptime (in seconds) for that host. To get a list of the inventory of a host, issue the command:
ctl get inventory ID
Where ID is the host ID.
The next thing we’re going to do is run our first actor. WasmCloud has provided a handy Echo sample actor (which merely echos input) to use, which can be started with the command:
ctl start actor wasmcloud.azurecr.io/echo:0.2.1
Once you’ve started the actor, you should see the progress in the top-right pane, which will state Actor starting on host ID (where ID is the ID of the host). The Echo actor only includes a single operator, which is to respond to delivered HTTP requests and will echo the request sent. But in order for this to work, we have to start the HTTP Server provider with the command:
ctl start provider wasmcloud.azurecr.io/httpserver:0.12.1
Now, let’s view the host inventory again with the command:
ctl get inventory ID
Where ID is the host ID.
This time you should see both the Echo actor and the HTTP provider included (Figure 2).
Now that we have both the actor and provider started, we have to connect them so they can function properly. For this, you’ll need the Actor ID and Provider ID (which you should have copied down as each was deployed).
To connect these two together, the command will be:
ctl link ACTORID PROVIDERID wasmcloud:httpserver PORT=8080
Where ACTORID is the ID of the Echo actor and PROVIDERID is the ID of the HTTP provider.
You should see something like:
Advertised link (MBCF) <-> (VAG3) successfully
Let’s interact with our newly-linked actor. Open a second terminal to your hosting server and issue the command:
You should see returned:
That’s a successful call to your linked actor and provider.
To exit out of the wasmCloud console, just type exit and you’re out. Just remember, once you exit, your actors and providers will no longer be available (so you’ll have to deploy them again if you want to use them).
Congratulations, you’ve taken your first steps with wasmCloud. To learn more about this powerful tool, check out the wasmCloud App Development documentation.