Process images with Imaginary
This example uses Imaginary
, an HTTP microservice for high-level image processing.
Imaginary can be deployed as Unikraft Cloud service and can be queried via HTTP to process images.
To run this example, follow these steps:
-
Install the
kraft
CLI tool and a container runtime engine, e.g. Docker. -
Clone the
examples
repository andcd
into theexamples/imaginary/
directory:
git clone https://github.com/kraftcloud/examplescd examples/imaginary/
Make sure to log into Unikraft Cloud by setting your token and a metro close to you.
We use fra0
(Frankfurt, 🇩🇪) in this guide:
# Set Unikraft Cloud access tokenexport UKC_TOKEN=token# Set metro to Frankfurt, DEexport UKC_METRO=fra0
When done, invoke the following command to deploy this application on Unikraft Cloud:
kraft cloud deploy -p 443:8080 -M 256 .
The output shows the instance URL and other details:
[●] Deployed successfully! │ ├────────── name: imaginary-mwb4y ├────────── uuid: 8cf18bf7-2bf6-4f23-be07-f9c234c7962d ├───────── state: running ├─────────── url: https://divine-wind-1ycjvhqs.fra0.kraft.host ├───────── image: sha256:673834bc531038bb621266f7fd635a04e559050cbe82876df811fd4b975ea4fe ├───── boot time: 32.26 ms ├──────── memory: 256 MiB ├─────── service: divine-wind-1ycjvhqs ├── private fqdn: imaginary-mwb4y.internal ├──── private ip: 172.16.3.3 └────────── args: /usr/bin/imaginary -p 8080
In this case, the instance name is imaginary-mwb4y
and the URL is https://divine-wind-1ycjvhqs.fra0.kraft.host
.
They are different for each run.
Use curl
to query the Unikraft Cloud instance of Imaginary.
You will get a health status of the service:
curl -s https://divine-wind-1ycjvhqs.fra0.kraft.host/health | jq
{ "uptime": 414, "allocatedMemory": 0.19, "totalAllocatedMemory": 0.72, "goroutines": 6, "completedGCCycles": 13, "cpus": 1, "maxHeapUsage": 3.63, "heapInUse": 0.19, "objectsInUse": 846, "OSMemoryObtained": 7.73}
To test the Imaginary instance on Unikraft Cloud use the /form
endpoint.
That is, open the https://divine-wind-1ycjvhqs.fra0.kraft.host/form
URL in the browser and use the existing forms to process an image.
To make actual use of the Imaginary instance, use the endpoints of the HTTP API.
Endpoints are provided, together with parameters, for different image processing options: /crop
, /resize
, /flip
, /convert
, /watermark
, /rotate
, /blur
etc.
At any point in time, you can list information about the instance:
kraft cloud instance list
NAME FQDN STATE CREATED AT IMAGE MEMORY ARGS BOOT TIMEimaginary-mwb4y divine-wind-1ycjvhqs.fra0.kraft.host running 54 seconds ago sha256:673834bc531038bb621266f7fd635a04e5... 256 MiB /usr/bin/imaginary -p 8080 32262us
When done, you can remove the instance:
kraft cloud instance remove divine-wind-1ycjvhqs
The Imaginary Unikraft Cloud service mostly works as is: you deploy it and then you query the endpoints of the HTTP API.
You can customize the command line options used to start the service, by updating the cmd
line in the Kraftfile
:
spec: v0.6
runtime: imaginary:1.2
cmd: ["/usr/bin/imaginary", "-p", "8080"]
You can update the cmd
line with command line option for Imaginary.
Learn More
Use the --help
option for detailed information on using Unikraft Cloud:
kraft cloud --help
Or visit the CLI Reference.