16
16
17
17
set -e
18
18
19
+ RELEASE=${RELEASE:- false} # Whether to build for an official release.
20
+
19
21
repo_path=" github.com/google/cadvisor"
20
22
21
23
version=$( cat version/VERSION )
22
24
revision=$( git rev-parse --short HEAD 2> /dev/null || echo ' unknown' )
23
25
branch=$( git rev-parse --abbrev-ref HEAD 2> /dev/null || echo ' unknown' )
24
- host= $( hostname -f )
26
+ build_user= " ${USER} @ ${HOSTNAME} "
25
27
build_date=$( date +%Y%m%d-%H:%M:%S )
26
28
go_version=$( go version | sed -e ' s/^[^0-9.]*\([0-9.]*\).*/\1/' )
27
29
30
+ GO_CMD=" install"
31
+
32
+ if [ " $RELEASE " == " true" ]; then
33
+ # Don't include hostname with release builds
34
+ build_user=" $( git config --get user.email) "
35
+ build_date=$( date +%Y%m%d ) # Release date is only to day-granularity
36
+
37
+ # Don't use cached build objects for releases.
38
+ GO_CMD=" build"
39
+ fi
40
+
28
41
# go 1.4 requires ldflags format to be "-X key value", not "-X key=value"
29
42
ldseparator=" ="
30
43
if [ " ${go_version: 0: 3} " = " 1.4" ]; then
@@ -35,11 +48,16 @@ ldflags="
35
48
-X ${repo_path} /version.Version${ldseparator}${version}
36
49
-X ${repo_path} /version.Revision${ldseparator}${revision}
37
50
-X ${repo_path} /version.Branch${ldseparator}${branch}
38
- -X ${repo_path} /version.BuildUser${ldseparator}${USER} @ ${host }
51
+ -X ${repo_path} /version.BuildUser${ldseparator}${build_user }
39
52
-X ${repo_path} /version.BuildDate${ldseparator}${build_date}
40
53
-X ${repo_path} /version.GoVersion${ldseparator}${go_version} "
41
54
42
55
echo " > cadvisor"
43
- GOBIN=$PWD godep go install -ldflags " ${ldflags} " ${repo_path}
56
+
57
+ if [ " $RELEASE " == " true" ]; then
58
+ echo " Building release candidate with -ldflags $ldflags "
59
+ fi
60
+
61
+ GOBIN=$PWD godep go " $GO_CMD " -ldflags " ${ldflags} " " ${repo_path} "
44
62
45
63
exit 0
0 commit comments