Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
* bump to 1.7.1
Browse files Browse the repository at this point in the history
* add cgo argument (also add to webui)
* add env arguments
  • Loading branch information
jpillora committed Sep 21, 2016
1 parent 7e83634 commit 7118410
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions handler/compilation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
11 changes: 5 additions & 6 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{},
Expand Down
17 changes: 11 additions & 6 deletions handler/handler_compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion handler/handler_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion handler/handler_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 13 additions & 39 deletions handler/platforms.go
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -58,5 +32,5 @@ func getDefaultPlatforms() Platforms {
p[os] = map[string]bool{arch: def}
}
}
return p
return p, nil
}
11 changes: 9 additions & 2 deletions static/files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ <h2 class="ui header">Cloud Gox</h2>
<label>Version <span class="tip">Sets the <input type="text" class="ldflag" ng-model="package.versionVar"> ld-flag. Click to edit.</span></label>
<input type="text" placeholder="1.0.0" ng-model="package.version">
</div>
<div class="field" ng-show="showPlatforms">
<div class="field" ng-show="showMore">
<label>CGO</label>
<div class="ui checkbox">
<input type="checkbox" ng-model="package.cgo">
<label>Enabled by default</label>
</div>
</div>
<div class="field" ng-show="showMore">
<label>Platforms</label>
<div class="platforms">
<div ng-repeat="(osID, os) in package.platforms">
Expand All @@ -54,7 +61,7 @@ <h2 class="ui header">Cloud Gox</h2>
</div>
</div>
<div class="controls">
<div class="ui small button" ng-click="showPlatforms = !showPlatforms">{{ showPlatforms && 'Hide' || 'Show' }} Platforms</div>
<div class="ui small button" ng-click="showMore = !showMore">{{ showMore && 'Hide' || 'Show' }} more</div>
<button class="ui small primary button" type="submit" ng-disabled="loading || !Connected">Compile</button>
</div>
</form>
Expand Down
1 change: 1 addition & 0 deletions static/files/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ app.controller("AppController", function($scope, $http) {
commitVar: "COMMIT",
platforms: null,
commitish: "",
cgo: true
}

//pull server config
Expand Down

0 comments on commit 7118410

Please sign in to comment.