Files
threshold/scripts/build.sh
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
2.4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
2023-02-02 17:15:17 -08:00
# SPDX-License-Identifier: MPL-2.0
#
# This script builds the application from source for a single platform.
set -e
2022-07-28 07:57:12 -07:00
GO_CMD=${GO_CMD:-go}
# 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"
if [ "${CI_BUILD}x" != "x" ]; then
2023-02-23 14:58:40 -05:00
[[ -f /home/circleci/.bashrc ]] && source /home/circleci/.bashrc
fi
# 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}"
# Get the git commit
GIT_COMMIT="$(git rev-parse HEAD)"
GIT_DIRTY="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)"
# 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)
fi
GOPATH=${GOPATH:-$(go env GOPATH)}
case $(uname) in
CYGWIN*)
GOPATH="$(cygpath $GOPATH)"
;;
esac
BINARY_SUFFIX=""
2022-04-15 09:17:43 -04:00
if [ "${GOOS}x" = "windowsx" ]; then
BINARY_SUFFIX=".exe"
fi
# Build needed plugins first
if [ "${SKIP_PLUGIN_BUILD}x" == "x" ]; then
2022-04-15 09:17:43 -04:00
$DIR/scripts/plugins.sh
fi
if [ "${CI_BUILD}x" != "x" ]; then
exit
fi
PRODUCT_VERSION=${PRODUCT_VERSION:=$(cat version/VERSION)}
# Declare binary paths!
BINARY_NAME="boundary${BINARY_SUFFIX}"
BIN_PATH=${BIN_PATH:=bin/${BINARY_NAME}}
BIN_PARENT_DIR="${BIN_PATH%/*}"
BIN_PARENT_DIR="${BIN_PARENT_DIR##*/}"
# Delete the old dir
echo "==> Removing old directory ${BIN_PARENT_DIR}..."
rm -rf ${BIN_PARENT_DIR}
mkdir -p ${BIN_PARENT_DIR}
# Build!
echo "==> Building into ${BIN_PARENT_DIR} for ${GOOS}_${GOARCH}..."
2022-07-28 07:57:12 -07:00
${GO_CMD} build \
-tags="${BUILD_TAGS}" \
-trimpath \
-buildvcs=false \
-ldflags "
-X github.com/hashicorp/boundary/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY}
-X 'github.com/hashicorp/boundary/version.Version=$PRODUCT_VERSION'
-X 'github.com/hashicorp/boundary/version.VersionPrerelease=$PRERELEASE_PRODUCT_VERSION'
-X 'github.com/hashicorp/boundary/version.VersionMetadata=$METADATA_PRODUCT_VERSION'
" \
-o "$BIN_PATH" \
2020-08-10 17:15:02 -04:00
./cmd/boundary
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_PATH}" "${GOPATH}/bin/"
2022-03-09 16:20:44 -05:00
fi
# Done!
2022-07-28 07:57:12 -07:00
echo "==> Results:"
ls -hl ${BIN_PARENT_DIR}