The ROM feature isn't currently enabled for the public Unikraft Cloud offering.
As such, the KraftKit CLI tool can't entirely leverage this feature.
For boxes where it's enabled, use it via the Unikraft Cloud API.
Unikraft Cloud supports the ability to attach Read-Only Memory (ROM) blobs to instances.
It allows you to create a general-purpose base image and then customize individual instances by attaching code or data as separate ROM blobs.
This enables quick deployment of custom functionality to preexisting language environments without rebuilding the entire image.
Overview
With ROMs, you can:
Deploy variations of an app from a single base image.
Update app code without rebuilding the base image.
Reduce image size and deployment time.
The ROM workflow consists of two main components:
Base Image: A general-purpose image containing the runtime environment (for example, Python interpreter, Node.js, etc.).
ROM Blobs: Separate, lightweight images containing your app code or any other data you want to customize.
This separation allows you to maintain one base image while deploying many different instances with different data.
The app running inside the base image is responsible to read the data from the attached ROM devices.
ROM blobs appear as block devices at paths like /dev/ukp_rom<rom_name>, where <rom_name> is the ROM name you specify when creating the instance.
Setup
This example shows how to deploy Python functions using ROMs on Unikraft Cloud.
Ensure you have the kraft CLI installed and configured with your Unikraft Cloud account.
Set the following environment variables:
export UKC_USER="<your-username>"export UKC_TOKEN="<your-api-token>"export UKC_METRO="fra" # or your preferred metro
Base Image
First, create a base image with a Python HTTP server that loads and executes custom Python programs from a ROM.
Wait a few seconds for propagation and check that the image is present:
kraft cloud image ls
ROM files
To showcase the benefits of using ROMs, create two files, each containing a Python function that the base image will load and execute.
Create a separate directory for each of the ROMs:
Wait a few seconds for propagation and check that the ROMs are present:
kraft cloud image ls
The --no-kernel flag tells kraft to package only the ROM files, without the kernel, since this is data that will get attached to another image.
This example packages the ROMs as EROFS filesystems.
If packaging the ROMs as a cpio archives (that is, --rootfs-type cpio), or as standalone files, you must align their size to 4096 bytes.
kraft cloud instance get test-http-python-rom1kraft cloud instance get test-http-python-rom2
Note the roms array in the instances configurations.
Each ROM is available as a readable device at /dev/ukp_rom_python_function.py (in the form of an EROFS filesystem in this case), which the server program mounts at /tmp/rom.py and executes.
Testing
Query the instances to call the Python function from the ROM.
You should see different responses:
$ curl https://test-http-python-rom1.fra.kraft.cloudHi from 1st ROM!
$ curl https://test-http-python-rom2.fra.kraft.cloudHi from 2nd ROM!