start deploy cmd, move some functions to lib, add build info to cmd

This commit is contained in:
Dan Ballard 2014-12-10 08:12:46 -08:00
parent 22952bd21f
commit a1c017545b
5 changed files with 53 additions and 13 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
.*.swp
warren
/warren

View File

@ -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)
}

View File

@ -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()
}

23
src/warren/warren.go Normal file
View File

@ -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))
}

View File

@ -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)
}