forked from spinnaker/spin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·83 lines (68 loc) · 1.5 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
set -e
set -x
VERSION=
RELEASE_PHASE=
go_os=
go_arch=
function process_args() {
while [[ $# -gt 0 ]]
do
local key="$1"
shift
case ${key} in
--go-arch)
go_arch="$1"
shift
;;
--go-os)
go_os="$1"
shift
;;
--release-phase)
RELEASE_PHASE="$1"
shift
;;
--version)
VERSION="$1"
shift
;;
--help|-help|-h)
print_usage
exit 0
;;
*)
echo "ERROR: Unknown argument '$key'"
exit -1
esac
done
}
function print_usage() {
cat <<EOF
usage: $0 --version <version>
[--go-arch <arch>] [--go-os <os>]
[--release-phase <phase>]
--go-arch <arg> Architecture to build the binary for.
--go-os <arg> OS distribution to build for binary for.
--release-phase <arg> Release phase to decorate the version with.
--version <arg> Version to build the 'spin' binaries with.
EOF
}
process_args "$@"
if [[ -z "$VERSION" ]]; then
echo "No Version specified, using git hash at head."
VERSION="$(git rev-parse HEAD)"
fi
if [[ ! -z "$go_arch" ]]; then
export GOARCH="$go_arch"
fi
if [[ ! -z "$go_os" ]]; then
export GOOS="$go_os"
fi
LD_FLAGS=<<EOF
-X github.com/spinnaker/spin/version.Version=${VERSION} \
-X github.com/spinnaker/spin/version.ReleasePhase=${RELEASE_PHASE}"
EOF
go clean
go get -d -v
CGO_ENABLED=0 go build -ldflags "${LD_FLAGS}" .