rename DokkuCmd to ShellCmd and use strings.Join instead of fmt.Sprintf
This commit is contained in:
@@ -10,8 +10,8 @@ import (
|
|||||||
sh "github.com/codeskyblue/go-sh"
|
sh "github.com/codeskyblue/go-sh"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DokkuCmd represents a shell command to be run for dokku
|
// ShellCmd represents a shell command to be run for dokku
|
||||||
type DokkuCmd struct {
|
type ShellCmd struct {
|
||||||
Env map[string]string
|
Env map[string]string
|
||||||
Command *exec.Cmd
|
Command *exec.Cmd
|
||||||
CommandString string
|
CommandString string
|
||||||
@@ -19,12 +19,12 @@ type DokkuCmd struct {
|
|||||||
ShowOutput bool
|
ShowOutput bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDokkuCmd creates a new DokkuCmd
|
// NewShellCmd returns a new ShellCmd struct
|
||||||
func NewDokkuCmd(command string) *DokkuCmd {
|
func NewShellCmd(command string) *ShellCmd {
|
||||||
items := strings.Split(command, " ")
|
items := strings.Split(command, " ")
|
||||||
cmd := items[0]
|
cmd := items[0]
|
||||||
args := items[1:]
|
args := items[1:]
|
||||||
return &DokkuCmd{
|
return &ShellCmd{
|
||||||
Command: exec.Command(cmd, args...),
|
Command: exec.Command(cmd, args...),
|
||||||
CommandString: command,
|
CommandString: command,
|
||||||
Args: args,
|
Args: args,
|
||||||
@@ -33,7 +33,7 @@ func NewDokkuCmd(command string) *DokkuCmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute is a lightweight wrapper around exec.Command
|
// Execute is a lightweight wrapper around exec.Command
|
||||||
func (dc *DokkuCmd) Execute() bool {
|
func (dc *ShellCmd) Execute() bool {
|
||||||
env := os.Environ()
|
env := os.Environ()
|
||||||
for k, v := range dc.Env {
|
for k, v := range dc.Env {
|
||||||
env = append(env, fmt.Sprintf("%s=%s", k, v))
|
env = append(env, fmt.Sprintf("%s=%s", k, v))
|
||||||
@@ -132,7 +132,7 @@ func GetAppImageRepo(appName string) string {
|
|||||||
|
|
||||||
// VerifyImage returns true if docker image exists in local repo
|
// VerifyImage returns true if docker image exists in local repo
|
||||||
func VerifyImage(image string) bool {
|
func VerifyImage(image string) bool {
|
||||||
imageCmd := NewDokkuCmd(fmt.Sprintf("docker inspect %s", image))
|
imageCmd := NewShellCmd(strings.Join([]string{"docker inspect", image}, " "))
|
||||||
imageCmd.ShowOutput = false
|
imageCmd.ShowOutput = false
|
||||||
if imageCmd.Execute() {
|
if imageCmd.Execute() {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func main() {
|
|||||||
cmdEnv := map[string]string{
|
cmdEnv := map[string]string{
|
||||||
"GIT_DIR": appRoot,
|
"GIT_DIR": appRoot,
|
||||||
}
|
}
|
||||||
gitGcCmd := common.NewDokkuCmd("git gc --aggressive")
|
gitGcCmd := common.NewShellCmd("git gc --aggressive")
|
||||||
gitGcCmd.Env = cmdEnv
|
gitGcCmd.Env = cmdEnv
|
||||||
gitGcCmd.Execute()
|
gitGcCmd.Execute()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func main() {
|
|||||||
dokkuGlobalRunArgs := common.MustGetEnv("DOKKU_GLOBAL_RUN_ARGS")
|
dokkuGlobalRunArgs := common.MustGetEnv("DOKKU_GLOBAL_RUN_ARGS")
|
||||||
image := common.GetDeployingAppImageName(appName, "", "")
|
image := common.GetDeployingAppImageName(appName, "", "")
|
||||||
if info, _ := os.Stat(cacheDir); info != nil && info.IsDir() {
|
if info, _ := os.Stat(cacheDir); info != nil && info.IsDir() {
|
||||||
purgeCacheCmd := common.NewDokkuCmd(strings.Join([]string{"docker run --rm", dokkuGlobalRunArgs,
|
purgeCacheCmd := common.NewShellCmd(strings.Join([]string{"docker run --rm", dokkuGlobalRunArgs,
|
||||||
"-v", strings.Join([]string{cacheDir, ":/cache"}, ""), image,
|
"-v", strings.Join([]string{cacheDir, ":/cache"}, ""), image,
|
||||||
`find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} ;`}, " "))
|
`find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} ;`}, " "))
|
||||||
purgeCacheCmd.Execute()
|
purgeCacheCmd.Execute()
|
||||||
|
|||||||
Reference in New Issue
Block a user