Spin
In this guide we create and deploy a simple Spin HTTP app. This guide is derived from
Spin's spin-wagi-http
example
and shows how to run a Spin application serving routes from two programs written in
different languages (Rust and C++) using both the Spin executor and the Wagi executor
on Unikraft Cloud. To run it, follow these steps:
-
Install the
kraft
CLI tool and a container runtime engine, e.g. Docker. -
Clone the
examples
repository andcd
into theexamples/spin-wagi-http/
directory:
Code
Make sure to log into Unikraft Cloud by setting your token and a metro close to you.
We use fra0
(Frankfurt, ๐ฉ๐ช) in this guide:
Code
When done, invoke the following command to deploy this application on Unikraft Cloud:
Code
The output shows the instance URL and other details:
Code
In this case, the instance name is spin-wagi-http-is72r
and the URL is https://damp-bobo-wg43p36e.fra0.kraft.host
.
They are different for each run.
Then curl
the hello route:
Code
And curl
the goodbye route:
Code
At any point in time, you can list information about the instance:
Code
Code
When done, you can remove the instance:
Code
Customize your Application
To customize the application, update the files in the repository, listed below:
wagi-http-cpp
: C++ server handling the hello routehttp-rust
: Rust server handling the goodbye routeKraftfile
: the Unikraft Cloud specificationDockerfile
: the Docker-specified application filesystemspin.toml
: The Spin TOML configuration file
Lines in the Kraftfile
have the following roles:
-
spec: v0.6
: The currentKraftfile
specification version is0.6
. -
runtime: spin:latest
: The Unikraft runtime kernel to use is Spin. -
rootfs: ./Dockerfile
: Build the application root filesystem using theDockerfile
. -
cmd: ["/usr/bin/spin", "up", "--from", "/app/spin.toml", "--listen", "0.0.0.0:3000"]
: Usespin
as the command to start the app, with the given parameters.
The following options are available for customizing the application:
-
If only updating the existing files under the
wagi-http-cpp
andhttp-rust
directories, no other change is required. -
If new files are added, these have to be copied in the application filesystem, using the
COPY
command in theDockerfile
. -
More extensive changes may require expanding the
Dockerfile
with additionalDockerfile
commands.
Learn More
Use the --help
option for detailed information on using Unikraft Cloud:
Code
Or visit the CLI Reference.