Skip to content

Commit e1af50b

Browse files
committed
Add 'release mode' to build script
1 parent 6dd63f4 commit e1af50b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

build/build.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,28 @@
1616

1717
set -e
1818

19+
RELEASE=${RELEASE:-false} # Whether to build for an official release.
20+
1921
repo_path="github.com/google/cadvisor"
2022

2123
version=$( cat version/VERSION )
2224
revision=$( git rev-parse --short HEAD 2> /dev/null || echo 'unknown' )
2325
branch=$( git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown' )
24-
host=$( hostname -f )
26+
build_user="${USER}@${HOSTNAME}"
2527
build_date=$( date +%Y%m%d-%H:%M:%S )
2628
go_version=$( go version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/' )
2729

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+
2841
# go 1.4 requires ldflags format to be "-X key value", not "-X key=value"
2942
ldseparator="="
3043
if [ "${go_version:0:3}" = "1.4" ]; then
@@ -35,11 +48,16 @@ ldflags="
3548
-X ${repo_path}/version.Version${ldseparator}${version}
3649
-X ${repo_path}/version.Revision${ldseparator}${revision}
3750
-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}
3952
-X ${repo_path}/version.BuildDate${ldseparator}${build_date}
4053
-X ${repo_path}/version.GoVersion${ldseparator}${go_version}"
4154

4255
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}"
4462

4563
exit 0

0 commit comments

Comments
 (0)