Skip to content

Commit fc9155c

Browse files
authored
feat(examples): Introduce caddy 2.10 to library and examples (#237)
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io>
2 parents 4d7c511 + 04635c4 commit fc9155c

File tree

18 files changed

+495
-0
lines changed

18 files changed

+495
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: library/caddy:2.10
2+
3+
on:
4+
repository_dispatch:
5+
types: [core_merge, elfloader_merge, libelf_merge, lwip_merge]
6+
7+
workflow_dispatch:
8+
9+
schedule:
10+
- cron: '0 0 * * *'
11+
12+
push:
13+
branches: [main]
14+
paths:
15+
- 'library/caddy/2.10/**'
16+
- '.github/workflows/library-caddy2.10.yaml'
17+
- '!library/caddy/2.10/README.md'
18+
19+
pull_request:
20+
types: [opened, synchronize, reopened]
21+
branches: [main]
22+
paths:
23+
- 'library/caddy/2.10/**'
24+
- '.github/workflows/library-caddy2.10.yaml'
25+
- '!library/caddy/2.10/README.md'
26+
27+
# Automatically cancel in-progress actions on the same branch
28+
concurrency:
29+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
30+
cancel-in-progress: true
31+
32+
jobs:
33+
build:
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
include:
38+
- plat: qemu
39+
arch: x86_64
40+
- plat: fc
41+
arch: x86_64
42+
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- name: Build caddy2.10
49+
uses: unikraft/kraftkit@staging
50+
with:
51+
loglevel: debug
52+
workdir: library/caddy/2.10
53+
runtimedir: /github/workspace/.kraftkit
54+
plat: ${{ matrix.plat }}
55+
arch: ${{ matrix.arch }}
56+
push: false
57+
output: oci://index.unikraft.io/unikraft.org/caddy:2.10
58+
59+
- name: Archive OCI digests
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: oci-digests-${{ matrix.arch }}-${{ matrix.plat }}
63+
path: ${{ github.workspace }}/.kraftkit/oci/digests
64+
if-no-files-found: error
65+
66+
push:
67+
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }}
68+
needs: [ build ]
69+
runs-on: ubuntu-latest
70+
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Login to OCI registry
75+
uses: docker/login-action@v3
76+
with:
77+
registry: index.unikraft.io
78+
username: ${{ secrets.REG_USERNAME }}
79+
password: ${{ secrets.REG_TOKEN }}
80+
81+
- name: Retrieve, merge and push OCI digests
82+
uses: ./.github/actions/merge-oci-digests
83+
with:
84+
name: index.unikraft.io/unikraft.org/caddy:2.10
85+
push: true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.unikraft/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.unikraft/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM golang:1.25.3-trixie AS build
2+
3+
ARG CADDY_VERSION=2.10.2
4+
5+
WORKDIR /caddy
6+
7+
RUN --mount=type=cache,target=/root/go/pkg/mod \
8+
--mount=type=cache,target=/root/.cache/go-build \
9+
set -xe; \
10+
apt-get update; \
11+
apt-get install -y --no-install-recommends \
12+
git \
13+
ca-certificates; \
14+
git clone --depth=1 --branch v${CADDY_VERSION} https://github.com/caddyserver/caddy.git /caddy; \
15+
go build -v \
16+
-buildmode=pie \
17+
-ldflags "-linkmode external -extldflags -static-pie" \
18+
-tags netgo \
19+
-o /caddy/caddy cmd/caddy/main.go;
20+
21+
RUN echo "127.0.0.1 localhost" > /tmp/hosts
22+
23+
FROM scratch
24+
25+
COPY --from=build /caddy/caddy /usr/bin/caddy
26+
COPY --from=build /tmp/hosts /etc/hosts
27+
COPY ./rootfs /
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spec: v0.6
2+
3+
name: caddy2.10-go1.25-base
4+
5+
runtime: base:latest
6+
7+
rootfs: ./Dockerfile
8+
9+
cmd: ["/usr/bin/caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Caddy
2+
3+
This directory contains a [`Caddy`](https://caddyserver.com/) web server running on Unikraft.
4+
5+
## Set Up
6+
7+
To run this example, [install Unikraft's companion command-line toolchain `kraft`](https://unikraft.org/docs/cli), clone this repository and `cd` into this directory.
8+
9+
## Run and Use
10+
11+
Use `kraft` to run the image and start a Unikraft instance:
12+
13+
```bash
14+
kraft run --rm -p 2015:2015 --plat qemu --arch x86_64 -M 512M .
15+
```
16+
17+
If the `--plat` argument is left out, it defaults to `qemu`.
18+
If the `--arch` argument is left out, it defaults to your system's CPU architecture.
19+
20+
Once executed, it will open port `2015` and wait for connections.
21+
To test it, you can use `curl`:
22+
23+
```bash
24+
curl localhost:2015
25+
```
26+
27+
You should see a "Bye, World!" message.
28+
29+
## Inspect and Close
30+
31+
To list information about the Unikraft instance, use:
32+
33+
```bash
34+
kraft ps
35+
```
36+
37+
```text
38+
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
39+
vigilant_michael oci://unikraft.org/caddy:2.10 /usr/bin/caddy run --config /etc/caddy/Caddyfile 6 seconds ago running 244M 0.0.0.0:2015->2015/tcp qemu/x86_64
40+
```
41+
42+
The instance name is `vigilant_michael`.
43+
To close the Unikraft instance, close the `kraft` process (e.g., via `Ctrl+c`) or run:
44+
45+
```bash
46+
kraft rm vigilant_michael
47+
```
48+
49+
Note that depending on how you modify this example your instance **may** need more memory to run.
50+
To do so, use the `kraft run`'s `-M` flag, for example:
51+
52+
```bash
53+
kraft run --rm -p 2015:2015 --plat qemu --arch x86_64 -M 1G .
54+
```
55+
56+
## `kraft` and `sudo`
57+
58+
Mixing invocations of `kraft` and `sudo` can lead to unexpected behavior.
59+
Read more about how to start `kraft` without `sudo` at [https://unikraft.org/sudoless](https://unikraft.org/sudoless).
60+
61+
## Learn More
62+
63+
- [How to run unikernels locally](https://unikraft.org/docs/cli/running)
64+
- [Building `Dockerfile` Images with `BuildKit`](https://unikraft.org/guides/building-dockerfile-images-with-buildkit)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
:2015
2+
3+
root * /var/www
4+
5+
encode gzip
6+
7+
templates
8+
9+
file_server
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bye, World!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.unikraft/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.unikraft/

0 commit comments

Comments
 (0)