refactor: capture output by default
This is almost certainly the correct default for Dokku. While it's a BC break and might cause an increase in memory usage, the api is mostly internal and therefore this is safe to use.
This commit is contained in:
@@ -132,9 +132,8 @@ func CopyFromImage(appName string, image string, source string, destination stri
|
||||
|
||||
// add trailing newline for certain places where file parsing depends on it
|
||||
result, err := CallExecCommand(ExecCommandInput{
|
||||
Command: "tail",
|
||||
Args: []string{"-c1", destination},
|
||||
CaptureOutput: true,
|
||||
Command: "tail",
|
||||
Args: []string{"-c1", destination},
|
||||
})
|
||||
if err != nil || result.ExitCode != 0 {
|
||||
return fmt.Errorf("Unable to append trailing newline to copied file: %v", result.Stderr)
|
||||
@@ -243,9 +242,8 @@ func DockerContainerCreate(image string, containerCreateArgs []string) (string,
|
||||
// DockerInspect runs an inspect command with a given format against a container or image ID
|
||||
func DockerInspect(containerOrImageID, format string) (output string, err error) {
|
||||
result, err := CallExecCommand(ExecCommandInput{
|
||||
Command: DockerBin(),
|
||||
Args: []string{"inspect", "--format", format, containerOrImageID},
|
||||
CaptureOutput: true,
|
||||
Command: DockerBin(),
|
||||
Args: []string{"inspect", "--format", format, containerOrImageID},
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -272,9 +270,8 @@ func GetWorkingDir(appName string, image string) string {
|
||||
|
||||
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,
|
||||
Command: DockerBin(),
|
||||
Args: []string{"info", "--format", "{{range .ClientInfo.Plugins}}{{if eq .Name \"compose\"}}true{{end}}{{end}}')"},
|
||||
})
|
||||
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
|
||||
@@ -42,13 +42,13 @@ func CallPlugnTriggerWithContext(ctx context.Context, input PlugnTriggerInput) (
|
||||
args := []string{"trigger", input.Trigger}
|
||||
args = append(args, input.Args...)
|
||||
return CallExecCommandWithContext(ctx, ExecCommandInput{
|
||||
Command: "plugn",
|
||||
Args: args,
|
||||
CaptureOutput: input.CaptureOutput,
|
||||
Env: input.Env,
|
||||
Stdin: input.Stdin,
|
||||
StreamStdio: input.StreamStdio,
|
||||
StreamStdout: input.StreamStdout,
|
||||
StreamStderr: input.StreamStderr,
|
||||
Command: "plugn",
|
||||
Args: args,
|
||||
DisableStdioBuffer: input.DisableStdioBuffer,
|
||||
Env: input.Env,
|
||||
Stdin: input.Stdin,
|
||||
StreamStdio: input.StreamStdio,
|
||||
StreamStdout: input.StreamStdout,
|
||||
StreamStderr: input.StreamStderr,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user