Skip to content

Commit

Permalink
feat(library): Add support for Caddy
Browse files Browse the repository at this point in the history
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
razvand committed Dec 20, 2023
1 parent a6b47e9 commit 4cd7fc4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/caddy/2.7/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:2015

respond "Hello, world!"
34 changes: 34 additions & 0 deletions library/caddy/2.7/Dockerfile
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
7 changes: 7 additions & 0 deletions library/caddy/2.7/Kraftfile
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"]
15 changes: 15 additions & 0 deletions library/caddy/2.7/README.md
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).

0 comments on commit 4cd7fc4

Please sign in to comment.