这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions plugins/app-json/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
})

Expand Down Expand Up @@ -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
}

Expand Down
16 changes: 11 additions & 5 deletions plugins/app-json/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
8 changes: 5 additions & 3 deletions plugins/apps/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"os"
"strings"
"time"

"github.com/dokku/dokku/plugins/common"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions plugins/buildpacks/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 5 additions & 3 deletions plugins/buildpacks/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/dokku/dokku/plugins/common"
)
Expand All @@ -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)
Expand Down
48 changes: 35 additions & 13 deletions plugins/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
})
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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"
}
Expand Down
15 changes: 10 additions & 5 deletions plugins/common/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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()
}
}

Expand Down
10 changes: 10 additions & 0 deletions plugins/common/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions plugins/common/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions plugins/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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())
}
Expand Down
14 changes: 10 additions & 4 deletions plugins/ps/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions plugins/ps/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ps

import (
"fmt"
"strings"

"github.com/dokku/dokku/plugins/common"
)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions plugins/ps/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading