From de5f77d8e51c7ef5115657d1fbf872b06d19bb23 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Mon, 29 Feb 2016 10:25:49 -0800 Subject: [PATCH] fix(build): add build script --- scripts/build-go.sh | 22 ++++++++++++++++++++ scripts/common.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100755 scripts/build-go.sh create mode 100644 scripts/common.sh diff --git a/scripts/build-go.sh b/scripts/build-go.sh new file mode 100755 index 000000000..a824cdcbd --- /dev/null +++ b/scripts/build-go.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -o errexit +set -o pipefail + +[[ "$TRACE" ]] && set -x + +readonly REPO=github.com/kubernetes/deployment-manager +readonly DIR="${GOPATH}/src/${REPO}" + +source "${DIR}/scripts/common.sh" + +if [[ -z "${VERSION:-}" ]]; then + VERSION=$(version_from_git) +fi + +LDFLAGS="-s -X ${REPO}/pkg/version.DeploymentManagerVersion=${VERSION}" + +echo "Build version: ${VERSION}" + +build_binaries "$@" + +exit 0 diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100644 index 000000000..b55741392 --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +set -o errexit +set -o pipefail + +readonly ALL_TARGETS=(cmd/dm cmd/expandybird cmd/manager cmd/resourcifier) + +error_exit() { + # Display error message and exit + echo "error: ${1:-"unknown error"}" 1>&2 + exit 1 +} + +version_from_git() { + local git_tag=$(git describe --tags --abbrev=0 2>/dev/null) + local git_commit=$(git rev-parse --short HEAD) + echo "${git_tag}+${git_commit}" +} + +build_binary_cross() { + local target="$1" + + echo "Building ${target}" + gox -verbose \ + -ldflags="${LDFLAGS}" \ + -os="linux darwin" \ + -arch="amd64 386" \ + -output="bin/{{.OS}}-{{.Arch}}/{{.Dir}}" "${REPO}/${target}" +} + +build_binaries() { + local -a targets=($@) + + if [[ ${#targets[@]} -eq 0 ]]; then + targets=("${ALL_TARGETS[@]}") + fi + + for t in "${targets[@]}"; do + build_binary "$t" + done +} + +build_binary() { + local target="$1" + local binary="${target##*/}" + local outfile="bin/${binary}" + + echo "Building ${target}" + go build -o "$outfile" -ldflags "$LDFLAGS" "${REPO}/${target}" +}