Spin
This guide explains how to create and deploy a simple Spin HTTP app.
This guide comes from Spin's spin-wagi-http example.
It shows how to run a Spin app serving routes from two programs written in different languages (Rust and C++).
Both the Spin executor and the Wagi executor on Unikraft Cloud.
To run it, follow these steps:
-
Install the CLI and a container runtime engine, for example Docker. Use the unikraft CLI or the legacy kraft CLI.
-
Clone the
examplesrepository andcdinto theexamples/spin-wagi-http/directory:
Code
Make sure to log into Unikraft Cloud and pick a metro close to you.
This guide uses fra (Frankfurt, 🇩🇪):
When done, invoke the following command to deploy this app on Unikraft Cloud:
The output shows the instance address and other details:
Code
In this case, the instance name is spin-wagi-http-is72r and the address is https://damp-bobo-wg43p36e.fra.unikraft.app.
They're different for each run.
Then curl the hello route:
Code
And curl the goodbye route:
Code
You can list information about the instance by running:
Code
When done, you can remove the instance:
Customize your app
To customize the app, 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 app filesystemspin.toml: The Spin TOML configuration file
Lines in the Kraftfile have the following roles:
-
spec: v0.6: The currentKraftfilespecification version is0.6. -
runtime: spin:latest: The Unikraft runtime kernel to use is Spin. -
rootfs: ./Dockerfile: Build the app root filesystem using theDockerfile. -
cmd: ["/usr/bin/spin", "up", "--from", "/app/spin.toml", "--listen", "0.0.0.0:3000"]: Usespinas the command to start the app, with the given parameters.
The following options are available for customizing the app:
-
If only updating the existing files under the
wagi-http-cppandhttp-rustdirectories, you don't need to make any other changes. -
If you create any new source files, copy them into the app filesystem by using the
COPYcommand in theDockerfile. -
More extensive changes may require extending the
Dockerfile(seeDockerfilesyntax reference).
Learn more
Use the --help option for detailed information on using Unikraft Cloud:
Or visit the CLI Reference or the legacy CLI Reference.