This repository has been archived by the owner on Feb 23, 2021. It is now read-only.
forked from google/cadvisor
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·77 lines (62 loc) · 2.54 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
#!/usr/bin/env bash
# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
RELEASE=${RELEASE:-false} # Whether to build for an official release.
GO_FLAGS=${GO_FLAGS:-} # Extra go flags to use in the build.
repo_path="github.com/google/cadvisor"
version=$( git describe --tags --dirty --abbrev=14 | sed -E 's/-([0-9]+)-g/.\1+/' )
revision=$( git rev-parse --short HEAD 2> /dev/null || echo 'unknown' )
branch=$( git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown' )
build_user="${USER}@${HOSTNAME}"
build_date=$( date +%Y%m%d-%H:%M:%S )
go_version=$( go version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/' )
GO_CMD="install"
if [ "$RELEASE" == "true" ]; then
# Only allow releases of tagged versions.
TAGGED='^v[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta)[0-9]*)?$'
if [[ ! "$version" =~ $TAGGED ]]; then
echo "Error: Only tagged versions are allowed for releases" >&2
echo "Found: $version" >&2
exit 1
fi
# Don't include hostname with release builds
if ! build_user="$(git config --get user.email)"; then
echo "Error: git user not set, use:"
echo "git config user.email <email>"
exit 1
fi
build_date=$( date +%Y%m%d ) # Release date is only to day-granularity
# Don't use cached build objects for releases.
GO_CMD="build GOARCH=arm"
fi
# go 1.4 requires ldflags format to be "-X key value", not "-X key=value"
ldseparator="="
if [ "${go_version:0:3}" = "1.4" ]; then
ldseparator=" "
fi
ldflags="
-extldflags '-static'
-X ${repo_path}/version.Version${ldseparator}${version}
-X ${repo_path}/version.Revision${ldseparator}${revision}
-X ${repo_path}/version.Branch${ldseparator}${branch}
-X ${repo_path}/version.BuildUser${ldseparator}${build_user}
-X ${repo_path}/version.BuildDate${ldseparator}${build_date}
-X ${repo_path}/version.GoVersion${ldseparator}${go_version}"
echo ">> building cadvisor"
if [ "$RELEASE" == "true" ]; then
echo "Building release candidate with -ldflags $ldflags"
fi
GOBIN=$PWD go "$GO_CMD" ${GO_FLAGS} -ldflags "${ldflags}" "${repo_path}"
exit 0