2014-12-10 07:04:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-12-13 07:54:02 +00:00
|
|
|
"github.com/dballard/warren/lib/warren"
|
2014-12-12 07:13:55 +00:00
|
|
|
"os"
|
2014-12-13 07:54:02 +00:00
|
|
|
"os/exec"
|
2014-12-10 07:04:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var deployUsage = `
|
|
|
|
warren deploy - Deploys the go server and support files
|
|
|
|
`
|
|
|
|
|
|
|
|
var deployCmd = &Command{
|
|
|
|
Name: "deploy",
|
|
|
|
Usage: "",
|
|
|
|
Summary: "deploy the go server and support files",
|
|
|
|
Help: deployUsage,
|
|
|
|
Run: deployRun,
|
|
|
|
}
|
|
|
|
|
2014-12-13 07:54:02 +00:00
|
|
|
func checkDeployDir() string {
|
2014-12-12 07:13:55 +00:00
|
|
|
_, err := os.Stat("deploy")
|
|
|
|
if err != nil {
|
2014-12-13 07:54:02 +00:00
|
|
|
os.Mkdir("deploy", os.ModeDir|0777)
|
2014-12-12 07:13:55 +00:00
|
|
|
}
|
2014-12-13 07:54:02 +00:00
|
|
|
|
|
|
|
githash := warren.GitHash()
|
|
|
|
dst := "deploy/" + githash + "/"
|
|
|
|
_, err = os.Stat(dst)
|
|
|
|
if err != nil {
|
|
|
|
os.Mkdir(dst, os.ModeDir|0777)
|
|
|
|
}
|
|
|
|
return dst
|
2014-12-10 16:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getDeployFilesList() []string {
|
2014-12-12 07:13:55 +00:00
|
|
|
name := warren.AppName()
|
|
|
|
return []string{name}
|
2014-12-10 16:12:46 +00:00
|
|
|
}
|
|
|
|
|
2014-12-13 07:54:02 +00:00
|
|
|
func cp(dst, src string) error {
|
|
|
|
return exec.Command("cp", src, dst, "-r").Run()
|
|
|
|
}
|
|
|
|
|
2014-12-10 07:04:49 +00:00
|
|
|
func deployRun(cmd *Command, args ...string) {
|
|
|
|
if len(args) > 0 && args[0] == "help" {
|
|
|
|
fmt.Print(cmd.Help)
|
|
|
|
return
|
|
|
|
}
|
2014-12-13 07:54:02 +00:00
|
|
|
dst := checkDeployDir()
|
|
|
|
fmt.Println(dst)
|
2014-12-12 07:13:55 +00:00
|
|
|
files := getDeployFilesList()
|
2014-12-10 16:12:46 +00:00
|
|
|
|
2014-12-12 07:13:55 +00:00
|
|
|
fmt.Println(files)
|
2014-12-13 07:54:02 +00:00
|
|
|
for _, file := range files {
|
|
|
|
cp(dst+file, file)
|
|
|
|
}
|
2014-12-10 07:04:49 +00:00
|
|
|
}
|