sourcegraph/dev/caddy.sh
dyma solovei 5b40640349
fix(sg): start Caddy admin server before caddy trust (#58928)
fix(sg): start Caddy admin before `caddy trust`

From docs:
This command will attempt to connect to Caddy's admin API to fetch the root certificate,
using the GET /pki/ca/<id>/certificates endpoint.

If the admin server is not running at the moment, the GET request
will not succeed, and the certificate won't be installed correctly.
2023-12-20 10:03:45 +02:00

35 lines
668 B
Bash
Executable File

#!/usr/bin/env bash
set -euf -o pipefail
pushd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null
mkdir -p .bin
version="2.7.3"
case "$(go env GOOS)" in
linux)
os="linux"
;;
darwin)
os="mac"
;;
esac
name="caddy_${version}_${os}_$(go env GOARCH)"
target="$PWD/.bin/${name}"
url="https://github.com/caddyserver/caddy/releases/download/v${version}/${name}.tar.gz"
if [ ! -f "${target}" ]; then
echo "downloading ${url}" 1>&2
curl -sS -L -f "${url}" | tar -xz --to-stdout "caddy" >"${target}.tmp"
mv "${target}.tmp" "${target}"
fi
chmod +x "${target}"
popd >/dev/null
trap '${target} stop' EXIT SIGINT
eval "${target} start"
"${target}" "$@"