more work on tracking on the version bulid time

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-06 18:56:15 -07:00
parent 2768e0f278
commit 47e169d2ba
5 changed files with 82 additions and 18 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@
# built. what version was built, etc
# TODO: find a better way (not via ldflags)
resources/build
resources/BUILDDATE
cloud-control-panel

View File

@ -48,7 +48,9 @@ tag-version:
git tag v${VERSION}
git push --tags
# https://mirrors.wit.com/cloud/control-panel/
scp VERSION root@mirrors.wit.com:/data/mirrors/cloud/control-panel/
scp VERSION root@mirrors.wit.com:/data/mirrors/cloud/control-panel/linux/
# date +%s > resources/BUILDDATE
scp resources/BUILDDATE root@mirrors.wit.com:/data/mirrors/cloud/control-panel/linux/
scp README root@mirrors.wit.com:/data/mirrors/cloud/control-panel/
# should update every go dependancy (?)

View File

@ -252,7 +252,7 @@ func parseConfig() {
config.Dirty = true
}
buf, _ := wget("https://mirrors.wit.com/cloud/control-panel/VERSION")
buf := wget("https://mirrors.wit.com/cloud/control-panel/VERSION")
upstream := shell.Chomp(buf)
epoch := shell.Run("git log -1 --format=%at v" + version)
@ -297,6 +297,8 @@ 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)
}

71
update.go Normal file
View File

@ -0,0 +1,71 @@
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
*/
import "log"
import "time"
import "runtime"
// import "os"
// import "os/user"
// import "flag"
// import "fmt"
// import "runtime/debug"
// import "io/ioutil"
// import "strings"
// import "reflect"
// import "bytes"
// import "sys"
// import "github.com/golang/protobuf/jsonpb"
// import pb "git.wit.com/wit/witProtobuf"
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")
mirrorsBUILDDATE := shell.Chomp(wget("https://mirrors.wit.com/cloud/control-panel/linux/BUILDDATE"))
upstream := shell.Chomp(wget("https://mirrors.wit.com/cloud/control-panel/linux/VERSION"))
upstreamEpoch := shell.Run("git log -1 --format=%at v" + upstream)
epoch := time.Now().Unix()
myBUILDDATE, _ := packrBox.FindString("BUILDDATE")
if (! config.Dirty) {
// See if a newer version of this control panel exists
// if (epoch > time.now().Unix()) // seconds since epoch
}
log.Println()
log.Println("version =", version)
log.Println("upstream =", upstream)
log.Println("now() =", epoch)
log.Println("myBUILDDATE =", myBUILDDATE)
log.Println("upstreamEpoch =", upstreamEpoch)
log.Println("mirrorsBUILDDATE =", mirrorsBUILDDATE)
log.Println()
log.Println("config.Gitref =", config.Gitref)
log.Println("config.Goversion =", config.Goversion)
log.Println("config.Dirty =", config.Dirty)
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()
for {}
// os.Exit(0)
}

20
wget.go
View File

@ -16,35 +16,23 @@ import "bytes"
import "io"
/*
import "log"
import "os/user"
import "flag"
import "fmt"
import "runtime"
import "strings"
import "reflect"
import "github.com/golang/protobuf/jsonpb"
import pb "git.wit.com/wit/witProtobuf"
import "git.wit.com/wit/shell"
import "github.com/davecgh/go-spew/spew"
*/
func wget(url string) (*bytes.Buffer, error) {
func wget(url string) (*bytes.Buffer) {
buf := new(bytes.Buffer)
// Get the data
resp, err := http.Get(url)
if err != nil {
return buf, err
errChan <- err
return buf
}
defer resp.Body.Close()
buf.ReadFrom(resp.Body)
// newStr := buf.String()
// tmp := string(resp.Body)
return buf, err
return buf
}
func wgetToFile(filepath string, url string) error {