Add scaffolding for external host plugins and convert aws/azure over (#1581)
This commit is contained in:
1 parent
f6efde041d
commit
1c8e0ed1e1
30 files changed
+2860
-294
No files matched your search
+45
-49
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# This script builds the application from source for multiple platforms.
|
||||
# This script builds the application from source for a single platform.
|
||||
set -e
|
||||
|
||||
# Get the parent directory of where this script is.
|
||||
@@ -11,6 +11,10 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
||||
# Change into that directory
|
||||
cd "$DIR"
|
||||
|
||||
if [ "${CI_BUILD}x" != "x" ]; then
|
||||
source /home/circleci/.bashrc
|
||||
fi
|
||||
|
||||
# Set build tags
|
||||
BUILD_TAGS="${BUILD_TAGS:-"boundary"}"
|
||||
|
||||
@@ -18,20 +22,13 @@ BUILD_TAGS="${BUILD_TAGS:-"boundary"}"
|
||||
GIT_COMMIT="$(git rev-parse HEAD)"
|
||||
GIT_DIRTY="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)"
|
||||
|
||||
# If its dev mode, only build for ourself
|
||||
if [ "${BOUNDARY_DEV_BUILD}x" != "x" ] && [ "${XC_OSARCH}x" == "x" ]; then
|
||||
XC_OS=$(go env GOOS)
|
||||
XC_ARCH=$(go env GOARCH)
|
||||
XC_OSARCH=$(go env GOOS)/$(go env GOARCH)
|
||||
elif [ "${XC_OSARCH}x" != "x" ]; then
|
||||
IFS='/' read -ra SPLITXC <<< "${XC_OSARCH}"
|
||||
DEV_PLATFORM="./pkg/${SPLITXC[0]}_${SPLITXC[1]}"
|
||||
# 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
|
||||
|
||||
# Determine the arch/os combos we're building for
|
||||
XC_ARCH=${XC_ARCH:-"386 amd64"}
|
||||
XC_OS=${XC_OS:-linux darwin windows freebsd openbsd netbsd solaris}
|
||||
XC_OSARCH=${XC_OSARCH:-"linux/386 linux/amd64 linux/arm linux/arm64 darwin/386 darwin/amd64 windows/386 windows/amd64 freebsd/386 freebsd/amd64 freebsd/arm openbsd/386 openbsd/amd64 openbsd/arm netbsd/386 netbsd/amd64 solaris/amd64"}
|
||||
|
||||
GOPATH=${GOPATH:-$(go env GOPATH)}
|
||||
case $(uname) in
|
||||
@@ -40,50 +37,49 @@ case $(uname) in
|
||||
;;
|
||||
esac
|
||||
|
||||
BINARY_SUFFIX=""
|
||||
if [ "${GOOS}x" == "windowsx" ]; then
|
||||
BINARY_SUFFIX=".exe"
|
||||
fi
|
||||
|
||||
# Build needed plugins first
|
||||
ORIG_PATH=$(pwd);
|
||||
echo "==> Building Host Plugins..."
|
||||
for PLUGIN_TYPE in host; do
|
||||
rm -f $ORIG_PATH/plugins/$PLUGIN_TYPE/assets/boundary-plugin-${PLUGIN_TYPE}*
|
||||
for CURR_PLUGIN in $(ls $ORIG_PATH/plugins/$PLUGIN_TYPE/mains); do
|
||||
cd $ORIG_PATH/plugins/$PLUGIN_TYPE/mains/$CURR_PLUGIN;
|
||||
go build -v -o $ORIG_PATH/plugins/$PLUGIN_TYPE/assets/boundary-plugin-${PLUGIN_TYPE}-${CURR_PLUGIN}${BINARY_SUFFIX} .;
|
||||
cd $ORIG_PATH;
|
||||
done;
|
||||
cd $ORIG_PATH/plugins/$PLUGIN_TYPE/assets;
|
||||
for CURR_PLUGIN in $(ls); do
|
||||
gzip -f -9 $CURR_PLUGIN;
|
||||
done;
|
||||
cd $ORIG_PATH;
|
||||
done;
|
||||
|
||||
if [ "${CI_BUILD}x" != "x" ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
# Delete the old dir
|
||||
echo "==> Removing old directory..."
|
||||
rm -f bin/*
|
||||
rm -rf pkg/*
|
||||
mkdir -p bin/
|
||||
|
||||
# Build!
|
||||
# If GOX_PARALLEL_BUILDS is set, it will be used to add a "-parallel=${GOX_PARALLEL_BUILDS}" gox parameter
|
||||
echo "==> Building..."
|
||||
gox \
|
||||
-osarch="${XC_OSARCH}" \
|
||||
-gcflags "${GCFLAGS}" \
|
||||
-ldflags "${LD_FLAGS}-X github.com/hashicorp/boundary/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" \
|
||||
-output "pkg/{{.OS}}_{{.Arch}}/boundary" \
|
||||
${GOX_PARALLEL_BUILDS+-parallel="${GOX_PARALLEL_BUILDS}"} \
|
||||
-tags="${BUILD_TAGS}" \
|
||||
BINARY_NAME="boundary${BINARY_SUFFIX}"
|
||||
go build -tags="${BUILD_TAGS}" \
|
||||
-ldflags "-X github.com/hashicorp/boundary/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY}" \
|
||||
-o "bin/${BINARY_NAME}" \
|
||||
./cmd/boundary
|
||||
|
||||
# Move all the compiled things to the $GOPATH/bin
|
||||
OLDIFS=$IFS
|
||||
IFS=: MAIN_GOPATH=($GOPATH)
|
||||
IFS=$OLDIFS
|
||||
|
||||
# Copy our OS/Arch to the bin/ directory
|
||||
DEV_PLATFORM=${DEV_PLATFORM:-"./pkg/$(go env GOOS)_$(go env GOARCH)"}
|
||||
for F in $(find ${DEV_PLATFORM} -mindepth 1 -maxdepth 1 -type f); do
|
||||
cp -f ${F} bin/
|
||||
cp -f ${F} ${MAIN_GOPATH}/bin/
|
||||
done
|
||||
|
||||
if [ "${BOUNDARY_DEV_BUILD}x" = "x" ]; then
|
||||
# Zip and copy to the dist dir
|
||||
echo "==> Packaging..."
|
||||
for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do
|
||||
OSARCH=$(basename ${PLATFORM})
|
||||
echo "--> ${OSARCH}"
|
||||
|
||||
pushd $PLATFORM >/dev/null 2>&1
|
||||
zip ../${OSARCH}.zip ./*
|
||||
popd >/dev/null 2>&1
|
||||
done
|
||||
fi
|
||||
# Copy binary into gopath
|
||||
echo "==> Copying binary into GOPATH"
|
||||
cp -f "bin/${BINARY_NAME}" "${GOPATH}/bin/"
|
||||
|
||||
# Done!
|
||||
echo
|
||||
echo "==> Results:"
|
||||
ls -hl bin/
|
||||
echo "==> Done!"
|
||||
Reference in new issue
Block a user