From 3f5c15a56a0cdb08b1b358af8be0a38b10a6814c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 14 Jun 2019 10:48:14 -0700 Subject: [PATCH] move autobuild out of this repo Signed-off-by: Jeff Carr --- autobuild/Makefile | 2 - autobuild/autobuild.go | 156 ----------------------------------------- build/build.go | 58 ++------------- 3 files changed, 5 insertions(+), 211 deletions(-) delete mode 100644 autobuild/Makefile delete mode 100644 autobuild/autobuild.go diff --git a/autobuild/Makefile b/autobuild/Makefile deleted file mode 100644 index 712fb30..0000000 --- a/autobuild/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - go install diff --git a/autobuild/autobuild.go b/autobuild/autobuild.go deleted file mode 100644 index b270ba6..0000000 --- a/autobuild/autobuild.go +++ /dev/null @@ -1,156 +0,0 @@ -package main - -// This should build and upload the binary to mirrors - -// upload binary to mirrors.wit.com/cloud/control-panel - -import "log" -import "fmt" -import "time" -import "strings" -import "os/user" -import "os" -import "runtime" - -import "github.com/davecgh/go-spew/spew" - -import "git.wit.com/wit/shell" - -// import "os/user" -// import "io/ioutil" -// github.com/bramvdbogaerde/go-scp - -var BuildMap map[string]*bool - -var filename string -var builddir string - -func main() { - BuildMap = make(map[string]*bool) - - setbuilddir() - - // shell.Quiet(true) - shell.Quiet(false) - - // shell.Run("git tag --list") - // os.Exit(-1) - - for { - shell.Run("git checkout master") - shell.Run("git pull --tags") - findtags() - time.Sleep(time.Second * 60) - } -} - -func findtags() { - tags := shell.Run("git tag --list") - // log.Println(tags) - for _, tag := range strings.Split(tags, "\n") { - tag = strings.Replace(tag, "v", "", -1) // remove all 'v' chars - if (BuildMap[tag] == nil) { - log.Println("TAG =", tag, "is nil") - log.Println("\tCHECK IF BUILD WAS ATTEMPTED =", tag) - BuildMap[tag] = build(tag) - } else { - if (*BuildMap[tag] == true) { - log.Println("TAG =", tag, "is true") - } else { - log.Println("TAG =", tag, "is false") - } - } - } - - // os.Exit(0) -} - -func build(tag string) *bool { - var b bool - url := "https://mirrors.wit.com/cloud/control-panel/linux/" + filename + "-v" + tag + ".md5sum" - log.Println("\tTRYING URL", url) - - md5sum := shell.Chomp(shell.Wget(url)) - if (md5sum != "") { - log.Println("\tBUILD ALREADY DONE TAG =", tag, "md5sum =", md5sum) - b = true - // for {} - return &b - } - // for {} - - shell.Quiet(false) - - shell.Run("go get -v ...") - shell.Run("go get -v -u ...") - shell.Run("go get -v -u -t") - - shell.Run("git checkout v" + tag) - - gitref := shell.Run("git rev-list -1 HEAD") - tagref := shell.Run("git rev-list -1 v" + tag) - - if (gitref != tagref) { - log.Println("\tWHAT WENT WRONG?", gitref, "ne", tagref) - b = false - return &b - } - - // setup the files that will end up in the binary - epoch := fmt.Sprintf("%d", time.Now().Unix()) - shell.Write("./resources/build.DATE", epoch) - shell.Write("./resources/build.REF", gitref) - - // rebuild the binary (always remove the old one - shell.Run("rm " + filename) - shell.Run("packr build") - md5sum = shell.Run("md5sum " + filename) - log.Println("\tmd5sum =", md5sum) - - if (md5sum == "") { - log.Println("\tBUILD FAILED") - b = false - return &b - } - shell.Write("/tmp/autobuild.md5sum", md5sum) - upload(tag) - - // This version has been built yet - log.Println("\tTHIS VERSION HAS BEEN UPLOADED =", tag) - b = true - return &b -} - -func setbuilddir() { - user, err := user.Current() - spew.Dump(user) - if err != nil { - os.Exit(-1) - } - - if runtime.GOOS == "linux" { - log.Println("loadConfigFile() OS: Linux") - filename = "cloud-control-panel" - builddir = user.HomeDir + "/go/src/git.wit.com/wit/cloud-control-panel" - } else if runtime.GOOS == "windows" { - log.Println("loadConfigFile() OS: Windows") - builddir = user.HomeDir + "\\go\\src\\git.wit.com\\wit\\cloud-control-panel" - filename = "cloud-control-panel.exe" - } else { - log.Println("loadConfigFile() OS: " + runtime.GOOS) - filename = "cloud-control-panel" - builddir = user.HomeDir + "/go/src/git.wit.com/wit/cloud-control-panel" - } -} - -// upload the files to mirrors -func upload(tag string) { - mirrors := "root@mirrors.wit.com:/data/mirrors/cloud/control-panel/linux/" - - // don't update the master VERSION here - // shell.Run("scp resources/VERSION " + mirrors) - shell.Run("scp cloud-control-panel " + mirrors) - shell.Run("scp resources/BUILDDATE " + mirrors + filename + "-v" + tag + ".BUILDDATE") - shell.Run("scp cloud-control-panel " + mirrors + filename + "-v" + tag) - shell.Run("scp /tmp/autobuild.md5sum " + mirrors + filename + "-v" + tag + ".md5sum") -} diff --git a/build/build.go b/build/build.go index 92253de..ceaeb42 100644 --- a/build/build.go +++ b/build/build.go @@ -5,71 +5,23 @@ package main // Then, upload the binaries to mirrors.wit.com/cloud/control-panel import "log" -import "fmt" -import "time" -import "os/user" +//import "fmt" +//import "time" +//import "os/user" import "git.wit.com/wit/shell" +import build "git.wit.com/wit/cloud-control-panel-build" var filename string func main() { shell.Quiet(false) - md5sum := build() + md5sum := build.Build() log.Println("\tmd5sum =", md5sum) if (md5sum == "") { log.Println("\tBUILD FAILED") return } - -/* - // upload test - sess := shell.SSH("mirrors.wit.com", 22, "jcarr", "") - shell.Scp(sess, filename, "/tmp/jcarr-testing") -*/ -} - -func build() string { - user, _ := user.Current() - log.Println("user.HomeDir =", user.HomeDir) - - filename = shell.Execname("cloud-control-panel") // returns the right name for each OS - - gitref := shell.Run("git rev-list -1 HEAD") - - // setup the files that will end up in the binary - epoch := fmt.Sprintf("%d", time.Now().Unix()) - shell.Write("./resources/build.DATE", epoch) - shell.Write("./resources/build.REF", gitref) - - // make a dirty file if this build is dirty - shell.Run("rm ./resources/build.DIRTY") - - version := shell.Run("cat ./resources/VERSION") - versionref := shell.Run("git rev-list -1 v" + version) - - if (gitref != versionref) { - log.Println("build is DIRTY", gitref, "!=", versionref) - shell.Write("./resources/build.DIRTY", versionref) - } - - // Test if there are pending diffs. If so, also mark this as dirty. - diff := shell.Run("git diff HEAD") - if (diff != "") { - log.Println("build is DIRTY -- pending diffs") - shell.Write("./resources/build.DIRTY", "pending diffs") - } - - // rebuild the binary (always remove the old one - shell.Run("rm " + filename) - shell.Run("packr build") - log.Println("build finished") - - md5sum := shell.Md5sum(filename) - log.Println("\tmd5sum =", md5sum) - shell.Write("/tmp/build.md5sum", md5sum) - - return md5sum }