diff --git a/daemon/mgr/system.go b/daemon/mgr/system.go index be0942470..0dd8d4e93 100644 --- a/daemon/mgr/system.go +++ b/daemon/mgr/system.go @@ -159,7 +159,7 @@ func (mgr *SystemManager) Version() (types.SystemVersion, error) { Arch: runtime.GOARCH, BuildTime: version.BuildTime, GitCommit: version.GitCommit, - GoVersion: version.GOVersion, + GoVersion: runtime.Version(), KernelVersion: kernelVersion, Os: runtime.GOOS, Version: version.Version, diff --git a/hack/build b/hack/build index e51813612..80bb7253d 100755 --- a/hack/build +++ b/hack/build @@ -6,8 +6,15 @@ DIR="$( cd "$( dirname "$0" )/.." && pwd )" cd $DIR/ GOPATH=$BUILDPATH:$BUILDPATH/src/github.com/docker/libnetwork/Godeps/_workspace + # Go parameters +VERSION="0.4.0" +APIVERSION="1.24" +GITCOMMIT=$(git describe --dirty --always --tags 2> /dev/null || true) +BUILDTIME=$(date --rfc-3339 s 2> /dev/null | sed -e 's/ /T/') +PKG=github.com/alibaba/pouch GOBUILD="go build" +GOLDFLAGS="-X $PKG/version.GitCommit=${GITCOMMIT} -X $PKG/version.Version=${VERSION} -X $PKG/version.ApiVersion=${APIVERSION} -X $PKG/version.BuildTime=$BUILDTIME" # Binary name of CLI and Daemon BINARY_NAME=pouchd @@ -30,7 +37,7 @@ function server() { cd $BUILDPATH/src/github.com/alibaba/pouch echo "GOOS=linux $GOBUILD -o $BINARY_NAME" - GOOS=linux $GOBUILD -o $BINARY_NAME -tags 'selinux' + GOOS=linux $GOBUILD -ldflags "${GOLDFLAGS}" -o $BINARY_NAME -tags 'selinux' } function client() diff --git a/main.go b/main.go index 31a542ea2..4460734bb 100644 --- a/main.go +++ b/main.go @@ -122,7 +122,7 @@ func parseFlags(cmd *cobra.Command, flags []string) { func runDaemon() error { //user specifies --version or -v, print version and return. if printVersion { - fmt.Println(version.Version) + fmt.Printf("pouchd version: %s, build: %s, build at: %s\n", version.Version, version.GitCommit, version.BuildTime) return nil } diff --git a/test/cli_version_test.go b/test/cli_version_test.go index 4ee0112c5..7a4c47bd1 100644 --- a/test/cli_version_test.go +++ b/test/cli_version_test.go @@ -32,7 +32,7 @@ func (suite *PouchVersionSuite) TestPouchVersion(c *check.C) { res := command.PouchRun("version").Assert(c, icmd.Success) kv := versionToKV(res.Combined()) - c.Assert(kv["GoVersion"], check.Equals, version.GOVersion) + c.Assert(kv["GoVersion"], check.Equals, runtime.Version()) c.Assert(kv["APIVersion"], check.Equals, version.APIVersion) c.Assert(kv["Arch"], check.Equals, runtime.GOARCH) c.Assert(kv["Os"], check.Equals, runtime.GOOS) diff --git a/version/version.go b/version/version.go index 3acc1bc50..b7a0fa429 100644 --- a/version/version.go +++ b/version/version.go @@ -1,16 +1,16 @@ package version -// Version represents the version of pouchd. -const Version = "0.4.0" +// Version package values is auto-generated, the following values will be overwrited at build time. +var ( + // Version represents the version of pouchd. + Version = "0.4.0" -// BuildTime is the time when this binary of daemon is built -var BuildTime = "unknown" + // BuildTime is the time when pouch binary is built + BuildTime = "unknown" -// APIVersion means the api version daemon serves -var APIVersion = "1.24" + // APIVersion means the api version daemon serves + APIVersion = "1.24" -// GOVersion is the go version to build Pouch -var GOVersion = "go1.9.1" - -// GitCommit is the commit id to build Pouch -var GitCommit = "unknown" + // GitCommit is the commit id to build Pouch + GitCommit = "unknown" +)