WIP: Update gobuild.sh to pass version flags via -ldflags
@@ -18,16 +18,27 @@ export TOPWD="$(pwd)"
export BUILDDIR="$(mktemp -d)"
export GOPATH="${TOPWD}/ecs-init/Godeps/_workspace:${BUILDDIR}"
export SRCPATH="${BUILDDIR}/src/github.com/aws/amazon-ecs-init"
+
+version=$(cat "${TOPWD}/ecs-init/VERSION")
+git_hash=$(git rev-parse --short HEAD)
+git_dirty=false
+
+if [[ "$(git status --porcelain)" != "" ]]; then
+ git_dirty=true
+fi
+
+VERSIONFLAGS="-X version.Version=${version} -X version.GitDirty=${git_dirty} -X version.GitShortHash=${git_hash}"
+
mkdir -p "${SRCPATH}"
ln -s "${TOPWD}/ecs-init" "${SRCPATH}"
cd "${SRCPATH}/ecs-init"
if [[ "$1" == "dev" ]]; then
- go build -tags 'development' -o "${TOPWD}/amazon-ecs-init"
+ go build -tags -ldflags "${VERSIONFLAGS}" 'development' -o "${TOPWD}/amazon-ecs-init"
else
tags=""
if [[ "$1" != "" ]]; then
tags="-tags '$1'"
fi
- CGO_ENABLED=0 go build -a ${tags} -x -ldflags '-s' -o "${TOPWD}/amazon-ecs-init"
+ CGO_ENABLED=0 go build -a ${tags} -x -ldflags '-s' -ldflags "${VERSIONFLAGS}" -o "${TOPWD}/amazon-ecs-init"
fi
rm -r "${BUILDDIR}"
