warren/cmd/warren/cmd_deploy.go

59 lines
1.0 KiB
Go

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