Update build and release process for envoy embedding (#699)

This commit is contained in:
Travis Groth 2020-05-14 10:03:39 -04:00
parent dccec1e646
commit d58f68ab15
7 changed files with 50 additions and 150 deletions

View file

@ -1,28 +1,12 @@
#!/bin/bash
set -euxo pipefail
_script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
_dir=/tmp/pomerium-dev-docker
mkdir -p "$_dir"
# build linux binary
env GOOS=linux \
GOARCH=amd64 \
CGO_ENABLED=0 \
GO111MODULE=on \
go build \
-ldflags "-s -w" \
-o "$_dir/pomerium" \
./cmd/pomerium
# embed envoy
(
cd "$_script_dir"
env GOOS=linux \
GOARCH=amd64 \
./embed-envoy.bash \
"$_dir/pomerium"
)
env GOOS=linux make build-deps build
cp bin/pomerium $_dir/
# build docker image
(

View file

@ -1,50 +1,37 @@
#!/bin/bash
set -euo pipefail
_pomerium_binary_path="${1?"pomerium binary path is required"}"
_go_os="$(go env GOOS)"
_go_arch="$(go env GOARCH)"
BINARY=$1
is_musl() {
ldd /bin/ls | grep musl >/dev/null 2>&1
}
ENVOY_VERSION=1.14.1
DIR=$(dirname "${BINARY}")
GOOS=$(go env GOOS)
# URLs from: https://tetrate.bintray.com/getenvoy/manifest.json
_envoy_version="1.14.1"
_envoy_build=""
if [ "$_go_os" == linux ] && ! is_musl && [ "$_go_arch" == "amd64" ]; then
_envoy_build="LINUX_GLIBC"
elif [ "$_go_os" == darwin ] && [ "$_go_arch" == "amd64" ]; then
_envoy_build="DARWIN"
fi
if [ -z "$_envoy_build" ]; then
echo "this platform is not supported for embedded envoy"
if [ "${GOOS}" == "darwin" ]; then
ENVOY_PLATFORM="darwin"
elif [ "${GOOS}" == "linux" ]; then
ENVOY_PLATFORM="linux_glibc"
else
echo "unsupported"
exit 1
fi
_envoy_url="$(
curl --silent "https://tetrate.bintray.com/getenvoy/manifest.json" |
jq -r '.flavors.standard.versions["'"$_envoy_version"'"].builds["'"$_envoy_build"'"].downloadLocationUrl'
)"
_abs_pomerium_binary_path="$(realpath "$_pomerium_binary_path")"
## TODO we should be able to replace this with a utility that consumes
## https://godoc.org/github.com/tetratelabs/getenvoy/pkg/binary/envoy
## https://golang.org/pkg/archive/zip/#Writer.SetOffset
export PATH=$PATH:$(go env GOPATH)/bin
HOME=${DIR} getenvoy fetch standard:${ENVOY_VERSION}/${ENVOY_PLATFORM}
ENVOY_PATH=${DIR}/.getenvoy/builds/standard/${ENVOY_VERSION}/${ENVOY_PLATFORM}/bin
ARCHIVE=${ENVOY_PATH}/envoy.zip
_wd="/tmp/pomerium-embedded-files"
mkdir -p "$_wd"
(
cd "$_wd"
if [ ! -f "envoy-$_envoy_version.tar.xz" ]; then
echo "downloading $_envoy_url"
curl --silent --location --output "envoy-$_envoy_version.tar.xz" "$_envoy_url"
fi
echo "extracting"
tar --extract --xz --strip-components=3 --file "envoy-$_envoy_version.tar.xz"
echo "appending to $_abs_pomerium_binary_path"
# if this binary already has a zip file appended to it
if [ -z "$(unzip -z -qq "$_abs_pomerium_binary_path" 2>&1)" ]; then
zip -A "$_abs_pomerium_binary_path" envoy
else
zip envoy.zip envoy
cat envoy.zip >>"$_abs_pomerium_binary_path"
fi
zip -A "$_abs_pomerium_binary_path"
cd "${ENVOY_PATH}"
zip envoy.zip envoy
)
echo "appending ${ARCHIVE} to ${BINARY}"
if [ "$(unzip -z -qq "$BINARY" 2>&1)" != "" ]; then
cat "${ARCHIVE}" >>"${BINARY}"
fi
zip -A "${BINARY}"