refactor: remove all calls to common.NewShellCmd

At this point, the only usage of go-sh should be by plugin trigger calls.
This commit is contained in:
Jose Diaz-Gonzalez
2024-02-13 01:09:24 -05:00
parent 24b32432e6
commit 44dd933638
10 changed files with 207 additions and 234 deletions

View File

@@ -2,8 +2,6 @@ package repo
import (
"fmt"
"os"
"strings"
"github.com/dokku/dokku/plugins/common"
)
@@ -33,18 +31,16 @@ func PurgeCache(appName string) error {
if len(containerIDs) > 0 {
common.DockerRemoveContainers(containerIDs)
}
purgeCacheCmd := common.NewShellCmd(strings.Join([]string{
common.DockerBin(),
"volume",
"rm", "-f", fmt.Sprintf("cache-%s", appName)}, " "))
purgeCacheCmd.ShowOutput = false
purgeCacheCmd.Command.Stderr = os.Stderr
if !purgeCacheCmd.Execute() {
exitCode := 1
if purgeCacheCmd.ExitError != nil {
exitCode = purgeCacheCmd.ExitError.ExitCode()
}
return &PurgeCacheFailed{exitCode}
result, err := common.CallExecCommand(common.ExecCommandInput{
Command: common.DockerBin(),
Args: []string{"volume", "rm", "-f", fmt.Sprintf("cache-%s", appName)},
StreamStderr: true,
})
if err != nil {
return fmt.Errorf("Unable to remove cache volume: %w", err)
}
if result.ExitCode != 0 {
return &PurgeCacheFailed{result.ExitCode}
}
return nil

View File

@@ -1,6 +1,8 @@
package repo
import (
"fmt"
"github.com/dokku/dokku/plugins/common"
)
@@ -14,9 +16,20 @@ func CommandGc(appName string) error {
cmdEnv := map[string]string{
"GIT_DIR": appRoot,
}
gitGcCmd := common.NewShellCmd("git gc --aggressive")
gitGcCmd.Env = cmdEnv
gitGcCmd.Execute()
result, err := common.CallExecCommand(common.ExecCommandInput{
Command: "git",
Args: []string{"gc", "--aggressive"},
Env: cmdEnv,
StreamStdio: true,
})
if err != nil {
return fmt.Errorf("Unable to run git gc: %w", err)
}
if result.ExitCode != 0 {
return fmt.Errorf("Unable to run git gc: %s", result.StderrContents())
}
return nil
}