-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): Introduce Caddy as example
Introduce Caddy as binary compatibility run. Build Caddy as static PIE application using `Dockerfile`. Then run it with the `base` kernel images from `../../kernels/`. Add typical files for a bincompat app: * `Kraftfile`: build / run rules, including pulling the `base` image * `Dockerfile`: filesystem, including binary and libraries * `Makefile`: used to generate the root filesystem from the `Dockerfile` rules * `README.md`: instructions to set up, build and run the application * `config.yaml`: configuration file to generate scripts to the application * `hosts`, `Caddyfile`: required Caddy configuration files `config.yaml` is used to generate run scripts using the `../../utils/bincompat/generate.py` script. The kernels in `../../kernels` are generated by running the `../../utils/bincompat/base-build-all.sh` script while inside the `../../library/base/` directory. Signed-off-by: Razvan Deaconescu <[email protected]>
- Loading branch information
Showing
8 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/rootfs/ | ||
/rootfs.cpio | ||
/run-qemu* | ||
/run-fc* | ||
/kraft-run-* | ||
/fc*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:2015 | ||
|
||
respond "Hello, World!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FROM --platform=linux/x86_64 golang:1.21.4-bookworm AS build | ||
|
||
# Inspired from: https://github.com/caddyserver/caddy-docker/blob/master/2.7/builder/Dockerfile | ||
|
||
RUN set -xe; apt-get update ; \ | ||
apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
git \ | ||
libcap2-bin \ | ||
; | ||
|
||
ENV XCADDY_VERSION v0.3.5 | ||
# Configures xcaddy to build with this version of Caddy | ||
ENV CADDY_VERSION v2.7.5 | ||
# Configures xcaddy to not clean up post-build (unnecessary in a container) | ||
ENV XCADDY_SKIP_CLEANUP 1 | ||
# Sets capabilities for output caddy binary to be able to bind to privileged ports | ||
ENV XCADDY_SETCAP 1 | ||
|
||
RUN set -xe; \ | ||
wget -O /tmp/xcaddy.tar.gz "https://github.com/caddyserver/xcaddy/releases/download/v0.3.5/xcaddy_0.3.5_linux_amd64.tar.gz"; \ | ||
tar x -z -f /tmp/xcaddy.tar.gz -C /usr/bin xcaddy; \ | ||
rm -f /tmp/xcaddy.tar.gz; \ | ||
chmod +x /usr/bin/xcaddy; | ||
|
||
ENV CGO_ENABLED=1 | ||
ENV XCADDY_GO_BUILD_FLAGS "-buildmode=pie -ldflags '-linkmode external -extldflags -static-pie'" | ||
|
||
RUN /usr/bin/xcaddy build | ||
|
||
FROM scratch | ||
|
||
COPY --from=build /go/caddy /usr/local/bin/caddy | ||
COPY Caddyfile /etc/caddy/Caddyfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
spec: v0.6 | ||
|
||
name: caddy | ||
|
||
runtime: index.unikraft.io/unikraft.org/base:latest | ||
|
||
rootfs: ./rootfs | ||
|
||
cmd: ["/usr/local/bin/caddy", "run", "--config", "/etc/caddy/Caddyfile"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
IMAGE_NAME = unikraft-caddy | ||
|
||
include ../../utils/bincompat/docker.Makefile | ||
|
||
export: clean create cleanfs | ||
mkdir rootfs | ||
docker export $(CONTAINER_NAME) | tar -x -C rootfs | ||
cp hosts rootfs/etc/hosts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Caddy 2.7 | ||
|
||
This directory contains the definition to run [Caddy](https://github.com/caddyserver/caddy) on Unikraft in binary compatibility mode. | ||
|
||
Follow the instructions in the common `../README.md` file to set up and configure the application. | ||
|
||
## Quick Run | ||
|
||
Use `kraft` to run the image: | ||
|
||
```console | ||
kraft run -M 256M -p 2015:2015 | ||
``` | ||
|
||
Once executed, it will open port `2015` and wait for connections, and can be queried. | ||
|
||
Query the service using: | ||
|
||
```console | ||
curl localhost:2015 | ||
``` | ||
|
||
This doesn't work, however, probably due to some Caddy specifics. | ||
|
||
## Scripted Run | ||
|
||
Use the scripted runs, detailed in the common `../README.md`. | ||
Once you run the the scripts, query the service: | ||
|
||
```console | ||
curl 172.44.0.2:2015 | ||
``` | ||
|
||
This will show a `Hello, World!` message, provided by the Caddy, based on the configuration on `Caddyfile`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
networking: True | ||
accel: True | ||
memory: 512 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
127.0.0.1 localhost | ||
::1 ip6-localhost ip6-loopback |