Building Nginx Application Using Unikraft
Hacking with Unikraft 01
Project workflow
unikraft/lib
: Internal core libraries but we don’t necessarily need all of them for our application so when we built our application then at that time we configure the unikraft core libraries to suit our needs.
Similary, we add the external libraries which is not directly maintained by unikraft community.
We link those libraries to our application while building it. These repository are present outside of unikraft core repo.
For example: lib-musl
, lib-lwip
these are few C standard external libraries.
Build Nginx App
Step: Run the following commands in sequence-
git clone unikraft/app-nginx.git
cd app-nginx
cat Makefile
We will need to install these three libraries(dependencies) in order to built an nginx server. lib-lwip, lib-musl, lib-nginx
mkdir .unikraft
cd .unikraft
mkdir unikraft
mkdir libs
cd libs
Let’s clone those three dependencies-
git clone /lib-lwip
git clone /lib-musl
git clone /lib-nginx
cd ..
git clone unikraft-repo
cd ..
make menuconfig
: Create configuration tree of unikraft and give us an interactive method of configuring our app.
Inside the library config-
You can see all the libraries that were inside the unikraft/lib github folder.
Our Task
We need to build our nginx application for x86 architecture for KVM platform.
-
Select the architecture →
x_86
-
Go to
library config
→ selectlibnginx
.
Most options got selected but we also need to select the main
function. Select the main
function so that we run our application directly once the unikernel starts running.
Tip- Square brackets mean that those options can be changed, click on the
spacebar
key to select/unselect the option.
-
We have to use
9pfs
so we need to mount the root file system. -
Go to
library config
->vfcore config
Select automatically mount a root filesystem(/) -> default root filesystem -> select 9pfs -
Go to
Platform config
-> selectKVM guest
Save the new configuration
- Run
make
ormake -j8
(to compile faster by setting the number of cores you want to use)
It started compiling. It compiles in an order we set in config file -> first lwip-> musl -> nginx and then link everything together.
See the results -> Run ls build
-> We can see the app image app-nginx_qemu-x86_64
.