Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions elfloader-nginx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/workdir/
/rootfs/
firecracker.socket
38 changes: 38 additions & 0 deletions elfloader-nginx/Config.uk
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Configure ELF loader application, with networking support and NGINX.

config APPELFLOADERNETNGINX
bool "Configure NGINX ELF loader application (for binary compatibility) with networking support"
default y

# Select app-elfloader component.
select APPELFLOADER_DEPENDENCIES

# Configurations options for app-elfloader
# (they can't be part of the template atm)
select APPELFLOADER_ARCH_PRCTL
select APPELFLOADER_BRK
select APPELFLOADER_CUSTOMAPPNAME
select APPELFLOADER_STACK_NBPAGES
select APPELFLOADER_VFSEXEC_EXECBIT
select APPELFLOADER_VFSEXEC
select APPELFLOADER_HFS
select APPELFLOADER_HFS_ETCRESOLVCONF
select APPELFLOADER_HFS_ETCHOSTS
select APPELFLOADER_HFS_ETCHOSTNAME
select APPELFLOADER_HFS_REPLACEEXIST

# Select filesystem implementation: cpio, ramfs, devfs.
select LIBVFSCORE
select LIBVFSCORE_AUTOMOUNT_UP
select LIBRAMFS
select LIBUKCPIO
select LIBDEVFS
select LIBDEVFS_AUTOMOUNT

# Select LWIP networking stack library.
select LIBLWIP

# Use extended information (einfo) for configuring network parameters.
# This component parses the configuration string in the command line:
# netdev.ip=172.44.0.2/24:172.44.0.1:::
select LIBUKNETDEV_EINFO_LIBPARAM
37 changes: 37 additions & 0 deletions elfloader-nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM nginx:1.25.3-bookworm AS build

# These are normally syminks to /dev/stdout and /dev/stderr, which don't
# (currently) work with Unikraft. We remove them, such that Nginx will create
# them by hand.
RUN rm /var/log/nginx/error.log
RUN rm /var/log/nginx/access.log

FROM scratch

# Nginx binaries, modules, configuration, log and runtime files
COPY --from=build /usr/sbin/nginx /usr/bin/nginx
COPY --from=build /usr/lib/nginx /usr/lib/nginx
COPY --from=build /etc/nginx /etc/nginx
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /etc/group /etc/group
COPY --from=build /var/log/nginx /var/log/nginx
COPY --from=build /var/cache/nginx /var/cache/nginx
COPY --from=build /var/run /var/run

# Libraries
COPY --from=build /lib/x86_64-linux-gnu/libcrypt.so.1 /lib/x86_64-linux-gnu/libcrypt.so.1
COPY --from=build /lib/x86_64-linux-gnu/libpcre2-8.so.0 /lib/x86_64-linux-gnu/libpcre2-8.so.0
COPY --from=build /lib/x86_64-linux-gnu/libssl.so.3 /lib/x86_64-linux-gnu/libssl.so.3
COPY --from=build /lib/x86_64-linux-gnu/libcrypto.so.3 /lib/x86_64-linux-gnu/libcrypto.so.3
COPY --from=build /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1
COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
COPY --from=build /etc/ld.so.cache /etc/ld.so.cache

# Custom configuration files
COPY ./nginx/conf/nginx.conf /etc/nginx/nginx.conf

# Web root
COPY ./nginx/html /wwwroot

COPY ./nginx/logs /etc/nginx/logs
13 changes: 13 additions & 0 deletions elfloader-nginx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
UK_ROOT ?= $(PWD)/workdir/unikraft
UK_BUILD ?= $(PWD)/workdir/build
UK_APP ?= $(PWD)/workdir/apps/elfloader
LIBS_BASE = $(PWD)/workdir/libs
UK_LIBS ?= $(LIBS_BASE)/libelf:$(LIBS_BASE)/lwip

.PHONY: all

all:
@$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD)

$(MAKECMDGOALS):
@$(MAKE) -C $(UK_ROOT) L=$(UK_LIBS) A=$(UK_APP) O=$(UK_BUILD) $(MAKECMDGOALS)
Empty file added elfloader-nginx/Makefile.uk
Empty file.
21 changes: 21 additions & 0 deletions elfloader-nginx/fc.x86_64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"boot-source": {
"kernel_image_path": "workdir/build/elfloader_fc-x86_64",
"boot_args": "elfloader_fc-x86_64 netdev.ip=172.44.0.2/24:172.44.0.1::: vfs.fstab=[ \"initrd0:/:extract::ramfs=1:\" ] -- ./usr/bin/nginx",
"initrd_path": "initrd.cpio"
},
"drives": [],
"machine-config": {
"vcpu_count": 1,
"mem_size_mib": 512,
"smt": false,
"track_dirty_pages": false
},
"network-interfaces": [
{
"iface_id": "net1",
"guest_mac": "06:00:ac:10:00:02",
"host_dev_name": "tap0"
}
]
}
96 changes: 96 additions & 0 deletions elfloader-nginx/nginx/conf/mime.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;

text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;

image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;

font/woff woff;
font/woff2 woff2;

application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;

application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;

audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;

video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}
33 changes: 33 additions & 0 deletions elfloader-nginx/nginx/conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
worker_processes 1;
daemon off;
master_process off;
user root root;

events {
worker_connections 64;
}

http {
include mime.types;
default_type application/octet-stream;

open_file_cache max=10000 inactive=30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;

error_log stderr error;
access_log off;

keepalive_timeout 10s;
keepalive_requests 10000;
send_timeout 10s;

server {
listen 80;

server_name localhost;

root /wwwroot;
index index.html;
}
}
9 changes: 9 additions & 0 deletions elfloader-nginx/nginx/html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello from Unikraft!</title>
</head>
<body>
<h1>Hello from Unikraft!</h1>
</body>
</html>
Empty file.
39 changes: 39 additions & 0 deletions elfloader-nginx/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh

check_exists_and_create_symlink()
{
path="$1"

if ! test -d workdir/"$path"; then
if ! test -d ../repos/"$path"; then
echo "No directory ../repos/$path. Run the top-level setup.sh script first." 1>&2
exit 1
fi
depth=$(echo "$path" | awk -F / '{ print NF }')
if test "$depth" -eq 1; then
ln -sfn ../../repos/"$path" workdir/"$path"
elif test "$depth" -eq 2; then
ln -sfn ../../../repos/"$path" workdir/"$path"
else
echo "Unknown depth of path $path." 1>&2
exit 1
fi
fi
}

if ! test -d workdir; then
mkdir workdir
fi

if ! test -d workdir/libs; then
mkdir workdir/libs
fi

if ! test -d workdir/apps; then
mkdir workdir/apps
fi

check_exists_and_create_symlink "unikraft"
check_exists_and_create_symlink "libs/lwip"
check_exists_and_create_symlink "libs/libelf"
check_exists_and_create_symlink "apps/elfloader"