2020-05-21 16:03:21 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
#
|
2021-10-14 11:56:08 -04:00
|
|
|
# This script builds the application from source for a single platform.
|
2020-05-21 16:03:21 -04:00
|
|
|
set -e
|
|
|
|
|
|
2022-07-28 07:57:12 -07:00
|
|
|
GO_CMD=${GO_CMD:-go}
|
|
|
|
|
|
2020-05-21 16:03:21 -04:00
|
|
|
# Get the parent directory of where this script is.
|
|
|
|
|
SOURCE="${BASH_SOURCE[0]}"
|
|
|
|
|
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
|
|
|
|
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
|
|
|
|
|
|
|
|
|
# Change into that directory
|
|
|
|
|
cd "$DIR"
|
|
|
|
|
|
2021-10-14 11:56:08 -04:00
|
|
|
if [ "${CI_BUILD}x" != "x" ]; then
|
|
|
|
|
source /home/circleci/.bashrc
|
|
|
|
|
fi
|
|
|
|
|
|
2020-05-21 16:03:21 -04:00
|
|
|
# Set build tags
|
2020-08-10 17:15:02 -04:00
|
|
|
BUILD_TAGS="${BUILD_TAGS:-"boundary"}"
|
2022-07-28 07:57:12 -07:00
|
|
|
echo "==> Build tags: ${BUILD_TAGS}"
|
2020-05-21 16:03:21 -04:00
|
|
|
|
|
|
|
|
# Get the git commit
|
|
|
|
|
GIT_COMMIT="$(git rev-parse HEAD)"
|
|
|
|
|
GIT_DIRTY="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)"
|
|
|
|
|
|
2021-10-14 11:56:08 -04:00
|
|
|
# If not explicitly cross-compiling, build for the current platform
|
|
|
|
|
if [ "${GOOS}x" == "x" ]; then
|
|
|
|
|
GOOS=$(go env GOOS)
|
|
|
|
|
fi
|
|
|
|
|
if [ "${GOARCH}x" == "x" ]; then
|
|
|
|
|
GOARCH=$(go env GOARCH)
|
2020-05-21 16:03:21 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
GOPATH=${GOPATH:-$(go env GOPATH)}
|
|
|
|
|
case $(uname) in
|
|
|
|
|
CYGWIN*)
|
|
|
|
|
GOPATH="$(cygpath $GOPATH)"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
2021-10-14 11:56:08 -04:00
|
|
|
BINARY_SUFFIX=""
|
2022-04-15 09:17:43 -04:00
|
|
|
if [ "${GOOS}x" = "windowsx" ]; then
|
2021-10-14 11:56:08 -04:00
|
|
|
BINARY_SUFFIX=".exe"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Build needed plugins first
|
2022-03-16 17:04:07 -04:00
|
|
|
if [ "${SKIP_PLUGIN_BUILD}x" == "x" ]; then
|
2022-04-15 09:17:43 -04:00
|
|
|
$DIR/scripts/plugins.sh
|
2022-03-16 17:04:07 -04:00
|
|
|
fi
|
2021-10-14 11:56:08 -04:00
|
|
|
|
|
|
|
|
if [ "${CI_BUILD}x" != "x" ]; then
|
|
|
|
|
exit
|
|
|
|
|
fi
|
|
|
|
|
|
2020-05-21 16:03:21 -04:00
|
|
|
# Delete the old dir
|
|
|
|
|
echo "==> Removing old directory..."
|
|
|
|
|
rm -f bin/*
|
|
|
|
|
mkdir -p bin/
|
|
|
|
|
|
|
|
|
|
# Build!
|
2022-07-28 07:57:12 -07:00
|
|
|
echo "==> Building into bin/ for ${GOOS}_${GOARCH}..."
|
2021-10-14 11:56:08 -04:00
|
|
|
BINARY_NAME="boundary${BINARY_SUFFIX}"
|
2022-07-28 07:57:12 -07:00
|
|
|
${GO_CMD} build \
|
|
|
|
|
-tags="${BUILD_TAGS}" \
|
2021-10-14 11:56:08 -04:00
|
|
|
-ldflags "-X github.com/hashicorp/boundary/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" \
|
|
|
|
|
-o "bin/${BINARY_NAME}" \
|
2020-08-10 17:15:02 -04:00
|
|
|
./cmd/boundary
|
2020-05-21 16:03:21 -04:00
|
|
|
|
2022-03-09 16:20:44 -05:00
|
|
|
# Copy binary into gopath if desired
|
|
|
|
|
if [ "${BOUNDARY_INSTALL_BINARY}x" != "x" ]; then
|
|
|
|
|
echo "==> Moving binary into GOPATH/bin..."
|
|
|
|
|
mv -f "bin/${BINARY_NAME}" "${GOPATH}/bin/"
|
|
|
|
|
fi
|
2020-05-21 16:03:21 -04:00
|
|
|
|
|
|
|
|
# Done!
|
2022-07-28 07:57:12 -07:00
|
|
|
echo "==> Results:"
|
2022-08-24 09:05:25 -04:00
|
|
|
ls -hl bin/
|