refactor: standardize plugin trigger calls

This commit is contained in:
Jose Diaz-Gonzalez committed 2020-02-22 06:39:33 -05:00
1 parent 59316f4a21
commit 09b656e37e
2 files changed
+19 -6

No files matched your search

+15 -4
View File
@@ -75,19 +75,19 @@ func GetDeployingAppImageName(appName, imageTag, imageRepo string) (imageName st
LogFail("(GetDeployingAppImageName) APP must not be empty") LogFail("(GetDeployingAppImageName) APP must not be empty")
} }
b, err := sh.Command("plugn", "trigger", "deployed-app-repository", appName).Output() b, err := PlugnTriggerOutput("deployed-app-repository", []string{appName}...)
if err != nil { if err != nil {
LogFail(err.Error()) LogFail(err.Error())
} }
imageRemoteRepository := string(b[:]) imageRemoteRepository := string(b[:])
b, err = sh.Command("plugn", "trigger", "deployed-app-image-tag", appName).Output() b, err = PlugnTriggerOutput("deployed-app-image-tag", []string{appName}...)
if err != nil { if err != nil {
LogFail(err.Error()) LogFail(err.Error())
} }
newImageTag := string(b[:]) newImageTag := string(b[:])
b, err = sh.Command("plugn", "trigger", "deployed-app-image-repo", appName).Output() b, err = PlugnTriggerOutput("deployed-app-image-repo", []string{appName}...)
if err != nil { if err != nil {
LogFail(err.Error()) LogFail(err.Error())
} }
@@ -456,7 +456,7 @@ func DockerBin() string {
return dockerBin return dockerBin
} }
//PlugnTrigger fire the given plugn trigger with the given args // PlugnTrigger fire the given plugn trigger with the given args
func PlugnTrigger(triggerName string, args ...string) error { func PlugnTrigger(triggerName string, args ...string) error {
shellArgs := make([]interface{}, len(args)+2) shellArgs := make([]interface{}, len(args)+2)
shellArgs[0] = "trigger" shellArgs[0] = "trigger"
@@ -467,6 +467,17 @@ func PlugnTrigger(triggerName string, args ...string) error {
return sh.Command("plugn", shellArgs...).Run() return sh.Command("plugn", shellArgs...).Run()
} }
// PlugnTriggerOutput fire the given plugn trigger with the given args
func PlugnTriggerOutput(triggerName string, args ...string) ([]byte, error) {
shellArgs := make([]interface{}, len(args)+2)
shellArgs[0] = "trigger"
shellArgs[1] = triggerName
for i, arg := range args {
shellArgs[i+2] = arg
}
return sh.Command("plugn", shellArgs...).Output()
}
func times(str string, n int) (out string) { func times(str string, n int) (out string) {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
out += str out += str
+4 -2
View File
@@ -75,14 +75,16 @@ func BuildConfig(appName string) {
port := GetContainerPort(appName, processType, isHerokuishContainer, containerID) port := GetContainerPort(appName, processType, isHerokuishContainer, containerID)
if ipAddress != "" { if ipAddress != "" {
_, err := sh.Command("plugn", "trigger", "network-write-ipaddr", appName, processType, containerIndexString, ipAddress).Output() args := []string{appName, processType, containerIndexString, ipAddress}
_, err := common.PlugnTriggerOutput("network-write-ipaddr", args...)
if err != nil { if err != nil {
common.LogWarn(err.Error()) common.LogWarn(err.Error())
} }
} }
if port != "" { if port != "" {
_, err := sh.Command("plugn", "trigger", "network-write-port", appName, processType, containerIndexString, port).Output() args := []string{appName, processType, containerIndexString, port}
_, err := common.PlugnTriggerOutput("network-write-port", args...)
if err != nil { if err != nil {
common.LogWarn(err.Error()) common.LogWarn(err.Error())
} }