Project Environment Setup

Installation process for kraftkit-

Run curl --proto '=https' --tlsv1.2 -sSf https://get.kraftkit.sh | sh

Breaking down the above command:

curl: curl is a command-line tool used for transferring data with URLs. In this case, it's being used to fetch content from a specified URL.

--proto '=https': This option specifies the protocol that curl should use for the request. It sets the protocol to HTTPS, which is a secure version of HTTP.

--tlsv1.2: This option specifies that curl should use TLS version 1.2 for secure communication. TLS (Transport Layer Security) is a cryptographic protocol used for securing data transmission over the internet.

-sSf: These are options that modify how curl behaves:
    -s or --silent: This option makes curl operate in silent mode, which means it won't show progress information or error messages.
    -S or --show-error: This option tells curl to show error messages if the request encounters an error.
    -f or --fail: This option makes curl exit with an error status if the requested URL returns an HTTP error response.

https://get.kraftkit.sh: This is the URL from which curl will fetch content. In this case, it's fetching a script hosted at 'https://get.kraftkit.sh'.

| sh: This part of the command is using a pipe (|) to pass the content fetched by curl to the sh command for execution. It essentially runs the downloaded script as a shell script.

image

To check the location of kraft if it is installed correctly or not:

image

Assuming you have docker installed and successfully running on your Linux machine.

Run the following command:

docker run -it --rm -v $(pwd):/workspace --entrypoint bash kraftkit.sh/base:latest

Breaking down the above command:

docker run: This is the command to run a Docker container.

-it: These are options that control the interaction with the container:
    -i or --interactive: This option allows you to interact with the container by providing an interactive shell.
    -t or --tty: This option allocates a pseudo-TTY (terminal) for the container, allowing you to see and interact with the shell.

--rm: This option specifies that the container should be automatically removed when it exits. This is useful for cleaning up containers after they are done running.

-v $(pwd):/workspace: This is the volume mounting option, which maps a directory on your host system to a directory inside the container. In this case:
    $(pwd) is a command substitution that gets the current working directory on your host system.
    /workspace is the directory inside the container where the current working directory on the host will be mounted.

--entrypoint bash: This option specifies the entry point for the container. It overrides the default entry point defined in the Docker image and sets it to the Bash shell (bash), allowing you to start an interactive Bash session inside the container.

kraftkit.sh/base:latest: This is the name and tag of the Docker image used to create the container. It indicates that you are using the kraftkit.sh/base image with the latest tag. This image likely contains some specific configuration or environment for a development or execution environment.

image

Hello World App

Create a file named Kraftkit that contains the following information:

libraries{musl(stable)}, targets{name, architecture for which you are creating this unikernel(x86_64), platform(qemu)}

You can edit the following targets and libraries according to your needs.

image

Enter the root directory of your project. Create main.c file and write a basic hello world program in C.

image

Then run nano Makefile.uk that creates a Makefile. Enter the following contents in the Makefile.uk.

image

Make sure to install all the dependencies required to run the unikernel, failing to install the dependencies will cause build errors like this-

image

Resolving the above error by installing musl-libc on my fedora system.

Error resolved!

Tip: You can run kraft clean to remove the existing builds and rebuild the unikernel again to resolve some errors.

Run update pkg and then compile the unikernel using the command kraft build:

image

Finally Run your hello world app using kraft run:

image

References