From da9d8e7a8faa69825e47ee9b54297816f0b6b6c8 Mon Sep 17 00:00:00 2001 From: Tom Boettger Date: Mon, 24 Oct 2022 00:15:38 +0200 Subject: [PATCH] Add caddy server static PIE build --- consul/.gitignore | 2 ++ consul/GNUmakefile.patch | 5 +++++ consul/README.md | 32 ++++++++++++++++++++++++++++++++ consul/build.sh | 17 +++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 consul/.gitignore create mode 100644 consul/GNUmakefile.patch create mode 100644 consul/README.md create mode 100755 consul/build.sh diff --git a/consul/.gitignore b/consul/.gitignore new file mode 100644 index 0000000..ec49586 --- /dev/null +++ b/consul/.gitignore @@ -0,0 +1,2 @@ +/consul-* +/v1.*.zip diff --git a/consul/GNUmakefile.patch b/consul/GNUmakefile.patch new file mode 100644 index 0000000..ed3d1c3 --- /dev/null +++ b/consul/GNUmakefile.patch @@ -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)" diff --git a/consul/README.md b/consul/README.md new file mode 100644 index 0000000..624f51c --- /dev/null +++ b/consul/README.md @@ -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] +``` diff --git a/consul/build.sh b/consul/build.sh new file mode 100755 index 0000000..9a4764b --- /dev/null +++ b/consul/build.sh @@ -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 ""