diff --git a/library/caddy/2.7/README.md b/library/caddy/2.7/README.md new file mode 100644 index 00000000..37c4f68e --- /dev/null +++ b/library/caddy/2.7/README.md @@ -0,0 +1,65 @@ +# Caddy 2.7 + +This directory contains the definition for building the `unikraft.org/caddy:2.7` image. + +## Build + +To build this image, first create the root filesystem and the `Kraftfile` from `Kraftfile.template`: + +```console +make initrd +``` + +Then build the images: + +```console +kraft build --no-cache --arch x86_64 --plat fc +kraft build --no-cache --arch x86_64 --plat qemu +``` + +## Package + +```console +kraft pkg --name index.unikraft.io/unikraft.org/caddy:2.7 --strategy overwrite --push +``` + +## Run + +To run this image, [install Unikraft's companion command-line toolchain `kraft`](https://unikraft.org/docs/cli) and then you can run, for QEMU: + +```console +sudo kraft net create -n 172.44.0.1/24 virbr0 +sudo kraft run \ + -W \ + --memory 256M \ + --log-level debug --log-type basic \ + --network bridge:virbr0 \ + --arch x86_64 --plat qemu \ + .unikraft/build/2.7_qemu-x86_64 \ + -a netdev.ipv4_addr=172.44.0.2 -a netdev.ipv4_gw_addr=172.44.0.1 -a netdev.ipv4_subnet_mask=255.255.255.0 \ + -- $cmd +``` + +For Firecracker (RD: this doesn't work for me): + +``` +sudo kraft net create -n 172.44.0.1/24 virbr0 +sudo kraft run \ + --memory 256M \ + --log-level debug --log-type basic \ + --network bridge:virbr0 \ + --arch x86_64 --plat fc \ + .unikraft/build/2.7_fc-x86_64 \ + -a netdev.ipv4_addr=172.44.0.2 -a netdev.ipv4_gw_addr=172.44.0.1 -a netdev.ipv4_subnet_mask=255.255.255.0 \ + -- $cmd +``` + +Once executed, it will open port `2015` on IP address `172.44.0.2` and wait for connections, and can be queried on: + +```console +curl 172.44.0.2:2015 +``` + +## See also + +- [How to run unikernels locally in Unikraft's Documentation](https://unikraft.org/docs/cli/running). diff --git a/library/caddy/2.7/fc-initrd.json b/library/caddy/2.7/fc-initrd.json new file mode 100644 index 00000000..29e7cdf4 --- /dev/null +++ b/library/caddy/2.7/fc-initrd.json @@ -0,0 +1,33 @@ +{ + "boot-source": { + "kernel_image_path": ".unikraft/build/2.7_fc-x86_64", + "boot_args": "kernel netdev.ipv4_addr=172.44.0.2 netdev.ipv4_gw_addr=172.44.0.1 netdev.ipv4_subnet_mask=255.255.255.0 vfs.fstab=[ \"initrd:/data:initrd:::\" ] -- /usr/local/bin/caddy run --config /data/Caddyfile", + "initrd_path": "data.cpio" + }, + "drives": [], + "machine-config": { + "vcpu_count": 1, + "mem_size_mib": 256, + "smt": false, + "track_dirty_pages": false + }, + "cpu-config": null, + "balloon": null, + "network-interfaces": [ + { + "iface_id": "net1", + "guest_mac": "06:00:ac:10:00:02", + "host_dev_name": "tap0" + } + ], + "vsock": null, + "logger": { + "log_path": "/tmp/firecracker.log", + "level": "Debug", + "show_level": true, + "show_log_origin": true + }, + "metrics": null, + "mmds-config": null, + "entropy": null +} diff --git a/library/caddy/2.7/fc.json b/library/caddy/2.7/fc.json new file mode 100644 index 00000000..da25cce8 --- /dev/null +++ b/library/caddy/2.7/fc.json @@ -0,0 +1,32 @@ +{ + "boot-source": { + "kernel_image_path": ".unikraft/build/2.7_fc-x86_64", + "boot_args": "kernel netdev.ipv4_addr=172.44.0.2 netdev.ipv4_gw_addr=172.44.0.1 netdev.ipv4_subnet_mask=255.255.255.0 -- /usr/local/bin/caddy run --config /data/Caddyfile" + }, + "drives": [], + "machine-config": { + "vcpu_count": 1, + "mem_size_mib": 256, + "smt": false, + "track_dirty_pages": false + }, + "cpu-config": null, + "balloon": null, + "network-interfaces": [ + { + "iface_id": "net1", + "guest_mac": "06:00:ac:10:00:02", + "host_dev_name": "tap0" + } + ], + "vsock": null, + "logger": { + "log_path": "/tmp/firecracker.log", + "level": "Debug", + "show_level": true, + "show_log_origin": true + }, + "metrics": null, + "mmds-config": null, + "entropy": null +} diff --git a/library/caddy/2.7/kraft-run-fc.sh b/library/caddy/2.7/kraft-run-fc.sh new file mode 100755 index 00000000..821a07ea --- /dev/null +++ b/library/caddy/2.7/kraft-run-fc.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +cmd="/usr/local/bin/caddy run --config /data/Caddyfile" +rootfs="data/" + +# Clean up any previous instances. +sudo pkill -f qemu-system +sudo pkill -f firecracker +sudo kraft stop --all +sudo kraft rm --all + +# Create CPIO archive to be used as the initrd. +old="$PWD" +cd "$rootfs" +find -depth -print | tac | bsdcpio -o --format newc > "$old"/data.cpio +cd "$old" + +# Remove previously created network interfaces. +sudo ip link set dev tap0 down 2> /dev/null +sudo ip link del dev tap0 2> /dev/null +sudo ip link set dev virbr0 down 2> /dev/null +sudo ip link del dev virbr0 2> /dev/null + +# Create bridge interface for KraftKit networking. +sudo kraft net create -n 172.44.0.1/24 virbr0 + +sudo kraft run \ + --memory 256M \ + --log-level debug --log-type basic \ + --network bridge:virbr0 \ + --arch x86_64 --plat fc \ + .unikraft/build/2.7_fc-x86_64 \ + -a netdev.ipv4_addr=172.44.0.2 -a netdev.ipv4_gw_addr=172.44.0.1 -a netdev.ipv4_subnet_mask=255.255.255.0 \ + -- $cmd diff --git a/library/caddy/2.7/kraft-run-qemu.sh b/library/caddy/2.7/kraft-run-qemu.sh new file mode 100755 index 00000000..b32ff101 --- /dev/null +++ b/library/caddy/2.7/kraft-run-qemu.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +cmd="/usr/local/bin/caddy run --config /data/Caddyfile" +rootfs="data/" + +# Clean up any previous instances. +sudo pkill -f qemu-system +sudo pkill -f firecracker +sudo kraft stop --all +sudo kraft rm --all + +# Create CPIO archive to be used as the initrd. +old="$PWD" +cd "$rootfs" +find -depth -print | tac | bsdcpio -o --format newc > "$old"/data.cpio +cd "$old" + +# Remove previously created network interfaces. +sudo ip link set dev tap0 down 2> /dev/null +sudo ip link del dev tap0 2> /dev/null +sudo ip link set dev virbr0 down 2> /dev/null +sudo ip link del dev virbr0 2> /dev/null + +# Create bridge interface for KraftKit networking. +sudo kraft net create -n 172.44.0.1/24 virbr0 + +sudo kraft run \ + -W \ + --memory 256M \ + --log-level debug --log-type basic \ + --network bridge:virbr0 \ + --arch x86_64 --plat qemu \ + .unikraft/build/2.7_qemu-x86_64 \ + -a netdev.ipv4_addr=172.44.0.2 -a netdev.ipv4_gw_addr=172.44.0.1 -a netdev.ipv4_subnet_mask=255.255.255.0 \ + -- $cmd diff --git a/library/caddy/2.7/run-fc.sh b/library/caddy/2.7/run-fc.sh new file mode 100755 index 00000000..7e6c38cf --- /dev/null +++ b/library/caddy/2.7/run-fc.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +config="fc.json" + +if test $# -eq 1; then + config="$1" +fi + +rootfs="data/" + +# Clean up any previous instances. +sudo pkill -f qemu-system +sudo pkill -f firecracker +sudo kraft stop --all +sudo kraft rm --all + +# Create CPIO archive to be used as the initrd. +old="$PWD" +cd "$rootfs" +find -depth -print | tac | bsdcpio -o --format newc > "$old"/data.cpio +cd "$old" + +# Remove previously created network interfaces. +sudo ip link set dev tap0 down 2> /dev/null +sudo ip link del dev tap0 2> /dev/null +sudo ip link set dev virbr0 down 2> /dev/null +sudo ip link del dev virbr0 2> /dev/null + +# Create tap interface for Firecracker networking. +sudo ip tuntap add dev tap0 mode tap +sudo ip address add 172.44.0.1/24 dev tap0 +sudo ip link set dev tap0 up + +# Remove previously created files. +sudo rm -f /tmp/firecracker.log +> /tmp/firecracker.log +sudo rm -f /tmp/firecracker.socket +sudo firecracker-x86_64 \ + --api-sock /tmp/firecracker.socket \ + --config-file "$config" diff --git a/library/caddy/2.7/run-qemu-initrd.sh b/library/caddy/2.7/run-qemu-initrd.sh new file mode 100755 index 00000000..1faeed2d --- /dev/null +++ b/library/caddy/2.7/run-qemu-initrd.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +kernel=".unikraft/build/2.7_qemu-x86_64" +cmd="/usr/local/bin/caddy run --config /data/Caddyfile" +rootfs="data/" + +# Clean up any previous instances. +sudo pkill -f qemu-system > /dev/null 2>&1 +sudo pkill -f firecracker > /dev/null 2>&1 +sudo kraft stop --all > /dev/null 2>&1 +sudo kraft rm --all > /dev/null 2>&1 + +# Create CPIO archive to be used as the initrd. +old="$PWD" +cd "$rootfs" +find -depth -print | tac | bsdcpio -o --format newc > "$old"/data.cpio +cd "$old" + +# Remove previously created network interfaces. +sudo ip link set dev tap0 down 2> /dev/null +sudo ip link del dev tap0 2> /dev/null +sudo ip link set dev virbr0 down 2> /dev/null +sudo ip link del dev virbr0 2> /dev/null + +# Create bridge interface for QEMU networking. +sudo ip link add dev virbr0 type bridge +sudo ip address add 172.44.0.1/24 dev virbr0 +sudo ip link set dev virbr0 up + +sudo qemu-system-x86_64 \ + -enable-kvm \ + -kernel "$kernel" \ + -nographic \ + -m 256M \ + -netdev bridge,id=en0,br=virbr0 -device virtio-net-pci,netdev=en0 \ + -append "netdev.ipv4_addr=172.44.0.2 netdev.ipv4_gw_addr=172.44.0.1 netdev.ipv4_subnet_mask=255.255.255.0 vfs.fstab=[ \"initrd:/data:initrd:::\" ] -- $cmd" \ + -initrd ./data.cpio \ + -cpu max diff --git a/library/caddy/2.7/run-qemu.sh b/library/caddy/2.7/run-qemu.sh new file mode 100755 index 00000000..acff856b --- /dev/null +++ b/library/caddy/2.7/run-qemu.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +kernel=".unikraft/build/2.7_qemu-x86_64" +cmd="/usr/local/bin/caddy run --config /data/Caddyfile" + +# Clean up any previous instances. +sudo pkill -f qemu-system > /dev/null 2>&1 +sudo pkill -f firecracker > /dev/null 2>&1 +sudo kraft stop --all > /dev/null 2>&1 +sudo kraft rm --all > /dev/null 2>&1 + +# Remove previously created network interfaces. +sudo ip link set dev tap0 down 2> /dev/null +sudo ip link del dev tap0 2> /dev/null +sudo ip link set dev virbr0 down 2> /dev/null +sudo ip link del dev virbr0 2> /dev/null + +# Create bridge interface for QEMU networking. +sudo ip link add dev virbr0 type bridge +sudo ip address add 172.44.0.1/24 dev virbr0 +sudo ip link set dev virbr0 up + +sudo qemu-system-x86_64 \ + -enable-kvm \ + -kernel "$kernel" \ + -nographic \ + -m 256M \ + -netdev bridge,id=en0,br=virbr0 -device virtio-net-pci,netdev=en0 \ + -append "netdev.ipv4_addr=172.44.0.2 netdev.ipv4_gw_addr=172.44.0.1 netdev.ipv4_subnet_mask=255.255.255.0 -- $cmd" \ + -cpu max