-
-
Save skoslitz/6e36e42b7bcc95d222c7c68cd82ba5ba to your computer and use it in GitHub Desktop.
Build Caddy w/ plugins from sources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Big respect to @mholt6 for making Caddy. | |
# | |
#/ Usage: | |
#/ build_caddy.sh [-h] | |
#/ | |
#/ It builds Caddy with plugins defined in `plugins` file. | |
#/ | |
#/ Cross compilation: | |
#/ $ env OS=darwin ./build_caddy.sh | |
#/ $ env OS=linux ARCH=amd64 ./build_caddy.sh | |
#/ $ env OS=linux ARCH=arm ARM=7 ./build_caddy.sh | |
#/ | |
#/ Environment variables: | |
#/ UPDATE=1 - check source repos for updaes | |
set -eo pipefail | |
if [[ "$1" == "--help" || "$1" == '-h' ]]; then | |
grep ^#/ "$0" | cut -c4- | |
exit | |
fi | |
function error { | |
echo >&2 "ERROR: ${1:-unknown error occured}" | |
exit 1 | |
} | |
function reset_git { | |
pushd "${1}" | |
git reset --hard || true | |
popd | |
} | |
for cmd in go sed; do | |
command -v "${cmd}" 2>/dev/null || error "I require '${cmd}', but it's not installed" | |
done | |
HERE="$(pwd)" | |
UPDATE="${UPDATE:-}" | |
OS="${OS:-}" | |
ARCH="${ARCH:-}" | |
ARM="${ARM:-}" | |
GOPATH="${GOPATH:-$HOME/go}" | |
FILE_PLUGINS_LIST="${HERE}/plugins" | |
DIR_CADDY_SOURCE="${GOPATH}/src/github.com/mholt/caddy" | |
DIR_CADDY_BUILDS="${GOPATH}/src/github.com/caddyserver/builds" | |
mkdir -p "${GOPATH}/src" | |
[ ! -d "${DIR_CADDY_SOURCE}" ] || reset_git "${DIR_CADDY_SOURCE}" | |
[ ! -d "${DIR_CADDY_BUILDS}" ] || reset_git "${DIR_CADDY_BUILDS}" | |
go get -d -v ${UPDATE:+-u} github.com/mholt/caddy | |
go get -d -v ${UPDATE:+-u} github.com/caddyserver/builds | |
PLUGINS= | |
while read plugin; do | |
go get -d -v ${UPDATE:+-u} "${plugin}" | |
PLUGINS="${PLUGINS}$(basename "${plugin}") " | |
done < "${FILE_PLUGINS_LIST}" | |
# patch caddy | |
pushd "${DIR_CADDY_SOURCE}" | |
echo | |
echo "Shall I build Caddy?" | |
echo " - version : $(git describe --exact-match HEAD) ($(git rev-parse --short HEAD))" | |
echo " - plugins : ${PLUGINS:--}" | |
echo " - GOOS=${OS:-}" | |
echo " - GOARCH=${ARCH:-}" | |
echo " - GOARM=${ARM:-}" | |
echo | |
echo "Press ENTER to patch or 'Ctrl+c' to abort ..." | |
read | |
# --- add plugins | |
while read plugin; do | |
sed -i "/other plugins get plugged in/a \\\t_ \"${plugin}\"" caddy/caddymain/run.go | |
done < "${FILE_PLUGINS_LIST}" | |
# --- remove sponsor header | |
sed -i -e '/sponsors/d' caddyhttp/httpserver/server.go | |
# --- add verbosity | |
sed -i '/args :=/a \\targs = append(args, "-v")' caddy/build.go | |
git diff | |
echo | |
echo "Press ENTER to build or 'Ctrl+c' to abort ..." | |
read | |
popd | |
# patch build flags | |
pushd "${DIR_CADDY_BUILDS}" | |
sed -i -e '/var ldflags/c\ldflags := []string{"-w"}' compilation.go | |
sed -i -e '/diff-index/c\return "", nil' compilation.go | |
popd | |
# execute build itself | |
pushd "${DIR_CADDY_SOURCE}/caddy" | |
go run build.go ${OS:+-goos=${OS}} ${ARCH:+-goarch=${ARCH}} ${ARM:+-goarm=${ARM}} | |
mv -f caddy "${HERE}" | |
popd | |
echo "DONE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github.com/abiosoft/caddy-git | |
github.com/epicagency/caddy-expires |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment