refactor: use CallPlugnTrigger instead of PlugnTrigger

Refs #6422
This commit is contained in:
Jose Diaz-Gonzalez committed 2024-03-14 03:11:37 -04:00
1 parent ea609801b5
commit bb5ab0a777
17 files changed
+314 -128

No files matched your search

+25 -6
View File
@@ -442,7 +442,11 @@ func createdContainerID(appName string, dockerArgs []string, image string, comma
} }
containerID := result.StdoutContents() containerID := result.StdoutContents()
err = common.PlugnTrigger("post-container-create", []string{"app", containerID, appName, phase}...) _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "post-container-create",
Args: []string{"app", containerID, appName, phase},
StreamStdio: true,
})
return containerID, err return containerID, err
} }
@@ -462,12 +466,27 @@ func setScale(appName string, image string) error {
} }
if len(args) == 3 { if len(args) == 3 {
return common.PlugnTrigger("ps-can-scale", []string{appName, "true"}...) _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
} Trigger: "ps-can-scale",
Args: []string{appName, "true"},
if err := common.PlugnTrigger("ps-can-scale", []string{appName, "false"}...); err != nil { StreamStdio: true,
})
return err return err
} }
return common.PlugnTrigger("ps-set-scale", args...) _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "ps-can-scale",
Args: []string{appName, "false"},
StreamStdio: true,
})
if err != nil {
return err
}
_, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "ps-set-scale",
Args: args,
StreamStdio: true,
})
return err
} }
+38 -10
View File
@@ -38,11 +38,12 @@ func createApp(appName string) error {
return err return err
} }
if err := common.PlugnTrigger("post-create", []string{appName}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
return err Trigger: "post-create",
} Args: []string{appName},
StreamStdio: true,
return nil })
return err
} }
// destroys an app // destroys an app
@@ -56,19 +57,41 @@ func destroyApp(appName string) error {
common.LogInfo1(fmt.Sprintf("Destroying %s (including all add-ons)", appName)) common.LogInfo1(fmt.Sprintf("Destroying %s (including all add-ons)", appName))
imageTag, _ := common.GetRunningImageTag(appName, "") imageTag, _ := common.GetRunningImageTag(appName, "")
if err := common.PlugnTrigger("pre-delete", []string{appName, imageTag}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "pre-delete",
Args: []string{appName, imageTag},
StreamStdio: true,
})
if err != nil {
return err return err
} }
scheduler := common.GetAppScheduler(appName) scheduler := common.GetAppScheduler(appName)
removeContainers := "true" removeContainers := "true"
if err := common.PlugnTrigger("scheduler-stop", []string{scheduler, appName, removeContainers}...); err != nil { _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "scheduler-stop",
Args: []string{scheduler, appName, removeContainers},
StreamStdio: true,
})
if err != nil {
return err return err
} }
if err := common.PlugnTrigger("scheduler-post-delete", []string{scheduler, appName, imageTag}...); err != nil {
_, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "scheduler-post-delete",
Args: []string{scheduler, appName, imageTag},
StreamStdio: true,
})
if err != nil {
return err return err
} }
if err := common.PlugnTrigger("post-delete", []string{appName, imageTag}...); err != nil {
_, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "post-delete",
Args: []string{appName, imageTag},
StreamStdio: true,
})
if err != nil {
return err return err
} }
@@ -76,7 +99,12 @@ func destroyApp(appName string) error {
common.DockerCleanup(appName, forceCleanup) common.DockerCleanup(appName, forceCleanup)
common.LogInfo1("Retiring old containers and images") common.LogInfo1("Retiring old containers and images")
if err := common.PlugnTrigger("scheduler-retire", []string{scheduler, appName}...); err != nil { _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "scheduler-retire",
Args: []string{scheduler, appName},
StreamStdio: true,
})
if err != nil {
return err return err
} }
+36 -14
View File
@@ -40,7 +40,12 @@ func CommandClone(oldAppName string, newAppName string, skipDeploy bool, ignoreE
return err return err
} }
if err := common.PlugnTrigger("post-app-clone-setup", []string{oldAppName, newAppName}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "post-app-clone-setup",
Args: []string{oldAppName, newAppName},
StreamStdio: true,
})
if err != nil {
return err return err
} }
@@ -48,15 +53,21 @@ func CommandClone(oldAppName string, newAppName string, skipDeploy bool, ignoreE
os.Setenv("SKIP_REBUILD", "true") os.Setenv("SKIP_REBUILD", "true")
} }
if err := common.PlugnTrigger("git-has-code", []string{newAppName}...); err != nil { _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "git-has-code",
Args: []string{newAppName},
StreamStdio: true,
})
if err != nil {
os.Setenv("SKIP_REBUILD", "true") os.Setenv("SKIP_REBUILD", "true")
} }
if err := common.PlugnTrigger("post-app-clone", []string{oldAppName, newAppName}...); err != nil { _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
return err Trigger: "post-app-clone",
} Args: []string{oldAppName, newAppName},
StreamStdio: true,
return nil })
return err
} }
// CommandCreate creates app via command line // CommandCreate creates app via command line
@@ -158,7 +169,12 @@ func CommandRename(oldAppName string, newAppName string, skipDeploy bool) error
return err return err
} }
if err := common.PlugnTrigger("post-app-rename-setup", []string{oldAppName, newAppName}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "post-app-rename-setup",
Args: []string{oldAppName, newAppName},
StreamStdio: true,
})
if err != nil {
return err return err
} }
@@ -171,15 +187,21 @@ func CommandRename(oldAppName string, newAppName string, skipDeploy bool) error
os.Setenv("SKIP_REBUILD", "true") os.Setenv("SKIP_REBUILD", "true")
} }
if err := common.PlugnTrigger("git-has-code", []string{newAppName}...); err != nil { _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "git-has-code",
Args: []string{newAppName},
StreamStdio: true,
})
if err != nil {
os.Setenv("SKIP_REBUILD", "true") os.Setenv("SKIP_REBUILD", "true")
} }
if err := common.PlugnTrigger("post-app-rename", []string{oldAppName, newAppName}...); err != nil { _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
return err Trigger: "post-app-rename",
} Args: []string{oldAppName, newAppName},
StreamStdio: true,
return nil })
return err
} }
// CommandReport displays an app report for one or more apps // CommandReport displays an app report for one or more apps
+12 -2
View File
@@ -149,7 +149,12 @@ func CommandSetProperty(appName string, property string, value string) error {
common.CommandPropertySet("buildpacks", appName, property, value, DefaultProperties, GlobalProperties) common.CommandPropertySet("buildpacks", appName, property, value, DefaultProperties, GlobalProperties)
if property == "stack" && oldStack != value { if property == "stack" && oldStack != value {
if appName != "--global" { if appName != "--global" {
return common.PlugnTrigger("post-stack-set", []string{appName, value}...) _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "post-stack-set",
Args: []string{appName, value},
StreamStdio: true,
})
return err
} }
apps, err := common.DokkuApps() apps, err := common.DokkuApps()
@@ -157,7 +162,12 @@ func CommandSetProperty(appName string, property string, value string) error {
return err return err
} }
for _, app := range apps { for _, app := range apps {
if err := common.PlugnTrigger("post-stack-set", []string{app, value}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "post-stack-set",
Args: []string{app, value},
StreamStdio: true,
})
if err != nil {
return err return err
} }
} }
+1 -46
View File
@@ -1,60 +1,15 @@
package common package common
import ( import (
"fmt"
"io"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/codeskyblue/go-sh" "github.com/codeskyblue/go-sh"
) )
// PlugnTrigger fire the given plugn trigger with the given args
//
// Deprecated: use CallPlugnTrigger instead
func PlugnTrigger(triggerName string, args ...string) error {
LogDebug(fmt.Sprintf("plugn trigger %s %v", triggerName, args))
return PlugnTriggerSetup(triggerName, args...).Run()
}
// PlugnTriggerOutput fire the given plugn trigger with the given args
//
// Deprecated: use CallPlugnTrigger with CaptureOutput=true instead
func PlugnTriggerOutput(triggerName string, args ...string) ([]byte, error) {
LogDebug(fmt.Sprintf("plugn trigger %s %v", triggerName, args))
rE, wE, _ := os.Pipe()
rO, wO, _ := os.Pipe()
session := PlugnTriggerSetup(triggerName, args...)
session.Stderr = wE
session.Stdout = wO
err := session.Run()
wE.Close()
wO.Close()
readStderr, _ := io.ReadAll(rE)
readStdout, _ := io.ReadAll(rO)
stderr := string(readStderr[:])
if err != nil {
err = fmt.Errorf(stderr)
}
if os.Getenv("DOKKU_TRACE") == "1" {
for _, line := range strings.Split(stderr, "\n") {
LogDebug(fmt.Sprintf("plugn trigger %s stderr: %s", triggerName, line))
}
for _, line := range strings.Split(string(readStdout[:]), "\n") {
LogDebug(fmt.Sprintf("plugn trigger %s stdout: %s", triggerName, line))
}
}
return readStdout, err
}
// PlugnTriggerSetup sets up a plugn trigger call // PlugnTriggerSetup sets up a plugn trigger call
// //
// Deprecated: use CallPlugnTrigger instead // Deprecated: use CallPlugnTrigger with Stdin instead
func PlugnTriggerSetup(triggerName string, args ...string) *sh.Session { func PlugnTriggerSetup(triggerName string, args ...string) *sh.Session {
shellArgs := make([]interface{}, len(args)+2) shellArgs := make([]interface{}, len(args)+2)
shellArgs[0] = "trigger" shellArgs[0] = "trigger"
+12 -2
View File
@@ -129,14 +129,24 @@ func UnsetAll(appName string, restart bool) (err error) {
func triggerRestart(appName string) { func triggerRestart(appName string) {
common.LogInfo1(fmt.Sprintf("Restarting app %s", appName)) common.LogInfo1(fmt.Sprintf("Restarting app %s", appName))
if err := common.PlugnTrigger("release-and-deploy", appName); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "release-and-deploy",
Args: []string{appName},
StreamStdio: true,
})
if err != nil {
common.LogWarn(fmt.Sprintf("Failure while restarting app: %s", err)) common.LogWarn(fmt.Sprintf("Failure while restarting app: %s", err))
} }
} }
func triggerUpdate(appName string, operation string, args []string) { func triggerUpdate(appName string, operation string, args []string) {
args = append([]string{appName, operation}, args...) args = append([]string{appName, operation}, args...)
if err := common.PlugnTrigger("post-config-update", args...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "post-config-update",
Args: args,
StreamStdio: true,
})
if err != nil {
common.LogWarn(fmt.Sprintf("Failure while triggering post-config-update: %s", err)) common.LogWarn(fmt.Sprintf("Failure while triggering post-config-update: %s", err))
} }
} }
+11 -2
View File
@@ -110,7 +110,12 @@ func CommandRun(appName string, cronID string, detached bool) error {
os.Setenv("DOKKU_RM_CONTAINER", "1") os.Setenv("DOKKU_RM_CONTAINER", "1")
scheduler := common.GetAppScheduler(appName) scheduler := common.GetAppScheduler(appName)
args := append([]string{scheduler, appName, "0", "--"}, fields...) args := append([]string{scheduler, appName, "0", "--"}, fields...)
return common.PlugnTrigger("scheduler-run", args...) _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "scheduler-run",
Args: args,
StreamStdio: true,
})
return err
} }
// CommandSet set or clear a cron property for an app // CommandSet set or clear a cron property for an app
@@ -120,5 +125,9 @@ func CommandSet(appName string, property string, value string) error {
} }
common.CommandPropertySet("cron", appName, property, value, DefaultProperties, GlobalProperties) common.CommandPropertySet("cron", appName, property, value, DefaultProperties, GlobalProperties)
return common.PlugnTrigger("cron-write") _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "cron-write",
StreamStdio: true,
})
return err
} }
+7 -5
View File
@@ -40,9 +40,11 @@ var templates embed.FS
// GetFailedLogs outputs failed deploy logs for a given app // GetFailedLogs outputs failed deploy logs for a given app
func GetFailedLogs(appName string) error { func GetFailedLogs(appName string) error {
common.LogInfo2Quiet(fmt.Sprintf("%s failed deploy logs", appName)) common.LogInfo2Quiet(fmt.Sprintf("%s failed deploy logs", appName))
s := common.GetAppScheduler(appName) scheduler := common.GetAppScheduler(appName)
if err := common.PlugnTrigger("scheduler-logs-failed", s, appName); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
return err Trigger: "scheduler-logs-failed",
} Args: []string{scheduler, appName},
return nil StreamStdio: true,
})
return err
} }
+6 -1
View File
@@ -40,7 +40,12 @@ func TriggerInstall() error {
if common.PropertyExists("network", appName, "bind-all-interfaces") { if common.PropertyExists("network", appName, "bind-all-interfaces") {
continue continue
} }
if err := common.PlugnTrigger("proxy-is-enabled", []string{appName}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "proxy-is-enabled",
Args: []string{appName},
StreamStdio: true,
})
if err != nil {
common.LogVerboseQuiet("Setting network property 'bind-all-interfaces' to false") common.LogVerboseQuiet("Setting network property 'bind-all-interfaces' to false")
if err := common.PropertyWrite("network", appName, "bind-all-interfaces", "false"); err != nil { if err := common.PropertyWrite("network", appName, "bind-all-interfaces", "false"); err != nil {
common.LogWarn(err.Error()) common.LogWarn(err.Error())
+6 -4
View File
@@ -286,10 +286,12 @@ func inRange(value int, min int, max int) bool {
// isAppVhostEnabled checks if the app vhost is enabled // isAppVhostEnabled checks if the app vhost is enabled
func isAppVhostEnabled(appName string) bool { func isAppVhostEnabled(appName string) bool {
if err := common.PlugnTrigger("domains-vhost-enabled", []string{appName}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
return false Trigger: "domains-vhost-enabled",
} Args: []string{appName},
return true StreamStdio: true,
})
return err == nil
} }
// listAppPortMaps lists the port mappings for an app // listAppPortMaps lists the port mappings for an app
+24 -4
View File
@@ -46,7 +46,12 @@ func CommandAdd(appName string, portMapStrings []string) error {
return err return err
} }
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "add"}...) _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "post-proxy-ports-update",
Args: []string{appName, "add"},
StreamStdio: true,
})
return err
} }
// CommandClear clears all port mappings for an app // CommandClear clears all port mappings for an app
@@ -59,7 +64,12 @@ func CommandClear(appName string) error {
return err return err
} }
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "clear"}...) _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "post-proxy-ports-update",
Args: []string{appName, "clear"},
StreamStdio: true,
})
return err
} }
// CommandRemove removes specific port mappings from an app // CommandRemove removes specific port mappings from an app
@@ -81,7 +91,12 @@ func CommandRemove(appName string, portMapStrings []string) error {
return err return err
} }
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "remove"}...) _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "post-proxy-ports-update",
Args: []string{appName, "remove"},
StreamStdio: true,
})
return err
} }
// CommandSet sets port mappings for an app // CommandSet sets port mappings for an app
@@ -107,7 +122,12 @@ func CommandSet(appName string, portMapStrings []string) error {
return err return err
} }
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "set"}...) _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "post-proxy-ports-update",
Args: []string{appName, "set"},
StreamStdio: true,
})
return err
} }
// CommandReport displays a ports report for one or more apps // CommandReport displays a ports report for one or more apps
+24 -5
View File
@@ -11,12 +11,22 @@ const RunInSerial = 0
// BuildConfig rebuilds the proxy config for the specified app // BuildConfig rebuilds the proxy config for the specified app
func BuildConfig(appName string) error { func BuildConfig(appName string) error {
return common.PlugnTrigger("proxy-build-config", []string{appName}...) _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "proxy-build-config",
Args: []string{appName},
StreamStdio: true,
})
return err
} }
// ClearConfig clears the proxy config for the specified app // ClearConfig clears the proxy config for the specified app
func ClearConfig(appName string) error { func ClearConfig(appName string) error {
return common.PlugnTrigger("proxy-clear-config", []string{appName}...) _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "proxy-clear-config",
Args: []string{appName},
StreamStdio: true,
})
return err
} }
// Disable disables proxy implementations for the specified app // Disable disables proxy implementations for the specified app
@@ -35,7 +45,12 @@ func Disable(appName string) error {
return err return err
} }
return common.PlugnTrigger("proxy-disable", []string{appName}...) _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "proxy-disable",
Args: []string{appName},
StreamStdio: true,
})
return err
} }
// Enable enables proxy implementations for the specified app // Enable enables proxy implementations for the specified app
@@ -50,8 +65,12 @@ func Enable(appName string) error {
if err := config.UnsetMany(appName, keys, false); err != nil { if err := config.UnsetMany(appName, keys, false); err != nil {
return err return err
} }
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
return common.PlugnTrigger("proxy-enable", []string{appName}...) Trigger: "proxy-enable",
Args: []string{appName},
StreamStdio: true,
})
return err
} }
// IsAppProxyEnabled returns true if proxy is enabled; otherwise return false // IsAppProxyEnabled returns true if proxy is enabled; otherwise return false
+12 -2
View File
@@ -210,7 +210,12 @@ func getFormations(appName string) (FormationSlice, error) {
} }
func restorePrep() error { func restorePrep() error {
if err := common.PlugnTrigger("proxy-clear-config", []string{"--all"}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "proxy-clear-config",
Args: []string{"--all"},
StreamStdio: true,
})
if err != nil {
return fmt.Errorf("Error clearing proxy config: %s", err) return fmt.Errorf("Error clearing proxy config: %s", err)
} }
@@ -266,7 +271,12 @@ func scaleSet(appName string, skipDeploy bool, clearExisting bool, processTuples
} }
for _, formation := range formations { for _, formation := range formations {
if err := common.PlugnTrigger("deploy", []string{appName, imageTag, formation.ProcessType}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "deploy",
Args: []string{appName, imageTag, formation.ProcessType},
StreamStdio: true,
})
if err != nil {
return err return err
} }
} }
+72 -20
View File
@@ -68,7 +68,12 @@ func (d FormationSlice) Less(i, j int) bool {
// Rebuild rebuilds app from base image // Rebuild rebuilds app from base image
func Rebuild(appName string) error { func Rebuild(appName string) error {
return common.PlugnTrigger("receive-app", []string{appName}...) _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "receive-app",
Args: []string{appName},
StreamStdio: true,
})
return err
} }
// Restart restarts the app // Restart restarts the app
@@ -85,10 +90,20 @@ func Restart(appName string) error {
if imageTag == "" { if imageTag == "" {
common.LogWarn("No deployed-image-tag property saved, falling back to full release-and-deploy") common.LogWarn("No deployed-image-tag property saved, falling back to full release-and-deploy")
return common.PlugnTrigger("release-and-deploy", []string{appName}...) _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "release-and-deploy",
Args: []string{appName},
StreamStdio: true,
})
return err
} }
return common.PlugnTrigger("deploy", []string{appName, imageTag}...) _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "deploy",
Args: []string{appName, imageTag},
StreamStdio: true,
})
return err
} }
// RestartProcess restarts a process type within an app // RestartProcess restarts a process type within an app
@@ -105,21 +120,41 @@ func RestartProcess(appName string, processName string) error {
if imageTag == "" { if imageTag == "" {
common.LogWarn("No deployed-image-tag property saved, falling back to full release-and-deploy") common.LogWarn("No deployed-image-tag property saved, falling back to full release-and-deploy")
return common.PlugnTrigger("release-and-deploy", []string{appName}...) _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "release-and-deploy",
Args: []string{appName},
StreamStdio: true,
})
return err
} }
return common.PlugnTrigger("deploy", []string{appName, imageTag, processName}...) _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "deploy",
Args: []string{appName, imageTag, processName},
StreamStdio: true,
})
return err
} }
// Restore ensures an app that should be running is running on boot // Restore ensures an app that should be running is running on boot
func Restore(appName string) error { func Restore(appName string) error {
scheduler := common.GetAppScheduler(appName) scheduler := common.GetAppScheduler(appName)
if err := common.PlugnTrigger("scheduler-pre-restore", []string{scheduler, appName}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "scheduler-pre-restore",
Args: []string{scheduler, appName},
StreamStdio: true,
})
if err != nil {
return fmt.Errorf("Error running scheduler-pre-restore: %s", err) return fmt.Errorf("Error running scheduler-pre-restore: %s", err)
} }
common.LogInfo1("Clearing potentially invalid proxy configuration") common.LogInfo1("Clearing potentially invalid proxy configuration")
if err := common.PlugnTrigger("proxy-clear-config", []string{appName}...); err != nil { _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "proxy-clear-config",
Args: []string{appName},
StreamStdio: true,
})
if err != nil {
common.LogWarn(fmt.Sprintf("Error clearing proxy config: %s", err)) common.LogWarn(fmt.Sprintf("Error clearing proxy config: %s", err))
} }
@@ -151,7 +186,12 @@ func Start(appName string) error {
return nil return nil
} }
if err := common.PlugnTrigger("pre-start", []string{appName}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "pre-start",
Args: []string{appName},
StreamStdio: true,
})
if err != nil {
return fmt.Errorf("Failure in pre-start hook: %s", err) return fmt.Errorf("Failure in pre-start hook: %s", err)
} }
@@ -164,18 +204,24 @@ func Start(appName string) error {
} }
if runningState != "true" { if runningState != "true" {
if err := common.PlugnTrigger("release-and-deploy", []string{appName, imageTag}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "release-and-deploy",
Args: []string{appName, imageTag},
StreamStdio: true,
})
if err != nil {
return err return err
} }
} else { } else {
common.LogWarn(fmt.Sprintf("App %s already running", appName)) common.LogWarn(fmt.Sprintf("App %s already running", appName))
} }
if err := common.PlugnTrigger("proxy-build-config", []string{appName}...); err != nil { _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
return err Trigger: "proxy-build-config",
} Args: []string{appName},
StreamStdio: true,
return nil })
return err
} }
// Stop stops the app // Stop stops the app
@@ -188,13 +234,19 @@ func Stop(appName string) error {
common.LogInfo1Quiet(fmt.Sprintf("Stopping %s", appName)) common.LogInfo1Quiet(fmt.Sprintf("Stopping %s", appName))
scheduler := common.GetAppScheduler(appName) scheduler := common.GetAppScheduler(appName)
if err := common.PlugnTrigger("scheduler-stop", []string{scheduler, appName}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "scheduler-stop",
Args: []string{scheduler, appName},
StreamStdio: true,
})
if err != nil {
return err return err
} }
if err := common.PlugnTrigger("post-stop", []string{appName}...); err != nil { _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
return err Trigger: "post-stop",
} Args: []string{appName},
StreamStdio: true,
return nil })
return err
} }
+17 -3
View File
@@ -18,7 +18,12 @@ func CommandInspect(appName string) error {
} }
scheduler := common.GetAppScheduler(appName) scheduler := common.GetAppScheduler(appName)
return common.PlugnTrigger("scheduler-inspect", []string{scheduler, appName}...) _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "scheduler-inspect",
Args: []string{scheduler, appName},
StreamStdio: true,
})
return err
} }
// CommandRebuild rebuilds an app from source // CommandRebuild rebuilds an app from source
@@ -74,7 +79,11 @@ func CommandRestart(appName string, processName string, allApps bool, parallelCo
// CommandRestore starts previously running apps e.g. after reboot // CommandRestore starts previously running apps e.g. after reboot
func CommandRestore(appName string, allApps bool, parallelCount int) error { func CommandRestore(appName string, allApps bool, parallelCount int) error {
if err := common.PlugnTrigger("pre-restore", []string{}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "pre-restore",
StreamStdio: true,
})
if err != nil {
return fmt.Errorf("Error running pre-restore: %s", err) return fmt.Errorf("Error running pre-restore: %s", err)
} }
@@ -124,7 +133,12 @@ func CommandRetire(appName string) error {
} }
common.LogInfo1("Retiring old containers and images") common.LogInfo1("Retiring old containers and images")
return common.PlugnTrigger("scheduler-retire", []string{scheduler, appName}...) _, err = common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "scheduler-retire",
Args: []string{scheduler, appName},
StreamStdio: true,
})
return err
} }
// CommandScale gets or sets how many instances of a given process to run // CommandScale gets or sets how many instances of a given process to run
+6 -1
View File
@@ -90,7 +90,12 @@ func TriggerPostDelete(appName string) error {
func TriggerPostReleaseBuilder(appName string, image string) error { func TriggerPostReleaseBuilder(appName string, image string) error {
parts := strings.Split(image, ":") parts := strings.Split(image, ":")
imageTag := parts[len(parts)-1] imageTag := parts[len(parts)-1]
if err := common.PlugnTrigger("pre-deploy", []string{appName, imageTag}...); err != nil { _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "pre-deploy",
Args: []string{appName, imageTag},
StreamStdio: true,
})
if err != nil {
return err return err
} }
+5 -1
View File
@@ -227,7 +227,11 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
domains := []string{} domains := []string{}
if _, ok := processes["web"]; ok { if _, ok := processes["web"]; ok {
err = common.PlugnTrigger("domains-vhost-enabled", []string{appName}...) _, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "domains-vhost-enabled",
Args: []string{appName},
StreamStdio: true,
})
if err == nil { if err == nil {
results, err := common.CallPlugnTrigger(common.PlugnTriggerInput{ results, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
Trigger: "domains-list", Trigger: "domains-list",