diff --git a/plugins/app-json/functions.go b/plugins/app-json/functions.go index fe24ca885b3..2b3cc33af42 100644 --- a/plugins/app-json/functions.go +++ b/plugins/app-json/functions.go @@ -102,8 +102,11 @@ func getPhaseScript(appName string, phase string) (string, error) { func getReleaseCommand(appName string, image string) string { processType := "release" port := "5000" - b, _ := common.PlugnTriggerOutput("procfile-get-command", []string{appName, processType, port}...) - return strings.TrimSpace(string(b[:])) + results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "procfile-get-command", + Args: []string{appName, processType, port}, + }) + return results.StdoutContents() } func getDokkuAppShell(appName string) string { @@ -114,13 +117,19 @@ func getDokkuAppShell(appName string) string { ctx := context.Background() errs, ctx := errgroup.WithContext(ctx) errs.Go(func() error { - b, _ := common.PlugnTriggerOutput("config-get-global", []string{"DOKKU_APP_SHELL"}...) - globalShell = strings.TrimSpace(string(b[:])) + results, _ := common.CallPlugnTriggerWithContext(ctx, common.PlugnTriggerInput{ + Trigger: "config-get-global", + Args: []string{"DOKKU_APP_SHELL"}, + }) + globalShell = results.StdoutContents() return nil }) errs.Go(func() error { - b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_APP_SHELL"}...) - appShell = strings.TrimSpace(string(b[:])) + results, _ := common.CallPlugnTriggerWithContext(ctx, common.PlugnTriggerInput{ + Trigger: "config-get", + Args: []string{appName, "DOKKU_APP_SHELL"}, + }) + appShell = results.StdoutContents() return nil }) @@ -398,12 +407,15 @@ func createdContainerID(appName string, dockerArgs []string, image string, comma arguments = append(arguments, image) arguments = append(arguments, command...) - b, err := common.PlugnTriggerOutput("config-export", []string{appName, "false", "true", "json"}...) + results, err := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "config-export", + Args: []string{appName, "false", "true", "json"}, + }) if err != nil { return "", err } var env map[string]string - if err := json.Unmarshal(b, &env); err != nil { + if err := json.Unmarshal(results.StdoutBytes(), &env); err != nil { return "", err } diff --git a/plugins/app-json/triggers.go b/plugins/app-json/triggers.go index 72fd1ccaba7..b556c0d49ff 100644 --- a/plugins/app-json/triggers.go +++ b/plugins/app-json/triggers.go @@ -101,11 +101,17 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error { } processSpecificAppJSON := fmt.Sprintf("%s.%s", existingAppJSON, os.Getenv("DOKKU_PID")) - b, _ := common.PlugnTriggerOutput("git-get-property", []string{appName, "source-image"}...) - appSourceImage := strings.TrimSpace(string(b[:])) - - b, _ = common.PlugnTriggerOutput("builder-get-property", []string{appName, "build-dir"}...) - buildDir := strings.TrimSpace(string(b[:])) + results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "git-get-property", + Args: []string{appName, "source-image"}, + }) + appSourceImage := results.StdoutContents() + + results, _ = common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "builder-get-property", + Args: []string{appName, "build-dir"}, + }) + buildDir := results.StdoutContents() repoDefaultAppJSONPath := path.Join(sourceWorkDir, "app.json") if appSourceImage == "" { diff --git a/plugins/apps/functions.go b/plugins/apps/functions.go index 3c42cd3d5ca..3f9af955996 100644 --- a/plugins/apps/functions.go +++ b/plugins/apps/functions.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "os" - "strings" "time" "github.com/dokku/dokku/plugins/common" @@ -105,8 +104,11 @@ func maybeCreateApp(appName string) error { return nil } - b, _ := common.PlugnTriggerOutput("config-get-global", []string{"DOKKU_DISABLE_APP_AUTOCREATION"}...) - disableAutocreate := strings.TrimSpace(string(b[:])) + results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "config-get-global", + Args: []string{"DOKKU_DISABLE_APP_AUTOCREATION"}, + }) + disableAutocreate := results.StdoutContents() if disableAutocreate == "true" { common.LogWarn("App auto-creation disabled.") return fmt.Errorf("Re-enable app auto-creation or create an app with 'dokku apps:create %s'", appName) diff --git a/plugins/buildpacks/report.go b/plugins/buildpacks/report.go index 68b95aa0110..cec28af2a5c 100644 --- a/plugins/buildpacks/report.go +++ b/plugins/buildpacks/report.go @@ -40,8 +40,11 @@ func reportComputedStack(appName string) string { return stack } - b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_IMAGE"}...) - if dokkuImage := strings.TrimSpace(string(b[:])); dokkuImage != "" { + results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "config-get", + Args: []string{appName, "DOKKU_IMAGE"}, + }) + if dokkuImage := results.StdoutContents(); dokkuImage != "" { common.LogWarn("Deprecated: use buildpacks:set-property instead of specifying DOKKU_IMAGE environment variable") return dokkuImage } diff --git a/plugins/buildpacks/triggers.go b/plugins/buildpacks/triggers.go index 187a0f8e156..37f1c33d755 100644 --- a/plugins/buildpacks/triggers.go +++ b/plugins/buildpacks/triggers.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "path/filepath" - "strings" "github.com/dokku/dokku/plugins/common" ) @@ -22,8 +21,11 @@ func TriggerBuildpackStackName(appName string) error { return nil } - b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_IMAGE"}...) - dokkuImage := strings.TrimSpace(string(b[:])) + results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "config-get", + Args: []string{appName, "DOKKU_IMAGE"}, + }) + dokkuImage := results.StdoutContents() if dokkuImage != "" { common.LogWarn("Deprecated: use buildpacks:set-property instead of specifying DOKKU_IMAGE environment variable") fmt.Println(dokkuImage) diff --git a/plugins/common/common.go b/plugins/common/common.go index e0ffb613ea7..23e96c0f8d9 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -124,8 +124,11 @@ func GetAppScheduler(appName string) string { } func getAppScheduler(appName string) string { - b, _ := PlugnTriggerOutput("scheduler-detect", []string{appName}...) - value := strings.TrimSpace(string(b[:])) + results, _ := CallPlugnTrigger(PlugnTriggerInput{ + Trigger: "scheduler-detect", + Args: []string{appName}, + }) + value := results.StdoutContents() if value != "" { return value } @@ -134,8 +137,11 @@ func getAppScheduler(appName string) string { // GetGlobalScheduler fetchs the global scheduler func GetGlobalScheduler() string { - b, _ := PlugnTriggerOutput("scheduler-detect", []string{"--global"}...) - value := strings.TrimSpace(string(b[:])) + results, _ := CallPlugnTrigger(PlugnTriggerInput{ + Trigger: "scheduler-detect", + Args: []string{"--global"}, + }) + value := results.StdoutContents() if value != "" { return value } @@ -152,24 +158,34 @@ func GetDeployingAppImageName(appName, imageTag, imageRepo string) (string, erro ctx := context.Background() errs, ctx := errgroup.WithContext(ctx) errs.Go(func() error { - b, err := PlugnTriggerOutput("deployed-app-repository", []string{appName}...) + results, err := CallPlugnTrigger(PlugnTriggerInput{ + Trigger: "deployed-app-repository", + Args: []string{appName}, + }) if err == nil { - imageRemoteRepository = strings.TrimSpace(string(b[:])) + imageRemoteRepository = results.StdoutContents() } return err }) errs.Go(func() error { - b, err := PlugnTriggerOutput("deployed-app-image-tag", []string{appName}...) + results, err := CallPlugnTrigger(PlugnTriggerInput{ + Trigger: "deployed-app-image-tag", + Args: []string{appName}, + }) + if err == nil { - newImageTag = strings.TrimSpace(string(b[:])) + newImageTag = results.StdoutContents() } return err }) errs.Go(func() error { - b, err := PlugnTriggerOutput("deployed-app-image-repo", []string{appName}...) + results, err := CallPlugnTrigger(PlugnTriggerInput{ + Trigger: "deployed-app-image-repo", + Args: []string{appName}, + }) if err == nil { - newImageRepo = strings.TrimSpace(string(b[:])) + newImageRepo = results.StdoutContents() } return err }) @@ -251,11 +267,14 @@ func GetAppRunningContainerIDs(appName string, containerType string) ([]string, // GetRunningImageTag retrieves current deployed image tag for a given app func GetRunningImageTag(appName string, imageTag string) (string, error) { - b, err := PlugnTriggerOutput("deployed-app-image-tag", []string{appName}...) + results, err := CallPlugnTrigger(PlugnTriggerInput{ + Trigger: "deployed-app-image-tag", + Args: []string{appName}, + }) if err != nil { return imageTag, err } - newImageTag := strings.TrimSpace(string(b[:])) + newImageTag := results.StdoutContents() if newImageTag != "" { imageTag = newImageTag } @@ -326,7 +345,10 @@ func IsDeployed(appName string) bool { if deployed == "" { deployed = "false" scheduler := GetAppScheduler(appName) - _, err := PlugnTriggerOutput("scheduler-is-deployed", []string{scheduler, appName}...) + _, err := CallPlugnTrigger(PlugnTriggerInput{ + Trigger: "scheduler-is-deployed", + Args: []string{scheduler, appName}, + }) if err == nil { deployed = "true" } diff --git a/plugins/common/docker.go b/plugins/common/docker.go index 3ee17915f89..e99fca6803b 100644 --- a/plugins/common/docker.go +++ b/plugins/common/docker.go @@ -182,9 +182,11 @@ func DockerCleanup(appName string, forceCleanup bool) error { triggerArgs = []string{"DOKKU_SKIP_CLEANUP"} } - b, _ := PlugnTriggerOutput(triggerName, triggerArgs...) - output := strings.TrimSpace(string(b[:])) - if output == "true" { + results, _ := CallPlugnTrigger(PlugnTriggerInput{ + Trigger: triggerName, + Args: triggerArgs, + }) + if results.StdoutContents() == "true" { skipCleanup = true } } @@ -309,9 +311,12 @@ func IsImageHerokuishBased(image string, appName string) bool { dokkuAppUser := "" if len(appName) != 0 { - b, err := PlugnTriggerOutput("config-get", []string{appName, "DOKKU_APP_USER"}...) + results, err := CallPlugnTrigger(PlugnTriggerInput{ + Trigger: "config-get", + Args: []string{appName, "DOKKU_APP_USER"}, + }) if err == nil { - dokkuAppUser = strings.TrimSpace(string(b)) + dokkuAppUser = results.StdoutContents() } } diff --git a/plugins/common/exec.go b/plugins/common/exec.go index 84eaa895410..c8471cc6fb0 100644 --- a/plugins/common/exec.go +++ b/plugins/common/exec.go @@ -77,6 +77,16 @@ func (ecr ExecCommandResponse) StderrContents() string { return strings.TrimSpace(ecr.Stderr) } +// StderrBytes returns the trimmed stderr of the command as bytes +func (ecr ExecCommandResponse) StderrBytes() []byte { + return []byte(ecr.StderrContents()) +} + +// StdoutBytes returns the trimmed stdout of the command as bytes +func (ecr ExecCommandResponse) StdoutBytes() []byte { + return []byte(ecr.StdoutContents()) +} + // CallExecCommand executes a command on the local host func CallExecCommand(input ExecCommandInput) (ExecCommandResponse, error) { ctx := context.Background() diff --git a/plugins/common/functions.go b/plugins/common/functions.go index 185ddd9f5da..0ae83bb9e97 100644 --- a/plugins/common/functions.go +++ b/plugins/common/functions.go @@ -25,8 +25,11 @@ func filterApps(apps []string) ([]string, error) { } args := append([]string{sshUser, sshName}, apps...) - b, _ := PlugnTriggerOutput("user-auth-app", args...) - filteredApps := strings.Split(strings.TrimSpace(string(b[:])), "\n") + results, _ := CallPlugnTrigger(PlugnTriggerInput{ + Trigger: "user-auth-app", + Args: args, + }) + filteredApps := strings.Split(results.StdoutContents(), "\n") filteredApps = removeEmptyEntries(filteredApps) if len(filteredApps) == 0 { diff --git a/plugins/network/network.go b/plugins/network/network.go index f8bf2d1dcb5..4c0254e6121 100644 --- a/plugins/network/network.go +++ b/plugins/network/network.go @@ -43,12 +43,15 @@ func BuildConfig(appName string) error { } appRoot := common.AppRoot(appName) - s, err := common.PlugnTriggerOutput("ps-current-scale", []string{appName}...) + results, err := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "ps-current-scale", + Args: []string{appName}, + }) if err != nil { return err } - scale, err := common.ParseScaleOutput(s) + scale, err := common.ParseScaleOutput(results.StdoutBytes()) if err != nil { return err } @@ -78,7 +81,10 @@ func BuildConfig(appName string) error { ipAddress := GetContainerIpaddress(appName, processType, containerID) if ipAddress != "" { args := []string{appName, processType, containerIndexString, ipAddress} - _, err := common.PlugnTriggerOutput("network-write-ipaddr", args...) + _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "network-write-ipaddr", + Args: args, + }) if err != nil { common.LogWarn(err.Error()) } diff --git a/plugins/ps/functions.go b/plugins/ps/functions.go index c77475c0f77..de6d9aa8634 100644 --- a/plugins/ps/functions.go +++ b/plugins/ps/functions.go @@ -69,15 +69,21 @@ func getRestartPolicy(appName string) (string, error) { func getProcessCount(appName string) (int, error) { scheduler := common.GetAppScheduler(appName) - b, _ := common.PlugnTriggerOutput("scheduler-app-status", []string{scheduler, appName}...) - count := strings.Split(strings.TrimSpace(string(b[:])), " ")[0] + results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "scheduler-app-status", + Args: []string{scheduler, appName}, + }) + count := strings.Split(results.StdoutContents(), " ")[0] return strconv.Atoi(count) } func getRunningState(appName string) string { scheduler := common.GetAppScheduler(appName) - b, _ := common.PlugnTriggerOutput("scheduler-app-status", []string{scheduler, appName}...) - return strings.Split(strings.TrimSpace(string(b[:])), " ")[1] + results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "scheduler-app-status", + Args: []string{scheduler, appName}, + }) + return strings.Split(results.StdoutContents(), " ")[1] } func hasProcfile(appName string) bool { diff --git a/plugins/ps/ps.go b/plugins/ps/ps.go index 75e6f3c931a..a0b937e832f 100644 --- a/plugins/ps/ps.go +++ b/plugins/ps/ps.go @@ -2,7 +2,6 @@ package ps import ( "fmt" - "strings" "github.com/dokku/dokku/plugins/common" ) @@ -129,8 +128,11 @@ func Restore(appName string) error { return nil } - b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_APP_RESTORE"}...) - restore := strings.TrimSpace(string(b[:])) + results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "config-get", + Args: []string{appName, "DOKKU_APP_RESTORE"}, + }) + restore := results.StdoutContents() if restore == "0" { common.LogWarn(fmt.Sprintf("Skipping ps:restore for %s as DOKKU_APP_RESTORE=%s", appName, restore)) return nil diff --git a/plugins/ps/report.go b/plugins/ps/report.go index af78b7263d5..5e0ddfe4088 100644 --- a/plugins/ps/report.go +++ b/plugins/ps/report.go @@ -129,8 +129,11 @@ func reportRestartPolicy(appName string) string { } func reportRestore(appName string) string { - b, _ := common.PlugnTriggerOutput("config-get", []string{appName, "DOKKU_APP_RESTORE"}...) - restore := strings.TrimSpace(string(b[:])) + results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "config-get", + Args: []string{appName, "DOKKU_APP_RESTORE"}, + }) + restore := results.StdoutContents() if restore == "0" { restore = "false" } else { diff --git a/plugins/ps/triggers.go b/plugins/ps/triggers.go index c91b6c67f5c..c21e68a892b 100644 --- a/plugins/ps/triggers.go +++ b/plugins/ps/triggers.go @@ -72,8 +72,11 @@ func TriggerCorePostExtract(appName string, sourceWorkDir string) error { } processSpecificProcfile := fmt.Sprintf("%s.%s", existingProcfile, os.Getenv("DOKKU_PID")) - b, _ := common.PlugnTriggerOutput("git-get-property", []string{appName, "source-image"}...) - appSourceImage := strings.TrimSpace(string(b[:])) + results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "git-get-property", + Args: []string{appName, "source-image"}, + }) + appSourceImage := results.StdoutContents() repoDefaultProcfilePath := path.Join(sourceWorkDir, "Procfile") if appSourceImage == "" { diff --git a/plugins/scheduler-k3s/triggers.go b/plugins/scheduler-k3s/triggers.go index f0d47120cc9..5bd2b933463 100644 --- a/plugins/scheduler-k3s/triggers.go +++ b/plugins/scheduler-k3s/triggers.go @@ -80,12 +80,15 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e if scheduler != "k3s" { return nil } - s, err := common.PlugnTriggerOutput("ps-current-scale", []string{appName}...) + results, err := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "ps-current-scale", + Args: []string{appName}, + }) if err != nil { return err } - processes, err := common.ParseScaleOutput(s) + processes, err := common.ParseScaleOutput(results.StdoutBytes()) if err != nil { return err } @@ -226,12 +229,15 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e if _, ok := processes["web"]; ok { err = common.PlugnTrigger("domains-vhost-enabled", []string{appName}...) if err == nil { - b, err := common.PlugnTriggerOutput("domains-list", []string{appName}...) + results, err := common.CallPlugnTrigger(common.PlugnTriggerInput{ + Trigger: "domains-list", + Args: []string{appName}, + }) if err != nil { return fmt.Errorf("Error getting domains for deployment: %w", err) } - for _, domain := range strings.Split(string(b), "\n") { + for _, domain := range strings.Split(results.StdoutContents(), "\n") { domain = strings.TrimSpace(domain) if domain != "" { domains = append(domains, domain)