mirror of
https://github.com/dokku/dokku.git
synced 2025-12-29 00:25:08 +01:00
Merge pull request #6712 from dokku/6422-remove-plugin-trigger-output
Use CallPlugnTrigger instead of PlugnTriggerOutput
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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[:]))
|
||||
results, _ := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "git-get-property",
|
||||
Args: []string{appName, "source-image"},
|
||||
})
|
||||
appSourceImage := results.StdoutContents()
|
||||
|
||||
b, _ = common.PlugnTriggerOutput("builder-get-property", []string{appName, "build-dir"}...)
|
||||
buildDir := strings.TrimSpace(string(b[:]))
|
||||
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 == "" {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 == "" {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user