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++).
To run this example, follow these steps:
-
Install the unikraft CLI. You need a BuildKit builder. The easiest way to get one is via Docker. Alternatively, you can also directly set up and use BuildKit, see the quick start.
-
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, 🇩🇪):
Code
When done, invoke the following command to deploy this app on Unikraft Cloud:
Code
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
Code
When done, you can remove the instance:
Code
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.7: The currentKraftfilespecification version is0.7. -
runtime: base-compat:latest: The runtime kernel to use is the base compatibility kernel. -
rootfs: Build the app root filesystem.source: ./Dockerfilemeans the filesystem is built using theDockerfile.format: erofsmeans the filesystem type is EROFS. -
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:
Code
Or visit the CLI Reference.