Skip to content

Commit

Permalink
Add caddy server static PIE build
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Boettger <[email protected]>
  • Loading branch information
bttger committed Oct 23, 2022
1 parent 5974451 commit 6dd6dde
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions consul/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/consul-*
/v1.*.zip
5 changes: 5 additions & 0 deletions consul/GNUmakefile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
202c202,203
< CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) go build -o ./pkg/bin/linux_$(GOARCH) -ldflags "$(GOLDFLAGS)" -tags "$(GOTAGS)"
---
> GOLDFLAGS="$(GOLDFLAGS) -linkmode external -extldflags '-static-pie'"
> CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) go build -o ./pkg/bin -buildmode=pie -ldflags "$(GOLDFLAGS)" -tags "$(GOTAGS)"
32 changes: 32 additions & 0 deletions consul/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Build consul server as static PIE

Build the consul server as a static PIE ELF running on Linux.

## Requirements

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

## Build

The `consul` 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:

```
$ ./consul-1.13.3/pkg/bin/consul version
```

Or with [run-elfloader](https://github.com/unikraft/run-app-elfloader) on Unikraft:
```
$ ./run_elfloader ../static-pie-apps/consul/consul-1.13.3/pkg/bin/consul [args]
```
17 changes: 17 additions & 0 deletions consul/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

# Clean up
rm -rf consul-*
rm -f v1.*

echo "Downloading consul source code... "
wget -q https://github.com/hashicorp/consul/archive/refs/tags/v1.13.3.zip

echo "Unpacking consul source code..."
unzip v1.13.3.zip

echo "Building consul... "
cd consul-1.13.3 || exit
patch GNUmakefile ../GNUmakefile.patch
make linux
echo ""

0 comments on commit 6dd6dde

Please sign in to comment.