move VERSION into the go binary

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-06 20:56:14 -07:00
parent 1c3040c4e9
commit fca9b170f9
8 changed files with 70 additions and 29 deletions

View File

@ -1,7 +1,7 @@
GITCOMMIT = $(shell git rev-list -1 HEAD)
GOVERSION = $(shell go version | cut -d' ' -f 3)
BUILDTIME = $(shell date -u --iso-8601=seconds)
VERSION = $(shell cat VERSION)
VERSION = $(shell cat resources/VERSION)
GO111MODULE=on
@ -14,7 +14,7 @@ run:
./cloud-control-panel
build:
go build -ldflags "-X main.GITCOMMIT=${GITCOMMIT} -X main.VERSION=${VERSION}"
go build -ldflags "-X main.GITCOMMIT=${GITCOMMIT}"
default-config: config-delete
echo loading the test config

View File

@ -1 +0,0 @@
0.6.18

View File

@ -297,8 +297,6 @@ func parseConfig() {
// my pid (cross platform) p, err := os.FindProcess(os.Getpid())
// send signal (cross platform) return p.Signal(syscall.SIGTERM)
update()
// for {}
// os.Exit(0)
}

View File

@ -8,6 +8,7 @@ import "os/exec"
import "strings"
import "git.wit.com/wit/gui"
import "git.wit.com/wit/shell"
// import pb "git.wit.com/wit/witProtobuf"
import "github.com/davecgh/go-spew/spew"
@ -47,7 +48,7 @@ func debugClick(b *gui.GuiButton) {
Ybox3 := gui.NewBox(Ybox1, gui.Yaxis, "subdomain Y1 test")
gui.NewLabel(Ybox3, "git rev-list: " + config.Gitref)
gui.NewLabel(Ybox3, "go build version: " + config.Goversion)
gui.NewLabel(Ybox3, "build date: " + BUILDTIME)
gui.NewLabel(Ybox3, "build date: " + shell.Chomp(config.Builddate))
Ybox2 := gui.NewBox(hardXbox, gui.Yaxis, "subdomain Y test")
makeColorButton(Ybox2, nil, nil, "COLOR73", "COLOR73", nil)

View File

@ -4,6 +4,7 @@ import "log"
import "runtime"
import "git.wit.com/wit/gui"
import "git.wit.com/wit/shell"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
@ -24,12 +25,16 @@ func showSplashBox(gw *gui.GuiWindow) *gui.GuiBox {
gui.NewLabel(box,"OS: " + runtime.GOOS)
}
gui.NewLabel(box, "Version: " + config.Version)
if (config.Dirty) {
gui.NewLabel(box, "Version: " + config.Version + " (dirty)")
} else {
gui.NewLabel(box, "Version: " + config.Version)
}
if (config.Debug) {
gui.NewLabel(box, "git rev-list: " + config.Gitref)
gui.NewLabel(box, "go build version: " + config.Goversion)
gui.NewLabel(box, "build date: " + BUILDTIME)
gui.NewLabel(box, "build date: " + shell.Chomp(config.Builddate))
}
button := makeButton(box, nil, nil, "OK", "AREA", splashClick)

13
main.go
View File

@ -21,9 +21,9 @@ 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 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 State string // used as a State machine
var sigChan chan os.Signal
@ -114,11 +114,8 @@ func main() {
// golang application IMHO
parseConfig()
if (config.Dirty) {
config.Version = VERSION + " (dirty)"
} else {
config.Version = VERSION
}
// this checks to see if there is a newer upstream version
upgrade()
for key, foo := range config.Accounts {
log.Println("FOUND ACCOUNT = ", key, foo)

1
resources/VERSION Normal file
View File

@ -0,0 +1 @@
0.6.19

View File

@ -1,13 +1,7 @@
package main
/*
This simply parses the command line arguments using the default golang
package called 'flag'. This can be used as a simple template to parse
command line arguments in other programs.
It puts everything in a 'config' Protobuf which I think is a good
wrapper around the 'flags' package and doesn't need a whole mess of
global variables
Check to see if there is a new version to upgrade
*/
import "log"
@ -18,12 +12,59 @@ import "git.wit.com/wit/shell"
// import "github.com/davecgh/go-spew/spew"
//
// This is what you call from main()
//
func update() {
version := shell.Run("cat VERSION")
func upgrade() {
mirrorsBUILDDATE := shell.Chomp(shell.Wget("https://mirrors.wit.com/cloud/control-panel/linux/BUILDDATE"))
// When this binary was built
myBUILDDATE, _ := packrBox.FindString("BUILDDATE")
myBUILDDATE = shell.Chomp(myBUILDDATE)
myBUILDVERSION, _ := packrBox.FindString("VERSION")
myBUILDVERSION = shell.Chomp(myBUILDVERSION)
config.Version = myBUILDVERSION
config.Builddate = shell.Int64(myBUILDDATE)
log.Println()
log.Println("config.Dirty =", config.Dirty)
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)
log.Println()
log.Println("update() compare", mirrorsBUILDDATE, "to", myBUILDDATE)
if (! config.Dirty) {
// See if a newer version of this control panel exists
// if (epoch > time.now().Unix()) // seconds since epoch
if (shell.Int(mirrorsBUILDDATE) > shell.Int(myBUILDDATE)) {
log.Println("update() THERE IS A NEW UPSTREAM VERSION !!!")
log.Println("update() THERE IS A NEW UPSTREAM VERSION !!!")
log.Println("update() THERE IS A NEW UPSTREAM VERSION !!!")
time.Sleep(time.Second * 2)
} else {
log.Println("update() UPSTREAM VERSION IS OLDER THAN THIS")
}
} else {
if (shell.Int(mirrorsBUILDDATE) > shell.Int(myBUILDDATE)) {
log.Println("update() dirty=true THERE IS A NEW UPSTREAM VERSION !!!")
log.Println("update() dirty=true THERE IS A NEW UPSTREAM VERSION !!!")
log.Println("update() dirty=true THERE IS A NEW UPSTREAM VERSION !!!")
time.Sleep(time.Second * 2)
} else {
log.Println("update() dirty=true UPSTREAM VERSION IS OLDER THAN THIS")
}
}
time.Sleep(time.Second)
// for {}
// os.Exit(0)
}
func updateDebug() {
mirrorsBUILDDATE := shell.Chomp(shell.Wget("https://mirrors.wit.com/cloud/control-panel/linux/BUILDDATE"))
upstream := shell.Chomp(shell.Wget("https://mirrors.wit.com/cloud/control-panel/linux/VERSION"))
upstreamEpoch := shell.Run("git log -1 --format=%at v" + upstream)
@ -33,7 +74,6 @@ func update() {
myBUILDDATE = shell.Chomp(myBUILDDATE)
log.Println()
log.Println("version =", version)
log.Println("upstream =", upstream)
log.Println("now() =", epoch)
log.Println("myBUILDDATE =", myBUILDDATE)