Skip to content

Commit caf45ec

Browse files
committed
build: generate version information at build time
auto-generate git commit, build time at build time, fix go-version hard code. Signed-off-by: Ace-Tang <[email protected]>
1 parent ecbe3b6 commit caf45ec

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

daemon/mgr/system.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (mgr *SystemManager) Version() (types.SystemVersion, error) {
159159
Arch: runtime.GOARCH,
160160
BuildTime: version.BuildTime,
161161
GitCommit: version.GitCommit,
162-
GoVersion: version.GOVersion,
162+
GoVersion: runtime.Version(),
163163
KernelVersion: kernelVersion,
164164
Os: runtime.GOOS,
165165
Version: version.Version,

hack/build

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ DIR="$( cd "$( dirname "$0" )/.." && pwd )"
66
cd $DIR/
77
GOPATH=$BUILDPATH:$BUILDPATH/src/github.com/docker/libnetwork/Godeps/_workspace
88

9+
910
# Go parameters
11+
VERSION="0.4.0"
12+
APIVERSION="1.24"
13+
GITCOMMIT=$(git describe --dirty --always --tags 2> /dev/null || true)
14+
BUILDTIME=$(date --rfc-3339 s 2> /dev/null | sed -e 's/ /T/')
15+
PKG=github.com/alibaba/pouch
1016
GOBUILD="go build"
17+
GOLDFLAGS="-X $PKG/version.GitCommit=${GITCOMMIT} -X $PKG/version.Version=${VERSION} -X $PKG/version.ApiVersion=${APIVERSION} -X $PKG/version.BuildTime=$BUILDTIME"
1118

1219
# Binary name of CLI and Daemon
1320
BINARY_NAME=pouchd
@@ -30,7 +37,7 @@ function server()
3037
{
3138
cd $BUILDPATH/src/github.com/alibaba/pouch
3239
echo "GOOS=linux $GOBUILD -o $BINARY_NAME"
33-
GOOS=linux $GOBUILD -o $BINARY_NAME -tags 'selinux'
40+
GOOS=linux $GOBUILD -ldflags "${GOLDFLAGS}" -o $BINARY_NAME -tags 'selinux'
3441
}
3542

3643
function client()

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func parseFlags(cmd *cobra.Command, flags []string) {
122122
func runDaemon() error {
123123
//user specifies --version or -v, print version and return.
124124
if printVersion {
125-
fmt.Println(version.Version)
125+
fmt.Printf("pouchd version: %s, build: %s, build at: %s\n", version.Version, version.GitCommit, version.BuildTime)
126126
return nil
127127
}
128128

test/cli_version_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (suite *PouchVersionSuite) TestPouchVersion(c *check.C) {
3232
res := command.PouchRun("version").Assert(c, icmd.Success)
3333
kv := versionToKV(res.Combined())
3434

35-
c.Assert(kv["GoVersion"], check.Equals, version.GOVersion)
35+
c.Assert(kv["GoVersion"], check.Equals, runtime.Version())
3636
c.Assert(kv["APIVersion"], check.Equals, version.APIVersion)
3737
c.Assert(kv["Arch"], check.Equals, runtime.GOARCH)
3838
c.Assert(kv["Os"], check.Equals, runtime.GOOS)

version/version.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package version
22

3-
// Version represents the version of pouchd.
4-
const Version = "0.4.0"
3+
// Version package values is auto-generated, the following values will be overwrited at build time.
4+
var (
5+
// Version represents the version of pouchd.
6+
Version = "0.4.0"
57

6-
// BuildTime is the time when this binary of daemon is built
7-
var BuildTime = "unknown"
8+
// BuildTime is the time when pouch binary is built
9+
BuildTime = "unknown"
810

9-
// APIVersion means the api version daemon serves
10-
var APIVersion = "1.24"
11+
// APIVersion means the api version daemon serves
12+
APIVersion = "1.24"
1113

12-
// GOVersion is the go version to build Pouch
13-
var GOVersion = "go1.9.1"
14-
15-
// GitCommit is the commit id to build Pouch
16-
var GitCommit = "unknown"
14+
// GitCommit is the commit id to build Pouch
15+
GitCommit = "unknown"
16+
)

0 commit comments

Comments
 (0)