envoy: add full version (#2287)

* envoy: add full version

* remove unused import

* get envoy for lint
This commit is contained in:
Caleb Doxsey 2021-06-14 13:58:12 -06:00 committed by GitHub
parent 5dd68f5ff0
commit 31fa214983
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 103 additions and 48 deletions

View file

@ -4,8 +4,9 @@ set -euo pipefail
PATH="$PATH:$(go env GOPATH)/bin"
export PATH
_project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/.."
_envoy_version=1.17.3
_dir="${DIR:-"$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/../bin"}"
_dir="${DIR:-"$_project_root/bin"}"
_target="${TARGET:-"$(go env GOOS)-$(go env GOARCH)"}"
# until m1 macs are supported, fallback to x86 and use rosetta
@ -13,35 +14,33 @@ if [ "$_target" == "darwin-arm64" ]; then
_target="darwin-amd64"
fi
is_command() {
command -v "$1" >/dev/null
}
_url="https://github.com/pomerium/envoy-binaries/releases/download/v${_envoy_version}/envoy-${_target}"
hash_sha256() {
TARGET=${1:-/dev/stdin}
if is_command gsha256sum; then
hash=$(gsha256sum "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command sha256sum; then
hash=$(sha256sum "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command shasum; then
hash=$(shasum -a 256 "$TARGET" 2>/dev/null) || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command openssl; then
hash=$(openssl -dst openssl dgst -sha256 "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f a
else
echo "hash_sha256 unable to find command to compute sha-256 hash"
return 1
fi
}
# create the directory if it doesn't exist
mkdir -p "$_dir"
if [ -f "$_dir/envoy" ]; then
exit 0
# download the shasum of the binary
curl \
--compressed \
--silent \
--location \
--output "$_dir/envoy-$_target.sha256" \
"$_url.sha256"
# if the shasum doesn't match (or the binary doesn't exist), re-download
if ! (cd "$_dir" && shasum -c "envoy-$_target.sha256" >/dev/null 2>&1) ; then
curl \
--compressed \
--silent \
--location \
--output "$_dir/envoy-$_target" \
"$_url"
fi
mkdir -p "$_dir"
curl -L --compressed -o "$_dir/envoy" "https://github.com/pomerium/envoy-binaries/releases/download/v${_envoy_version}/envoy-${_target}"
# save the bare name
cp -f "$_dir/envoy-$_target" "$_dir/envoy"
cp -f "$_dir/envoy-$_target.sha256" "$_dir/envoy.sha256"
hash_sha256 "$_dir/envoy" >"$_dir/envoy.sha256"
# save to the embedded files in the envoy package
cp -f "$_dir/envoy-$_target.sha256" "$_project_root/internal/envoy/files/envoy.sha256"
echo "$_envoy_version" > "$_project_root/internal/envoy/files/envoy.version"