Zudoku
Guides

Imaginary

This example uses imaginary, an HTTP microservice for high-level image processing.

To run this example, follow these steps:

  1. Install the kraft CLI tool and a container runtime engine, for example Docker.

  2. Clone the examples repository and cd into the examples/imaginary/ directory:

Code(bash)
git clone https://github.com/kraftcloud/examples cd examples/imaginary/

Make sure to log into Unikraft Cloud by setting your token and a metro close to you. This guide uses fra (Frankfurt, ๐Ÿ‡ฉ๐Ÿ‡ช):

Code(bash)
# Set Unikraft Cloud access token export UKC_TOKEN=token # Set metro to Frankfurt, DE export UKC_METRO=fra

When done, invoke the following command to deploy this app on Unikraft Cloud:

Code(bash)
kraft cloud deploy -p 443:8080 -M 256 .

The output shows the instance address and other details:

Code(ansi)
[โ—] Deployed successfully! โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ name: imaginary-mwb4y โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ uuid: 8cf18bf7-2bf6-4f23-be07-f9c234c7962d โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ state: running โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ url: https://divine-wind-1ycjvhqs.fra.unikraft.app โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ 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 address is https://divine-wind-1ycjvhqs.fra.unikraft.app. They're different for each run.

Use curl to query the Unikraft Cloud instance of Imaginary. You will get a health status of the service:

Code(bash)
curl -s https://divine-wind-1ycjvhqs.fra.unikraft.app/health | jq
Code(json)
{ "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.fra.unikraft.app/form address 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. The API provides endpoints, together with parameters, for different image processing options: /crop, /resize, /flip, /convert, /watermark, /rotate, /blur etc.

You can list information about the instance by running:

Code(bash)
kraft cloud instance list
Code(text)
NAME FQDN STATE CREATED AT IMAGE MEMORY ARGS BOOT TIME imaginary-mwb4y divine-wind-1ycjvhqs.fra.unikraft.app running 54 seconds ago sha256:673834bc531038bb621266f7fd635a04e5... 256 MiB /usr/bin/imaginary -p 8080 32262us

When done, you can remove the instance:

Code(bash)
kraft cloud instance remove divine-wind-1ycjvhqs

The Imaginary Unikraft Cloud service 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:

Code(yaml)
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:

Code(bash)
kraft cloud --help

Or visit the CLI Reference.

Last modified on