forked from unikraft/catalog
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Showing
4 changed files
with
59 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,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 /caddy | ||
COPY Caddyfile /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,7 @@ | ||
spec: v0.6 | ||
|
||
runtime: unikraft.org/base:latest | ||
|
||
rootfs: ./Dockerfile | ||
|
||
cmd: ["/caddy", "run"] |
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,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). |