Build and Test Environments with ROMs
Build and test workloads need to run frequently changing code in a stable, isolated runtime, without rebuilding a full image for every change.
This guide shows how to deploy a Go runtime that compiles ROM-provided code before execution.
The base image contains a generic server and Go toolchain.
Each ROM only contains a rom.go file, which the instance compiles into a Go plugin (.so) at startup.
Because only the ROM changes between runs, you update the code under test by pushing a small ROM while the runtime stays as it is.
Prerequisites
-
Install the unikraft CLI. You need a BuildKit builder. The easiest way is via Docker. Alternatively, set up and use BuildKit directly, see the quick start.
-
Clone the
examplesrepository andcdinto theexamples/build-environmentsdirectory:Code
Make sure to log into Unikraft Cloud and pick a metro close to you.
This guide uses fra (Frankfurt, 🇩🇪):
Code
Deployment Workflow
Package the base image
Package and push the base Go runtime image (see server.go for the runtime implementation):
Code
The server in server.go loads /rom/rom.go, compiles it to /run/rom.so using go build -buildmode=plugin, and invokes Handler() from the plugin.
Create an instance template from the base image
Create a short-lived instance from the base image (without ROM attached).
The server writes to /uk/libukp/template_instance and turns the instance into a template before serving requests (see /platform/instances#instance-templates):
Code
The output shows the instance details:
Code
If you are fast enough, you can list information about the instance by running:
Code
This instance is short-lived, since right before the server starts, it triggers a conversion into a template. To check the template is ready, run:
Code
Code
Package the ROMs
Each ROM contains a Go function implementation (see rom1/fs/rom.go and rom2/fs/rom.go).
Code
Create instances from the template with different ROMs attached
Create an instance with the first ROM:
Code
The instance will compile the ROM into a plugin on first start, which may take a few seconds. To check the progress, you can view the instance logs:
Code
Create another instance with the second ROM:
Code
The instance will compile the ROM into a plugin on first start, which may take a few seconds. To check the progress, you can view the instance logs:
Code
List the instances and note their FQDN values:
Code
Code
Test both instances:
Code
Code
Cleanup
Code
Learn more
Use the --help option for detailed information on using Unikraft Cloud:
Code
Or visit the CLI Reference.