From 71184100d6bafa66b0bd833adf7ff563b0397a4f Mon Sep 17 00:00:00 2001 From: Jaime Pillora Date: Wed, 21 Sep 2016 13:57:18 +1000 Subject: [PATCH] * bump to 1.7.1 * add cgo argument (also add to webui) * add env arguments --- Godeps/Godeps.json | 2 +- handler/compilation.go | 2 ++ handler/handler.go | 11 ++++---- handler/handler_compile.go | 17 ++++++++----- handler/handler_exec.go | 2 +- handler/handler_hook.go | 3 ++- handler/platforms.go | 52 ++++++++++---------------------------- static/files/index.html | 11 ++++++-- static/files/js/app.js | 1 + 9 files changed, 45 insertions(+), 56 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 061f04b..6b1c08d 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,6 +1,6 @@ { "ImportPath": "github.com/jpillora/cloud-gox", - "GoVersion": "go1.7rc5", + "GoVersion": "go1.7.1", "GodepVersion": "v74", "Deps": [ { diff --git a/handler/compilation.go b/handler/compilation.go index 1679d6c..aacec4f 100644 --- a/handler/compilation.go +++ b/handler/compilation.go @@ -21,9 +21,11 @@ type Compilation struct { Commitish string `json:"commitish"` CommitVar string `json:"commitVar"` //user compile options + CGO bool `json:"cgo"` Version string `json:"version"` VersionVar string `json:"versionVar"` Platforms Platforms `json:"platforms"` Targets []string `json:"targets"` LDFlags map[string]string `json:"ldflags"` + Env map[string]string `json:"env"` } diff --git a/handler/handler.go b/handler/handler.go index b06787b..0c2d807 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -75,19 +75,18 @@ func New() (http.Handler, error) { if err != nil { return nil, fmt.Errorf("go is not installed") } - - // go tool dist list - + platforms, err := GetDefaultPlatforms(goBin) + if err != nil { + return nil, fmt.Errorf("failed to list platforms (go 1.7 or higher required)") + } goPath := os.Getenv("GOPATH") if goPath == "" { return nil, fmt.Errorf("GOPATH is not set") } - userMessage := "" if u, err := user.Current(); err == nil { userMessage = fmt.Sprintf(" (process user: %s)", u.Username) } - //prepare temp dir if err := os.RemoveAll(tempBuild); err != nil && !os.IsNotExist(err) { return nil, fmt.Errorf("Failed to clear temporary directory: %s", err) @@ -115,7 +114,7 @@ func New() (http.Handler, error) { OS: runtime.GOOS, Arch: runtime.GOARCH, NumCPU: runtime.NumCPU(), - Platforms: defaultPlatforms, + Platforms: platforms, }, state: serverState{ Log: map[string]*message{}, diff --git a/handler/handler_compile.go b/handler/handler_compile.go index 6a0a28b..d2c8112 100644 --- a/handler/handler_compile.go +++ b/handler/handler_compile.go @@ -88,7 +88,6 @@ func (s *goxHandler) compile(c *Compilation) error { osarch := strings.SplitN(osarchstr, "/", 2) osname := osarch[0] arch := osarch[1] - targetFilename := fmt.Sprintf("%s_%s_%s", targetName, osname, arch) if osname == "windows" { targetFilename += ".exe" @@ -98,19 +97,25 @@ func (s *goxHandler) compile(c *Compilation) error { s.Printf("failed to find target %s\n", target) continue } - ldflags := "" for k, v := range c.LDFlags { ldflags += " -X main." + k + "=" + v } - args := []string{"build", "-v", "-ldflags", ldflags, "-o", targetOut, "."} - //run goxc with configuration - if err := s.exec(targetDir, "go", environ{"GOOS": osname, "GOARCH": arch}, args...); err != nil { + env := environ{} + if !c.CGO { + env["CGO"] = "0" + } + for k, v := range c.Env { + env[k] = v + } + env["GOOS"] = osname + env["GOARCH"] = arch + //run go build with cross compile configuration + if err := s.exec(targetDir, "go", env, args...); err != nil { s.Printf("failed to build %s\n", targetFilename) continue } - //gzip file b, err := ioutil.ReadFile(targetOut) if err != nil { diff --git a/handler/handler_exec.go b/handler/handler_exec.go index a02f754..7e8d4cb 100644 --- a/handler/handler_exec.go +++ b/handler/handler_exec.go @@ -51,7 +51,7 @@ func (s *goxHandler) exec(dir, prog string, env environ, args ...string) error { done <- cmd.Wait() }() select { - case <-time.After(120 * time.Second): + case <-time.After(300 * time.Second): err = errors.New("command timeout") cmd.Process.Kill() <-done //cmd.Wait says it was killed diff --git a/handler/handler_hook.go b/handler/handler_hook.go index f54e54c..1c209d9 100644 --- a/handler/handler_hook.go +++ b/handler/handler_hook.go @@ -64,13 +64,14 @@ func (s *goxHandler) hookReq(w http.ResponseWriter, r *http.Request) { Commitish: tag, Targets: targets, Releaser: "github", + CGO: q.Get("cgo") != "0", } //all hooks, by default, build for all systems if str := q.Get("osarch"); str != "" { c.OSArch = strings.Split(str, ",") } else { - c.Platforms = defaultPlatforms + c.Platforms = s.config.Platforms } err = s.enqueue(c) diff --git a/handler/platforms.go b/handler/platforms.go index 70705c8..65a6444 100644 --- a/handler/platforms.go +++ b/handler/platforms.go @@ -1,51 +1,25 @@ package handler -import "strings" - -//extracted from -//https://golang.org/doc/install/source#environment -// removed -// darwin arm -// darwin arm64 -const validPlatforms = ` -darwin 386 -darwin amd64 -dragonfly amd64 -freebsd 386 -freebsd amd64 -freebsd arm -linux 386 -linux amd64 -linux arm -linux arm64 -linux ppc64 -linux ppc64le -netbsd 386 -netbsd amd64 -netbsd arm -openbsd 386 -openbsd amd64 -openbsd arm -plan9 386 -plan9 amd64 -solaris amd64 -windows 386 -windows amd64 -` +import ( + "os/exec" + "strings" +) type Platforms map[string]map[string]bool -var defaultPlatforms = getDefaultPlatforms() - func isDefaultPlatform(os, arch string) bool { return (os == "linux" || os == "darwin" || os == "windows") && - (arch == "amd64" || arch == "386" || arch == "arm") + (arch == "amd64" || arch == "arm") } -func getDefaultPlatforms() Platforms { +func GetDefaultPlatforms(goBin string) (Platforms, error) { + out, err := exec.Command(goBin, "tool", "dist", "list").Output() + if err != nil { + return nil, err + } p := Platforms{} - for _, line := range strings.Split(validPlatforms, "\n") { - osarch := strings.SplitN(line, "\t", 2) + for _, line := range strings.Split(string(out), "\n") { + osarch := strings.SplitN(line, "/", 2) if len(osarch) != 2 { continue } @@ -58,5 +32,5 @@ func getDefaultPlatforms() Platforms { p[os] = map[string]bool{arch: def} } } - return p + return p, nil } diff --git a/static/files/index.html b/static/files/index.html index 8e69e91..4ec676d 100644 --- a/static/files/index.html +++ b/static/files/index.html @@ -41,7 +41,14 @@

Cloud Gox

-
+
+ +
+ + +
+
+
@@ -54,7 +61,7 @@

Cloud Gox

-
{{ showPlatforms && 'Hide' || 'Show' }} Platforms
+
{{ showMore && 'Hide' || 'Show' }} more
diff --git a/static/files/js/app.js b/static/files/js/app.js index fbeff5f..9847595 100644 --- a/static/files/js/app.js +++ b/static/files/js/app.js @@ -18,6 +18,7 @@ app.controller("AppController", function($scope, $http) { commitVar: "COMMIT", platforms: null, commitish: "", + cgo: true } //pull server config