diff --git a/GNUmakefile b/GNUmakefile index 069a7bc2f0..6bc619e5cc 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -25,7 +25,9 @@ GIT_COMMIT?=$(shell git rev-parse --short HEAD) GIT_COMMIT_YEAR?=$(shell git show -s --format=%cd --date=format:%Y HEAD) GIT_DIRTY?=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true) GIT_IMPORT=github.com/hashicorp/consul/version -GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) +DATE_FORMAT="%Y-%m-%dT%H:%M:%SZ" # it's tricky to do an RFC3339 format in a cross platform way, so we hardcode UTC +GIT_DATE=$(shell git show -s --format=%cd --date=format:"$(DATE_FORMAT)" HEAD) # we're using this for build date because it's stable across platform builds +GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) -X $(GIT_IMPORT).BuildDate=$(GIT_DATE) ifeq ($(FORCE_REBUILD),1) NOCACHE=--no-cache diff --git a/command/agent/agent.go b/command/agent/agent.go index 2167ba63b9..3bef84b0a8 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -27,12 +27,19 @@ import ( ) func New(ui cli.Ui) *cmd { + buildDate, err := time.Parse(time.RFC3339, consulversion.BuildDate) + if err != nil { + ui.Error(fmt.Sprintf("Fatal error with internal time set; check makefile for build date %v %v \n", buildDate, err)) + return nil + } + c := &cmd{ ui: ui, revision: consulversion.GitCommit, version: consulversion.Version, versionPrerelease: consulversion.VersionPrerelease, versionHuman: consulversion.GetHumanVersion(), + buildDate: buildDate, flags: flag.NewFlagSet("", flag.ContinueOnError), } config.AddFlags(c.flags, &c.configLoadOpts) @@ -53,6 +60,7 @@ type cmd struct { version string versionPrerelease string versionHuman string + buildDate time.Time configLoadOpts config.LoadOpts logger hclog.InterceptLogger } @@ -194,6 +202,7 @@ func (c *cmd) run(args []string) int { segment = "" } ui.Info(fmt.Sprintf(" Version: '%s'", c.versionHuman)) + ui.Info(fmt.Sprintf(" Build Date: %s", c.buildDate)) ui.Info(fmt.Sprintf(" Node ID: '%s'", config.NodeID)) ui.Info(fmt.Sprintf(" Node name: '%s'", config.NodeName)) if ap := config.PartitionOrEmpty(); ap != "" { diff --git a/version/version.go b/version/version.go index e7d187bfde..4ce586e77a 100644 --- a/version/version.go +++ b/version/version.go @@ -23,6 +23,9 @@ var ( // then it means that it is a final release. Otherwise, this is a pre-release // such as "dev" (in development), "beta", "rc1", etc. VersionPrerelease = "dev" + + // The date/time of the build + BuildDate string ) // GetHumanVersion composes the parts of the version in a way that's suitable