From 4cd7fc4c833146910cd7f949cbef7aa96238b6bf Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Wed, 15 Nov 2023 00:17:22 +0200 Subject: [PATCH] feat(library): Add support for Caddy Introduce Caddy bincompat run. Build Caddy as static PIE using a Dockerfile, inspired by Caddy's own Docker setup. Use `xcaddy` to build. The build uses binary compatibility mode (i.e. the `base` image). Add: * `Kraftfile`: build / run rules, including pulling the `base` image * `Dockerfile`: base filesystem, with binary and libraries * `README.md`: document how to use * `Caddyfile`: Caddy configuration file Signed-off-by: Razvan Deaconescu --- library/caddy/2.7/Caddyfile | 3 +++ library/caddy/2.7/Dockerfile | 34 ++++++++++++++++++++++++++++++++++ library/caddy/2.7/Kraftfile | 7 +++++++ library/caddy/2.7/README.md | 15 +++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 library/caddy/2.7/Caddyfile create mode 100644 library/caddy/2.7/Dockerfile create mode 100644 library/caddy/2.7/Kraftfile create mode 100644 library/caddy/2.7/README.md diff --git a/library/caddy/2.7/Caddyfile b/library/caddy/2.7/Caddyfile new file mode 100644 index 00000000..44b4ae8a --- /dev/null +++ b/library/caddy/2.7/Caddyfile @@ -0,0 +1,3 @@ +:2015 + +respond "Hello, world!" diff --git a/library/caddy/2.7/Dockerfile b/library/caddy/2.7/Dockerfile new file mode 100644 index 00000000..dcab420f --- /dev/null +++ b/library/caddy/2.7/Dockerfile @@ -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 /caddy +COPY Caddyfile /Caddyfile diff --git a/library/caddy/2.7/Kraftfile b/library/caddy/2.7/Kraftfile new file mode 100644 index 00000000..1a505fe0 --- /dev/null +++ b/library/caddy/2.7/Kraftfile @@ -0,0 +1,7 @@ +spec: v0.6 + +runtime: unikraft.org/base:latest + +rootfs: ./Dockerfile + +cmd: ["/caddy", "run"] diff --git a/library/caddy/2.7/README.md b/library/caddy/2.7/README.md new file mode 100644 index 00000000..94bc499c --- /dev/null +++ b/library/caddy/2.7/README.md @@ -0,0 +1,15 @@ +# Caddy 2.7 + +This directory contains the definition for the `unikraft.org/caddy:2.7` image. + +To run this image, [install Unikraft's companion command-line toolchain `kraft`](https://unikraft.org/docs/cli) and then you can run: + +``` +kraft run unikraft.org/caddy:2.7 -p 2015:2015 +``` + +Once executed, it will open port `2015` and wait for connections, and can be queried. + +## See also + +- [How to run unikernels locally in Unikraft's Documentation](https://unikraft.org/docs/cli/running).