2020-05-21 16:03:21 -04:00
|
|
|
#!/usr/bin/env bash
|
2026-04-06 15:48:37 +05:30
|
|
|
# Copyright IBM Corp. 2020, 2026
|
2023-02-02 17:15:17 -08:00
|
|
|
# SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2020-05-21 16:03:21 -04:00
|
|
|
#
|
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"
|
|
|
|
|
|
|
|
|
|
# Set build tags
|
2026-10-12 09:53:13 -07:00
|
|
|
BUILD_TAGS="${BUILD_TAGS:-"threshold"}"
|
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)"
|
|
|
|
|
|
2023-03-07 16:29:34 -05:00
|
|
|
# Get the build date from the latest commit since it can be used across all
|
|
|
|
|
# builds
|
|
|
|
|
function build_date() {
|
|
|
|
|
# It's tricky to do an RFC3339 format in a cross platform way, so we hardcode UTC
|
|
|
|
|
: "${DATE_FORMAT:="%Y-%m-%dT%H:%M:%SZ"}"
|
|
|
|
|
git show --no-show-signature -s --format=%cd --date=format:"$DATE_FORMAT" HEAD
|
|
|
|
|
}
|
|
|
|
|
BUILD_DATE=$(build_date)
|
|
|
|
|
|
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
|
|
|
|
2023-03-07 16:29:34 -05:00
|
|
|
BASE_PRODUCT_VERSION=${BASE_PRODUCT_VERSION:=$(cat version/VERSION)}
|
2023-01-06 12:34:29 -05:00
|
|
|
|
2022-12-09 13:08:02 -08:00
|
|
|
# Declare binary paths!
|
2026-10-12 09:53:13 -07:00
|
|
|
BINARY_NAME="threshold${BINARY_SUFFIX}"
|
2022-12-09 13:08:02 -08:00
|
|
|
BIN_PATH=${BIN_PATH:=bin/${BINARY_NAME}}
|
|
|
|
|
BIN_PARENT_DIR="${BIN_PATH%/*}"
|
|
|
|
|
BIN_PARENT_DIR="${BIN_PARENT_DIR##*/}"
|
|
|
|
|
|
2020-05-21 16:03:21 -04:00
|
|
|
# Delete the old dir
|
2022-12-09 13:08:02 -08:00
|
|
|
echo "==> Removing old directory ${BIN_PARENT_DIR}..."
|
|
|
|
|
rm -rf ${BIN_PARENT_DIR}
|
|
|
|
|
mkdir -p ${BIN_PARENT_DIR}
|
2020-05-21 16:03:21 -04:00
|
|
|
|
|
|
|
|
# Build!
|
2022-12-09 13:08:02 -08:00
|
|
|
echo "==> Building into ${BIN_PARENT_DIR} for ${GOOS}_${GOARCH}..."
|
2022-07-28 07:57:12 -07:00
|
|
|
${GO_CMD} build \
|
|
|
|
|
-tags="${BUILD_TAGS}" \
|
2022-12-09 13:08:02 -08:00
|
|
|
-trimpath \
|
|
|
|
|
-buildvcs=false \
|
|
|
|
|
-ldflags "
|
2023-03-07 16:29:34 -05:00
|
|
|
-X 'github.com/hashicorp/boundary/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY}'
|
|
|
|
|
-X 'github.com/hashicorp/boundary/version.Version=$BASE_PRODUCT_VERSION'
|
2022-12-09 13:08:02 -08:00
|
|
|
-X 'github.com/hashicorp/boundary/version.VersionPrerelease=$PRERELEASE_PRODUCT_VERSION'
|
|
|
|
|
-X 'github.com/hashicorp/boundary/version.VersionMetadata=$METADATA_PRODUCT_VERSION'
|
2023-03-07 16:29:34 -05:00
|
|
|
-X 'github.com/hashicorp/boundary/version.BuildDate=$BUILD_DATE'
|
2022-12-09 13:08:02 -08:00
|
|
|
" \
|
|
|
|
|
-o "$BIN_PATH" \
|
2026-10-12 09:53:13 -07:00
|
|
|
./cmd/threshold
|
2020-05-21 16:03:21 -04:00
|
|
|
|
2022-03-09 16:20:44 -05:00
|
|
|
# Copy binary into gopath if desired
|
2026-10-12 09:53:13 -07:00
|
|
|
if [ "${THRESHOLD_INSTALL_BINARY:-${BOUNDARY_INSTALL_BINARY:-}}x" != "x" ]; then
|
2022-03-09 16:20:44 -05:00
|
|
|
echo "==> Moving binary into GOPATH/bin..."
|
2022-12-09 13:08:02 -08:00
|
|
|
mv -f "${BIN_PATH}" "${GOPATH}/bin/"
|
2022-03-09 16:20:44 -05:00
|
|
|
fi
|
2020-05-21 16:03:21 -04:00
|
|
|
|
2024-04-17 09:04:40 -07:00
|
|
|
cp LICENSE "${BIN_PARENT_DIR}/LICENSE.txt"
|
|
|
|
|
|
2020-05-21 16:03:21 -04:00
|
|
|
# Done!
|
2022-07-28 07:57:12 -07:00
|
|
|
echo "==> Results:"
|
2022-12-19 12:35:10 -07:00
|
|
|
ls -hl ${BIN_PARENT_DIR}
|