Skip to content

Commit

Permalink
Create caddy server PIE build
Browse files Browse the repository at this point in the history
  • Loading branch information
bttger committed Oct 23, 2022
1 parent 5974451 commit 5b63195
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions caddy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/caddy-*
/v2.*.tar.gz
32 changes: 32 additions & 0 deletions caddy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Build caddy server as static PIE

Build the [caddy server](https://caddyserver.com/) web server as a static PIE ELF running on Linux.

## Requirements

Make sure the following packages are installed:
* go >= 1.17
* git

## Build

The `caddy` static PIE ELF is located in the current folder.
If you want to rebuild it, run:

```
$ ./build.sh
```

## Run

You can run the executable natively on Linux:

```
$ ./caddy-2.6.2/cmd/caddy/caddy respond --debug --access-log --listen :8089 "Hello world\!"
```

Or with [run-elfloader](https://github.com/unikraft/run-app-elfloader) on Unikraft:
```
$ ./run_elfloader ../static-pie-apps/caddy/caddy-2.6.2/cmd/caddy/caddy [args]
```

16 changes: 16 additions & 0 deletions caddy/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

# Clean up
rm -rf caddy-*
rm -f v2.*

echo "Downloading caddy source code... "
wget -q https://github.com/caddyserver/caddy/archive/refs/tags/v2.6.2.tar.gz

echo "Unpacking caddy source code..."
tar xzf v2.6.2.tar.gz

echo "Building caddy... "
cd caddy-2.6.2/cmd/caddy
CGO_ENABLED=1 go build -buildmode=pie -ldflags "-linkmode external -extldflags "-static-pie""
echo ""
5 changes: 5 additions & 0 deletions caddy/rootfs/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:80

route {
teapot
}

0 comments on commit 5b63195

Please sign in to comment.