Merge pull request #6591 from dokku/6422-more-sh-cleanup
Always capture stdout/stderr when executing subprocesses
This commit is contained in:
29 files changed
+12
-79
No files matched your search
@@ -35,8 +35,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -52,8 +52,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -35,8 +35,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -40,8 +40,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -23,8 +23,7 @@ func ContainerRemove(containerID string) bool {
|
||||
result, err := CallExecCommand(ExecCommandInput{
|
||||
Command: DockerBin(),
|
||||
Args: []string{"container", "remove", "-f", containerID},
|
||||
CaptureOutput: false,
|
||||
StreamStdio: false,
|
||||
StreamStderr: true,
|
||||
})
|
||||
if err != nil {
|
||||
return false
|
||||
@@ -37,8 +36,6 @@ func ContainerExists(containerID string) bool {
|
||||
result, err := CallExecCommand(ExecCommandInput{
|
||||
Command: DockerBin(),
|
||||
Args: []string{"container", "inspect", containerID},
|
||||
CaptureOutput: false,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err != nil {
|
||||
return false
|
||||
@@ -137,8 +134,6 @@ func CopyFromImage(appName string, image string, source string, destination stri
|
||||
result, err := CallExecCommand(ExecCommandInput{
|
||||
Command: "tail",
|
||||
Args: []string{"-c1", destination},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err != nil || result.ExitCode != 0 {
|
||||
return fmt.Errorf("Unable to append trailing newline to copied file: %v", result.Stderr)
|
||||
@@ -249,8 +244,6 @@ func DockerInspect(containerOrImageID, format string) (output string, err error)
|
||||
result, err := CallExecCommand(ExecCommandInput{
|
||||
Command: DockerBin(),
|
||||
Args: []string{"inspect", "--format", format, containerOrImageID},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -279,7 +272,6 @@ func IsComposeInstalled() bool {
|
||||
result, err := CallExecCommand(ExecCommandInput{
|
||||
Command: DockerBin(),
|
||||
Args: []string{"info", "--format", "{{range .ClientInfo.Plugins}}{{if eq .Name \"compose\"}}true{{end}}{{end}}')"},
|
||||
CaptureOutput: true,
|
||||
})
|
||||
return err == nil && result.ExitCode == 0
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ type ExecCommandInput struct {
|
||||
// Args are the arguments to pass to the command
|
||||
Args []string
|
||||
|
||||
// CaptureOutput determines whether to capture the output of the command
|
||||
CaptureOutput bool
|
||||
// DisableStdioBuffer disables the stdio buffer
|
||||
DisableStdioBuffer bool
|
||||
|
||||
// Env is the environment variables to pass to the command
|
||||
Env map[string]string
|
||||
@@ -95,7 +95,7 @@ func CallExecCommandWithContext(ctx context.Context, input ExecCommandInput) (Ex
|
||||
// being captured, then color output can be forced.
|
||||
isatty := !color.NoColor
|
||||
env := os.Environ()
|
||||
if isatty && !input.CaptureOutput {
|
||||
if isatty && input.DisableStdioBuffer {
|
||||
env = append(env, "FORCE_TTY=1")
|
||||
}
|
||||
if input.Env != nil {
|
||||
@@ -115,7 +115,7 @@ func CallExecCommandWithContext(ctx context.Context, input ExecCommandInput) (Ex
|
||||
Command: command,
|
||||
Args: commandArgs,
|
||||
Env: env,
|
||||
DisableStdioBuffer: !input.CaptureOutput,
|
||||
DisableStdioBuffer: input.DisableStdioBuffer,
|
||||
}
|
||||
|
||||
if os.Getenv("DOKKU_TRACE") == "1" {
|
||||
|
||||
@@ -10,8 +10,8 @@ type PlugnTriggerInput struct {
|
||||
// Args are the arguments to pass to the trigger
|
||||
Args []string
|
||||
|
||||
// CaptureOutput determines whether to capture the output of the trigger
|
||||
CaptureOutput bool
|
||||
// DisableStdioBuffer disables the stdio buffer
|
||||
DisableStdioBuffer bool
|
||||
|
||||
// Env is the environment variables to pass to the trigger
|
||||
Env map[string]string
|
||||
@@ -44,7 +44,7 @@ func CallPlugnTriggerWithContext(ctx context.Context, input PlugnTriggerInput) (
|
||||
return CallExecCommandWithContext(ctx, ExecCommandInput{
|
||||
Command: "plugn",
|
||||
Args: args,
|
||||
CaptureOutput: input.CaptureOutput,
|
||||
DisableStdioBuffer: input.DisableStdioBuffer,
|
||||
Env: input.Env,
|
||||
Stdin: input.Stdin,
|
||||
StreamStdio: input.StreamStdio,
|
||||
|
||||
@@ -31,8 +31,8 @@ type SshCommandInput struct {
|
||||
// Args are the arguments to pass to the command.
|
||||
Args []string
|
||||
|
||||
// CaptureOutput saves any output from in the TaskResult
|
||||
CaptureOutput bool
|
||||
// DisableStdioBuffer disables the stdio buffer
|
||||
DisableStdioBuffer bool
|
||||
|
||||
// Env is a list of environment variables to add to the current environment
|
||||
Env map[string]string
|
||||
@@ -137,7 +137,7 @@ func CallSshCommandWithContext(ctx context.Context, input SshCommandInput) (SshR
|
||||
Command: input.Command,
|
||||
Args: input.Args,
|
||||
Env: env,
|
||||
DisableStdioBuffer: !input.CaptureOutput,
|
||||
DisableStdioBuffer: input.DisableStdioBuffer,
|
||||
AllowUknownHosts: input.AllowUknownHosts,
|
||||
Hostname: u.Hostname(),
|
||||
Port: uint(port),
|
||||
|
||||
@@ -56,8 +56,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -36,8 +36,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -39,7 +39,6 @@ const vectorOldContainerName = "vector"
|
||||
func getComposeFile() ([]byte, error) {
|
||||
result, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "vector-template-source",
|
||||
CaptureOutput: true,
|
||||
})
|
||||
if err == nil && result.ExitCode == 0 && strings.TrimSpace(result.Stdout) != "" {
|
||||
contents, err := os.ReadFile(strings.TrimSpace(result.Stdout))
|
||||
|
||||
@@ -62,8 +62,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -48,8 +48,6 @@ func TriggerDockerArgsProcessDeploy(appName string) error {
|
||||
result, _ := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: common.DockerBin(),
|
||||
Args: []string{"system", "info", "--format", "{{ .LoggingDriver }}"},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
|
||||
if !allowedDrivers[result.StdoutContents()] {
|
||||
|
||||
@@ -61,8 +61,6 @@ func isContainerInNetwork(containerID string, networkName string) bool {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: common.DockerBin(),
|
||||
Args: []string{"container", "inspect", "--format", "{{range $net, $v := .NetworkSettings.Networks}}{{println $net}}{{end}}", containerID},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -132,8 +130,6 @@ func listNetworks() ([]string, error) {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: common.DockerBin(),
|
||||
Args: []string{"network", "ls", "--format", "{{ .Name }}"},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err != nil {
|
||||
common.LogVerboseQuiet(result.StderrContents())
|
||||
|
||||
@@ -42,8 +42,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -39,8 +39,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -39,8 +39,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -42,8 +42,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -105,8 +105,6 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "procfile-util",
|
||||
Args: []string{"check", "-P", processSpecificProcfile},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf(result.StderrContents())
|
||||
|
||||
@@ -126,7 +126,6 @@ func dockerTag(imageID string, imageTag string) bool {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: common.DockerBin(),
|
||||
Args: []string{"image", "tag", imageID, imageTag},
|
||||
CaptureOutput: false,
|
||||
StreamStdio: true,
|
||||
})
|
||||
return err == nil && result.ExitCode == 0
|
||||
@@ -136,7 +135,6 @@ func dockerPush(imageTag string) bool {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: common.DockerBin(),
|
||||
Args: []string{"image", "push", imageTag},
|
||||
CaptureOutput: false,
|
||||
StreamStdio: true,
|
||||
})
|
||||
return err == nil && result.ExitCode == 0
|
||||
|
||||
@@ -36,8 +36,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -57,7 +57,6 @@ func CommandLogin(server string, username string, password string, passwordStdin
|
||||
Trigger: "post-registry-login",
|
||||
Args: []string{server, username},
|
||||
StreamStdio: true,
|
||||
CaptureOutput: false,
|
||||
Env: map[string]string{
|
||||
"DOCKER_REGISTRY_PASS": password,
|
||||
},
|
||||
|
||||
@@ -35,8 +35,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -38,8 +38,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -337,8 +337,6 @@ func extractStartCommand(input StartCommandInput) string {
|
||||
resp, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-get",
|
||||
Args: []string{input.AppName, "DOKKU_START_CMD"},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && resp.ExitCode == 0 && len(resp.Stdout) > 0 {
|
||||
command = strings.TrimSpace(resp.Stdout)
|
||||
@@ -348,8 +346,6 @@ func extractStartCommand(input StartCommandInput) string {
|
||||
resp, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-get",
|
||||
Args: []string{input.AppName, "DOKKU_DOCKERFILE_START_CMD"},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && resp.ExitCode == 0 && len(resp.Stdout) > 0 {
|
||||
command = strings.TrimSpace(resp.Stdout)
|
||||
|
||||
@@ -45,8 +45,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
@@ -356,10 +356,7 @@ func CommandClusterAdd(role string, remoteHost string, serverIP string, allowUkn
|
||||
|
||||
k3sVersionCmd, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "k3s",
|
||||
Args: []string{
|
||||
"--version",
|
||||
},
|
||||
CaptureOutput: true,
|
||||
Args: []string{"--version"},
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to call k3s version command: %w", err)
|
||||
|
||||
@@ -532,7 +532,6 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
||||
common.LogInfo1("Running post-deploy")
|
||||
_, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Args: []string{appName, "", "", imageTag},
|
||||
CaptureOutput: false,
|
||||
StreamStdio: true,
|
||||
Trigger: "core-post-deploy",
|
||||
})
|
||||
@@ -542,7 +541,6 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
||||
}
|
||||
_, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Args: []string{appName, "", "", imageTag},
|
||||
CaptureOutput: false,
|
||||
StreamStdio: true,
|
||||
Trigger: "post-deploy",
|
||||
})
|
||||
@@ -805,15 +803,11 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args []
|
||||
resp, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-get",
|
||||
Args: []string{appName, "DOKKU_RM_CONTAINER"},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err != nil {
|
||||
resp, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "config-get-global",
|
||||
Args: []string{"DOKKU_RM_CONTAINER"},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil {
|
||||
dokkuRmContainer = strings.TrimSpace(resp.Stdout)
|
||||
@@ -864,8 +858,6 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args []
|
||||
resp, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "procfile-get-command",
|
||||
Args: []string{appName, args[0], "5000"},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && resp.Stdout != "" {
|
||||
common.LogInfo1Quiet(fmt.Sprintf("Found '%s' in Procfile, running that command", args[0]))
|
||||
|
||||
@@ -35,8 +35,6 @@ func main() {
|
||||
result, err := common.CallExecCommand(common.ExecCommandInput{
|
||||
Command: "ps",
|
||||
Args: []string{"-o", "command=", strconv.Itoa(os.Getppid())},
|
||||
CaptureOutput: true,
|
||||
StreamStdio: false,
|
||||
})
|
||||
if err == nil && strings.Contains(result.StdoutContents(), "--all") {
|
||||
fmt.Println(helpContent)
|
||||
|
||||
Reference in new issue
Block a user