start deploy cmd, move some functions to lib, add build info to cmd
This commit is contained in:
parent
22952bd21f
commit
a1c017545b
|
@ -1,2 +1,2 @@
|
|||
.*.swp
|
||||
warren
|
||||
/warren
|
||||
|
|
15
cmd_build.go
15
cmd_build.go
|
@ -2,10 +2,10 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dballard/warren/src/warren"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -31,20 +31,11 @@ func buildRun(cmd *Command, args ...string) {
|
|||
return
|
||||
}
|
||||
|
||||
githash, err := exec.Command("git", "rev-parse", "HEAD").Output()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
gitbranchb, err := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").Output()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
gitbranch := strings.TrimSpace(string(gitbranchb))
|
||||
date := time.Now().Format(time.RFC3339)
|
||||
gobuild := exec.Command("go", "build", "-ldflags", fmt.Sprintf("-X main.Build.Date %s -X main.Build.GitHash %s -X main.Build.GitBranch %s\"", date, githash, gitbranch))
|
||||
gobuild := exec.Command("go", "build", "-ldflags", fmt.Sprintf("-X main.Build.Date %s -X main.Build.GitHash %s -X main.Build.GitBranch %s\"", date, warren.GitHash(), warren.GitBranch()))
|
||||
gobuild.Stderr = os.Stderr
|
||||
gobuild.Stdout = os.Stdout
|
||||
err = gobuild.Run()
|
||||
err := gobuild.Run()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -16,9 +16,26 @@ var deployCmd = &Command{
|
|||
Run: deployRun,
|
||||
}
|
||||
|
||||
func checkDeployDir() {
|
||||
// does ./deploy exist?
|
||||
// if not make
|
||||
// does ./deploy/DST exist?
|
||||
// if not make
|
||||
}
|
||||
|
||||
func getDeployFilesList() []string {
|
||||
|
||||
return []string{""}
|
||||
}
|
||||
|
||||
func deployRun(cmd *Command, args ...string) {
|
||||
if len(args) > 0 && args[0] == "help" {
|
||||
fmt.Print(cmd.Help)
|
||||
return
|
||||
}
|
||||
|
||||
checkDeployDir()
|
||||
|
||||
//files := getDeployFilesList()
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package warren
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GitHash() string {
|
||||
hash, err := exec.Command("git", "rev-parse", "HEAD").Output()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return string(hash)
|
||||
}
|
||||
|
||||
func GitBranch() string {
|
||||
gitbranch, err := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").Output()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return strings.TrimSpace(string(gitbranch))
|
||||
}
|
|
@ -8,6 +8,14 @@ import (
|
|||
"text/template"
|
||||
)
|
||||
|
||||
type BuildInfo struct {
|
||||
GitHash string
|
||||
GitBranch string
|
||||
Date string
|
||||
}
|
||||
|
||||
var Build BuildInfo
|
||||
|
||||
var usagePrefix = `
|
||||
warren is a tool for building, deploying and running multiple versions of a Go server
|
||||
|
||||
|
@ -26,6 +34,7 @@ var commands = []*Command{
|
|||
}
|
||||
|
||||
func usage() {
|
||||
fmt.Println(Build.GitBranch, " ", Build.GitHash, " ", Build.Date)
|
||||
fmt.Print(usagePrefix)
|
||||
usageTmpl.Execute(os.Stdout, commands)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue