diff --git a/plugins/common/common.go b/plugins/common/common.go index cd77dcf20..ab3488532 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -10,8 +10,8 @@ import ( sh "github.com/codeskyblue/go-sh" ) -// DokkuCmd represents a shell command to be run for dokku -type DokkuCmd struct { +// ShellCmd represents a shell command to be run for dokku +type ShellCmd struct { Env map[string]string Command *exec.Cmd CommandString string @@ -19,12 +19,12 @@ type DokkuCmd struct { ShowOutput bool } -// NewDokkuCmd creates a new DokkuCmd -func NewDokkuCmd(command string) *DokkuCmd { +// NewShellCmd returns a new ShellCmd struct +func NewShellCmd(command string) *ShellCmd { items := strings.Split(command, " ") cmd := items[0] args := items[1:] - return &DokkuCmd{ + return &ShellCmd{ Command: exec.Command(cmd, args...), CommandString: command, Args: args, @@ -33,7 +33,7 @@ func NewDokkuCmd(command string) *DokkuCmd { } // Execute is a lightweight wrapper around exec.Command -func (dc *DokkuCmd) Execute() bool { +func (dc *ShellCmd) Execute() bool { env := os.Environ() for k, v := range dc.Env { 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 func VerifyImage(image string) bool { - imageCmd := NewDokkuCmd(fmt.Sprintf("docker inspect %s", image)) + imageCmd := NewShellCmd(strings.Join([]string{"docker inspect", image}, " ")) imageCmd.ShowOutput = false if imageCmd.Execute() { return true diff --git a/plugins/repo/src/subcommands/gc/gc.go b/plugins/repo/src/subcommands/gc/gc.go index 873ed3e85..7787385b8 100644 --- a/plugins/repo/src/subcommands/gc/gc.go +++ b/plugins/repo/src/subcommands/gc/gc.go @@ -23,7 +23,7 @@ func main() { cmdEnv := map[string]string{ "GIT_DIR": appRoot, } - gitGcCmd := common.NewDokkuCmd("git gc --aggressive") + gitGcCmd := common.NewShellCmd("git gc --aggressive") gitGcCmd.Env = cmdEnv gitGcCmd.Execute() } diff --git a/plugins/repo/src/subcommands/purge-cache/purge-cache.go b/plugins/repo/src/subcommands/purge-cache/purge-cache.go index b4d4eb8b0..863d4d46c 100644 --- a/plugins/repo/src/subcommands/purge-cache/purge-cache.go +++ b/plugins/repo/src/subcommands/purge-cache/purge-cache.go @@ -24,7 +24,7 @@ func main() { dokkuGlobalRunArgs := common.MustGetEnv("DOKKU_GLOBAL_RUN_ARGS") image := common.GetDeployingAppImageName(appName, "", "") 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, `find /cache -depth -mindepth 1 -maxdepth 1 -exec rm -Rf {} ;`}, " ")) purgeCacheCmd.Execute()