From 8465dae8a34e6eacb60a65ef5d77600a184c0d78 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 6 Jun 2019 21:23:43 -0700 Subject: [PATCH] no longer pass build flags via ldflags Signed-off-by: Jeff Carr --- Makefile | 4 ++-- config.go | 40 ++++------------------------------------ main.go | 8 ++++---- resources/BUILDREF | 1 + upgrade.go | 3 ++- 5 files changed, 13 insertions(+), 43 deletions(-) create mode 100644 resources/BUILDREF diff --git a/Makefile b/Makefile index 4fdca3f..fca441c 100644 --- a/Makefile +++ b/Makefile @@ -10,11 +10,11 @@ GO111MODULE=on run: @echo your version of go must be greater than 2.10. Your version is ${GOVERSION} - go build -ldflags "-X main.GITCOMMIT=${GITCOMMIT} -X main.GOVERSION='${GOVERSION}' -X main.BUILDTIME='${BUILDTIME}' -X main.VERSION=${VERSION}" + go build ./cloud-control-panel build: - go build -ldflags "-X main.GITCOMMIT=${GITCOMMIT}" + go build default-config: config-delete echo loading the test config diff --git a/config.go b/config.go index 7046ac5..41bfeb7 100644 --- a/config.go +++ b/config.go @@ -25,7 +25,7 @@ import "reflect" import "github.com/golang/protobuf/jsonpb" import pb "git.wit.com/wit/witProtobuf" -import "git.wit.com/wit/shell" +// import "git.wit.com/wit/shell" import "github.com/davecgh/go-spew/spew" @@ -223,27 +223,10 @@ func parseConfig() { } } - version := shell.Run("cat VERSION") - version = fmt.Sprintf("%s", strings.Trim(version, "\n")) - - // version, _ := ioutil.ReadFile("VERSION") -// version = fmt.Sprintf("%s", version.String()) - - perl(version) - - log.Println("VERSION =", version) - log.Println("len(VERSION) =", len(version)) - - tagref := shell.Run("cat .git/refs/tags/v" + version) - perl(tagref) - tagref = strings.TrimSpace(tagref) - log.Println("VERSION git tag ref =", tagref) - - config.Gitref = shell.Run("git rev-list -1 HEAD") - - config.Goversion = shell.Run("go version") + // config.Gitref = shell.Run("git rev-list -1 HEAD") config.Dirty = false + /* if (tagref == config.Gitref) { log.Println("setting config.Dirty = false") config.Dirty = false @@ -251,23 +234,8 @@ func parseConfig() { log.Println("setting config.Dirty = true") config.Dirty = true } + */ - buf := shell.Wget("https://mirrors.wit.com/cloud/control-panel/VERSION") - upstream := shell.Chomp(buf) - - epoch := shell.Run("git log -1 --format=%at v" + version) - // epoch = chomp(epoch) - - if (! config.Dirty) { - // See if a newer version of this control panel exists - - // if (epoch > time.now().Unix()) // seconds since epoch - } - - log.Println("epoch =", epoch) - log.Println("version =", version) - log.Println("upstream =", upstream) - log.Println("tagref =", tagref) log.Println("config.Gitref =", config.Gitref) log.Println("config.Goversion =", config.Goversion) log.Println("config.Dirty =", config.Dirty) diff --git a/main.go b/main.go index dfd7e5d..b6042a3 100644 --- a/main.go +++ b/main.go @@ -20,10 +20,7 @@ import "git.wit.com/wit/shell" import "github.com/gobuffalo/packr" import "github.com/davecgh/go-spew/spew" -var GITCOMMIT string // this is passed in as an ldflag -// var GOVERSION string // this is passed in as an ldflag -// var BUILDTIME string // this is passed in as an ldflag -// var VERSION string // this is passed in as an ldflag +// var GITCOMMIT string // this is passed in as an ldflag var State string // used as a State machine var sigChan chan os.Signal @@ -100,6 +97,9 @@ func main() { epoch := fmt.Sprintf("%d", time.Now().Unix()) shell.Write("./resources/BUILDDATE", epoch) + + ref := shell.Run("git rev-list -1 HEAD") + shell.Write("./resources/BUILDREF", ref) // for {} // This puts all the files in that directory in the binary diff --git a/resources/BUILDREF b/resources/BUILDREF new file mode 100644 index 0000000..50b9361 --- /dev/null +++ b/resources/BUILDREF @@ -0,0 +1 @@ +26322fa7d5382c9c03cfab9d49ee8c317fbaad6c diff --git a/upgrade.go b/upgrade.go index dd91d2e..e029a7e 100644 --- a/upgrade.go +++ b/upgrade.go @@ -22,15 +22,16 @@ func upgrade() { myBUILDVERSION = shell.Chomp(myBUILDVERSION) config.Version = myBUILDVERSION config.Builddate = shell.Int64(myBUILDDATE) + config.Goversion = runtime.Version() log.Println() log.Println("config.Dirty =", config.Dirty) + log.Println("config.Goversion =", config.Goversion) log.Println() log.Println("myBUILDVERSION =", myBUILDVERSION) log.Println("myBUILDDATE =", myBUILDDATE) log.Println("mirrorsBUILDDATE =", mirrorsBUILDDATE) log.Println() - log.Println("runtime.Version =", runtime.Version()) log.Println("Number of CPUs =", runtime.NumCPU()) log.Println("Number of GoRoutines =", runtime.NumGoroutine()) log.Println("runtime.GOARCH =", runtime.GOARCH)