Merge pull request #4374 from dokku/nonexistent-app-error-code

Change exit code when app does not exist
This commit is contained in:
Jose Diaz-Gonzalez authored and GitHub committed 2021-02-28 16:19:33 -05:00
commit a9821decca
33 files changed
+171 -112

No files matched your search

+3 -3
View File
@@ -245,14 +245,14 @@ func executeScript(appName string, image string, imageTag string, phase string)
containerID, err := createdContainerID(appName, dockerArgs, image, script, phase) containerID, err := createdContainerID(appName, dockerArgs, image, script, phase)
if err != nil { if err != nil {
common.LogFail(fmt.Sprintf("Failed to create %s execution container: %s", phase, err.Error())) return fmt.Errorf("Failed to create %s execution container: %s", phase, err.Error())
} }
if !waitForExecution(containerID) { if !waitForExecution(containerID) {
common.LogInfo2Quiet(fmt.Sprintf("Start of %s %s task (%s) output", appName, phaseName, containerID[0:9])) common.LogInfo2Quiet(fmt.Sprintf("Start of %s %s task (%s) output", appName, phaseName, containerID[0:9]))
common.LogVerboseQuietContainerLogs(containerID) common.LogVerboseQuietContainerLogs(containerID)
common.LogInfo2Quiet(fmt.Sprintf("End of %s %s task (%s) output", appName, phaseName, containerID[0:9])) common.LogInfo2Quiet(fmt.Sprintf("End of %s %s task (%s) output", appName, phaseName, containerID[0:9]))
common.LogFail(fmt.Sprintf("Execution of %s task failed: %s", phase, phaseName)) return fmt.Errorf("Execution of %s task failed: %s", phaseName, command)
} }
common.LogInfo2Quiet(fmt.Sprintf("Start of %s %s task (%s) output", appName, phaseName, containerID[0:9])) common.LogInfo2Quiet(fmt.Sprintf("Start of %s %s task (%s) output", appName, phaseName, containerID[0:9]))
@@ -292,7 +292,7 @@ func executeScript(appName string, image string, imageTag string, phase string)
containerCommitCmd.ShowOutput = false containerCommitCmd.ShowOutput = false
containerCommitCmd.Command.Stderr = os.Stderr containerCommitCmd.Command.Stderr = os.Stderr
if !containerCommitCmd.Execute() { if !containerCommitCmd.Execute() {
common.LogFail(fmt.Sprintf("Commiting of '%s' to image failed: %s", phase, command)) return fmt.Errorf("Commiting of '%s' to image failed: %s", phase, command)
} }
return common.PlugnTrigger("scheduler-register-retired", []string{appName, containerID}...) return common.PlugnTrigger("scheduler-register-retired", []string{appName, containerID}...)
+2 -2
View File
@@ -32,10 +32,10 @@ func main() {
imageTag := flag.Arg(1) imageTag := flag.Arg(1)
err = appjson.TriggerPreDeploy(appName, imageTag) err = appjson.TriggerPreDeploy(appName, imageTag)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) err = fmt.Errorf("Invalid plugin trigger call: %s", trigger)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+2 -2
View File
@@ -78,10 +78,10 @@ func main() {
appName := args.Arg(0) appName := args.Arg(0)
err = apps.CommandUnlock(appName) err = apps.CommandUnlock(appName)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+2 -2
View File
@@ -37,10 +37,10 @@ func main() {
appName := flag.Arg(0) appName := flag.Arg(0)
err = apps.ReportSingleApp(appName, "", "") err = apps.ReportSingleApp(appName, "", "")
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) err = fmt.Errorf("Invalid plugin trigger call: %s", trigger)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
@@ -72,10 +72,10 @@ func main() {
} }
err = buildpacks.CommandSetProperty(appName, property, value) err = buildpacks.CommandSetProperty(appName, property, value)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+2 -2
View File
@@ -42,10 +42,10 @@ func main() {
appName := flag.Arg(0) appName := flag.Arg(0)
err = buildpacks.ReportSingleApp(appName, "", "") err = buildpacks.ReportSingleApp(appName, "", "")
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) err = fmt.Errorf("Invalid plugin trigger call: %s", trigger)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+19 -1
View File
@@ -515,6 +515,24 @@ func isValidAppNameOld(appName string) error {
return errors.New("App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, or colons") return errors.New("App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, or colons")
} }
// AppDoesNotExist wraps error to include the app name
// and is used to distinguish between a normal error and an error
// where the app is missing
type AppDoesNotExist struct {
appName string
}
// ExitCode returns an exit code to use in case this error bubbles
// up into an os.Exit() call
func (err *AppDoesNotExist) ExitCode() int {
return 20
}
// Error returns a standard non-existent app error
func (err *AppDoesNotExist) Error() string {
return fmt.Sprintf("App %s does not exist", err.appName)
}
// VerifyAppName checks if an app conforming to either the old or new // VerifyAppName checks if an app conforming to either the old or new
// naming conventions exists // naming conventions exists
func VerifyAppName(appName string) error { func VerifyAppName(appName string) error {
@@ -526,7 +544,7 @@ func VerifyAppName(appName string) error {
appRoot := AppRoot(appName) appRoot := AppRoot(appName)
if !DirectoryExists(appRoot) { if !DirectoryExists(appRoot) {
return fmt.Errorf("App %s does not exist", appName) return &AppDoesNotExist{appName}
} }
return nil return nil
+3 -3
View File
@@ -150,13 +150,13 @@ dokku_log_fail_quiet() {
if [[ -z "$DOKKU_QUIET_OUTPUT" ]]; then if [[ -z "$DOKKU_QUIET_OUTPUT" ]]; then
echo " ! $*" 1>&2 echo " ! $*" 1>&2
fi fi
exit 1 exit ${DOKKU_FAIL_EXIT_CODE:=1}
} }
dokku_log_fail() { dokku_log_fail() {
declare desc="log fail formatter" declare desc="log fail formatter"
echo " ! $*" 1>&2 echo " ! $*" 1>&2
exit 1 exit ${DOKKU_FAIL_EXIT_CODE:=1}
} }
dokku_log_stderr() { dokku_log_stderr() {
@@ -256,7 +256,7 @@ verify_app_name() {
dokku_log_fail "App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, colons, or underscores" dokku_log_fail "App name must begin with lowercase alphanumeric character, and cannot include uppercase characters, colons, or underscores"
fi fi
[[ ! -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "App $APP does not exist" [[ ! -d "$DOKKU_ROOT/$APP" ]] && DOKKU_FAIL_EXIT_CODE=20 dokku_log_fail "App $APP does not exist"
return 0 return 0
} }
+15
View File
@@ -8,6 +8,11 @@ import (
"strings" "strings"
) )
// ErrWithExitCode wraps error and exposes an ExitCode method
type ErrWithExitCode interface {
ExitCode() int
}
// LogFail is the failure log formatter // LogFail is the failure log formatter
// prints text to stderr and exits with status 1 // prints text to stderr and exits with status 1
func LogFail(text string) { func LogFail(text string) {
@@ -15,6 +20,16 @@ func LogFail(text string) {
os.Exit(1) os.Exit(1)
} }
// LogFailWithError is the failure log formatter
// prints text to stderr and exits with the specified exit code
func LogFailWithError(err error) {
fmt.Fprintln(os.Stderr, fmt.Sprintf(" ! %s", err.Error()))
if errExit, ok := err.(ErrWithExitCode); ok {
os.Exit(errExit.ExitCode())
}
os.Exit(1)
}
// LogFailQuiet is the failure log formatter (with quiet option) // LogFailQuiet is the failure log formatter (with quiet option)
// prints text to stderr and exits with status 1 // prints text to stderr and exits with status 1
func LogFailQuiet(text string) { func LogFailQuiet(text string) {
+3 -4
View File
@@ -16,7 +16,7 @@ import (
func CommandPropertySet(pluginName, appName, property, value string, properties map[string]string, globalProperties map[string]bool) { func CommandPropertySet(pluginName, appName, property, value string, properties map[string]string, globalProperties map[string]bool) {
if appName != "--global" { if appName != "--global" {
if err := VerifyAppName(appName); err != nil { if err := VerifyAppName(appName); err != nil {
LogFail(err.Error()) LogFailWithError(err)
} }
} }
if appName == "--global" && !globalProperties[property] { if appName == "--global" && !globalProperties[property] {
@@ -42,9 +42,8 @@ func CommandPropertySet(pluginName, appName, property, value string, properties
PropertyWrite(pluginName, appName, property, value) PropertyWrite(pluginName, appName, property, value)
} else { } else {
LogInfo2Quiet(fmt.Sprintf("Unsetting %s", property)) LogInfo2Quiet(fmt.Sprintf("Unsetting %s", property))
err := PropertyDelete(pluginName, appName, property) if err := PropertyDelete(pluginName, appName, property); err != nil {
if err != nil { LogFailWithError(err)
LogFail(err.Error())
} }
} }
} }
+3 -1
View File
@@ -137,9 +137,11 @@ func getEnvironment(appName string, merged bool) (env *Env) {
} else { } else {
env, err = loadAppOrGlobalEnv(appName) env, err = loadAppOrGlobalEnv(appName)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
return env return env
} }
+1 -1
View File
@@ -77,7 +77,7 @@ func LoadMergedAppEnv(appName string) (env *Env, err error) {
} }
global, err := LoadGlobalEnv() global, err := LoadGlobalEnv()
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
global.Merge(env) global.Merge(env)
global.filename = "" global.filename = ""
+1 -1
View File
@@ -48,7 +48,7 @@ func main() {
appName := args.Arg(0) appName := args.Arg(0)
err := config.CommandShow(appName, *global, *merged, *shell, *export) err := config.CommandShow(appName, *global, *merged, *shell, *export)
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
case "config:help": case "config:help":
usage() usage()
@@ -105,10 +105,10 @@ func main() {
keys := getKeys(args.Args(), *global) keys := getKeys(args.Args(), *global)
err = config.CommandUnset(appName, keys, *global, *noRestart) err = config.CommandUnset(appName, keys, *global, *noRestart)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+4 -4
View File
@@ -27,15 +27,15 @@ func main() {
case "config-get": case "config-get":
appName := flag.Arg(0) appName := flag.Arg(0)
key := flag.Arg(1) key := flag.Arg(1)
config.TriggerConfigGet(appName, key) err = config.TriggerConfigGet(appName, key)
case "config-get-global": case "config-get-global":
key := flag.Arg(0) key := flag.Arg(0)
config.TriggerConfigGetGlobal(key) err = config.TriggerConfigGetGlobal(key)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) err = fmt.Errorf("Invalid plugin trigger call: %s", trigger)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+2 -2
View File
@@ -33,10 +33,10 @@ func main() {
err = cron.CommandReport(appName, *format, infoFlag) err = cron.CommandReport(appName, *format, infoFlag)
} }
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+2 -2
View File
@@ -28,10 +28,10 @@ func main() {
appName := flag.Arg(0) appName := flag.Arg(0)
err = cron.ReportSingleApp(appName, "", "") err = cron.ReportSingleApp(appName, "", "")
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) err = fmt.Errorf("Invalid plugin trigger call: %s", trigger)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+1 -1
View File
@@ -54,7 +54,7 @@ func main() {
appName := args.Arg(0) appName := args.Arg(0)
err := logs.CommandDefault(appName, *num, *ps, *tail, *quiet) err := logs.CommandDefault(appName, *num, *ps, *tail, *quiet)
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
case "logs:help": case "logs:help":
usage() usage()
+2 -2
View File
@@ -62,10 +62,10 @@ func main() {
args.Parse(os.Args[2:]) args.Parse(os.Args[2:])
err = logs.CommandVectorStop() err = logs.CommandVectorStop()
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+2 -2
View File
@@ -34,10 +34,10 @@ func main() {
appName := flag.Arg(0) appName := flag.Arg(0)
err = logs.ReportSingleApp(appName, "", "") err = logs.ReportSingleApp(appName, "", "")
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) err = fmt.Errorf("Invalid plugin trigger call: %s", trigger)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+4 -2
View File
@@ -12,7 +12,7 @@ import (
) )
// attachAppToNetwork attaches a container to a network // attachAppToNetwork attaches a container to a network
func attachAppToNetwork(containerID string, networkName string, appName string, phase string, processType string) { func attachAppToNetwork(containerID string, networkName string, appName string, phase string, processType string) error {
cmdParts := []string{ cmdParts := []string{
common.DockerBin(), common.DockerBin(),
"network", "network",
@@ -50,8 +50,10 @@ func attachAppToNetwork(containerID string, networkName string, appName string,
_, err := attachCmd.Output() _, err := attachCmd.Output()
if err != nil { if err != nil {
err = errors.New(strings.TrimSpace(stderr.String())) err = errors.New(strings.TrimSpace(stderr.String()))
common.LogFail(fmt.Sprintf("Unable to attach container to network: %v", err.Error())) return fmt.Errorf("Unable to attach container to network: %v", err.Error())
} }
return nil
} }
// isConflictingPropertyValue returns true if the other attach property has a conflicting value // isConflictingPropertyValue returns true if the other attach property has a conflicting value
@@ -68,10 +68,10 @@ func main() {
value := args.Arg(2) value := args.Arg(2)
err = network.CommandSet(appName, property, value) err = network.CommandSet(appName, property, value)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+16 -16
View File
@@ -19,49 +19,49 @@ func main() {
var err error var err error
switch trigger { switch trigger {
case "install": case "install":
network.TriggerInstall() err = network.TriggerInstall()
case "network-build-config": case "network-build-config":
appName := flag.Arg(0) appName := flag.Arg(0)
network.BuildConfig(appName) err = network.BuildConfig(appName)
case "network-compute-ports": case "network-compute-ports":
appName := flag.Arg(0) appName := flag.Arg(0)
processType := flag.Arg(1) processType := flag.Arg(1)
isHerokuishContainer := common.ToBool(flag.Arg(2)) isHerokuishContainer := common.ToBool(flag.Arg(2))
network.TriggerNetworkComputePorts(appName, processType, isHerokuishContainer) err = network.TriggerNetworkComputePorts(appName, processType, isHerokuishContainer)
case "network-config-exists": case "network-config-exists":
appName := flag.Arg(0) appName := flag.Arg(0)
network.TriggerNetworkConfigExists(appName) err = network.TriggerNetworkConfigExists(appName)
case "network-get-ipaddr": case "network-get-ipaddr":
appName := flag.Arg(0) appName := flag.Arg(0)
processType := flag.Arg(1) processType := flag.Arg(1)
containerID := flag.Arg(2) containerID := flag.Arg(2)
network.TriggerNetworkGetIppaddr(appName, processType, containerID) err = network.TriggerNetworkGetIppaddr(appName, processType, containerID)
case "network-get-listeners": case "network-get-listeners":
appName := flag.Arg(0) appName := flag.Arg(0)
processType := flag.Arg(1) processType := flag.Arg(1)
network.TriggerNetworkGetListeners(appName, processType) err = network.TriggerNetworkGetListeners(appName, processType)
case "network-get-port": case "network-get-port":
appName := flag.Arg(0) appName := flag.Arg(0)
processType := flag.Arg(1) processType := flag.Arg(1)
containerID := flag.Arg(2) containerID := flag.Arg(2)
isHerokuishContainer := common.ToBool(flag.Arg(3)) isHerokuishContainer := common.ToBool(flag.Arg(3))
network.TriggerNetworkGetPort(appName, processType, containerID, isHerokuishContainer) err = network.TriggerNetworkGetPort(appName, processType, containerID, isHerokuishContainer)
case "network-get-property": case "network-get-property":
appName := flag.Arg(0) appName := flag.Arg(0)
property := flag.Arg(1) property := flag.Arg(1)
network.TriggerNetworkGetProperty(appName, property) err = network.TriggerNetworkGetProperty(appName, property)
case "network-write-ipaddr": case "network-write-ipaddr":
appName := flag.Arg(0) appName := flag.Arg(0)
processType := flag.Arg(1) processType := flag.Arg(1)
containerIndex := flag.Arg(2) containerIndex := flag.Arg(2)
ip := flag.Arg(3) ip := flag.Arg(3)
network.TriggerNetworkWriteIpaddr(appName, processType, containerIndex, ip) err = network.TriggerNetworkWriteIpaddr(appName, processType, containerIndex, ip)
case "network-write-port": case "network-write-port":
appName := flag.Arg(0) appName := flag.Arg(0)
processType := flag.Arg(1) processType := flag.Arg(1)
containerIndex := flag.Arg(2) containerIndex := flag.Arg(2)
port := flag.Arg(3) port := flag.Arg(3)
network.TriggerNetworkWritePort(appName, processType, containerIndex, port) err = network.TriggerNetworkWritePort(appName, processType, containerIndex, port)
case "post-app-clone-setup": case "post-app-clone-setup":
oldAppName := flag.Arg(0) oldAppName := flag.Arg(0)
newAppName := flag.Arg(1) newAppName := flag.Arg(1)
@@ -76,24 +76,24 @@ func main() {
appName := flag.Arg(2) appName := flag.Arg(2)
phase := flag.Arg(3) phase := flag.Arg(3)
processType := flag.Arg(4) processType := flag.Arg(4)
network.TriggerPostContainerCreate(containerType, containerID, appName, phase, processType) err = network.TriggerPostContainerCreate(containerType, containerID, appName, phase, processType)
case "post-create": case "post-create":
appName := flag.Arg(0) appName := flag.Arg(0)
network.TriggerPostCreate(appName) err = network.TriggerPostCreate(appName)
case "post-delete": case "post-delete":
appName := flag.Arg(0) appName := flag.Arg(0)
network.TriggerPostDelete(appName) err = network.TriggerPostDelete(appName)
case "core-post-deploy": case "core-post-deploy":
appName := flag.Arg(0) appName := flag.Arg(0)
network.TriggerCorePostDeploy(appName) err = network.TriggerCorePostDeploy(appName)
case "report": case "report":
appName := flag.Arg(0) appName := flag.Arg(0)
err = network.ReportSingleApp(appName, "", "") err = network.ReportSingleApp(appName, "", "")
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) err = fmt.Errorf("Invalid plugin trigger call: %s", trigger)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+1 -1
View File
@@ -79,7 +79,7 @@ func CommandExists(networkName string) error {
if exists { if exists {
common.LogInfo1Quiet("Network exists") common.LogInfo1Quiet("Network exists")
} else { } else {
common.LogFail("Network does not exist") return errors.New("Network does not exist")
} }
return nil return nil
+55 -32
View File
@@ -11,15 +11,16 @@ import (
) )
// TriggerInstall runs the install step for the network plugin // TriggerInstall runs the install step for the network plugin
func TriggerInstall() { func TriggerInstall() error {
if err := common.PropertySetup("network"); err != nil { if err := common.PropertySetup("network"); err != nil {
common.LogFail(fmt.Sprintf("Unable to install the network plugin: %s", err.Error())) return fmt.Errorf("Unable to install the network plugin: %s", err.Error())
} }
apps, err := common.DokkuApps() apps, err := common.DokkuApps()
if err != nil { if err != nil {
return return nil
} }
for _, appName := range apps { for _, appName := range apps {
if common.PropertyExists("network", appName, "bind-all-interfaces") { if common.PropertyExists("network", appName, "bind-all-interfaces") {
continue continue
@@ -36,10 +37,12 @@ func TriggerInstall() {
} }
} }
} }
return nil
} }
// TriggerNetworkComputePorts computes the ports for a given app container // TriggerNetworkComputePorts computes the ports for a given app container
func TriggerNetworkComputePorts(appName string, processType string, isHerokuishContainer bool) { func TriggerNetworkComputePorts(appName string, processType string, isHerokuishContainer bool) error {
var dockerfilePorts []string var dockerfilePorts []string
if !isHerokuishContainer { if !isHerokuishContainer {
dokkuDockerfilePorts := strings.Trim(config.GetWithDefault(appName, "DOKKU_DOCKERFILE_PORTS", ""), " ") dokkuDockerfilePorts := strings.Trim(config.GetWithDefault(appName, "DOKKU_DOCKERFILE_PORTS", ""), " ")
@@ -60,80 +63,91 @@ func TriggerNetworkComputePorts(appName string, processType string, isHerokuishC
ports = append(ports, port) ports = append(ports, port)
} }
} }
fmt.Println(strings.Join(ports, " ")) fmt.Println(strings.Join(ports, " "))
return nil
} }
// TriggerNetworkConfigExists writes true or false to stdout whether a given app has network config // TriggerNetworkConfigExists writes true or false to stdout whether a given app has network config
func TriggerNetworkConfigExists(appName string) { func TriggerNetworkConfigExists(appName string) error {
if HasNetworkConfig(appName) { if HasNetworkConfig(appName) {
fmt.Println("true") fmt.Println("true")
return return nil
} }
fmt.Println("false") fmt.Println("false")
return nil
} }
// TriggerNetworkGetIppaddr writes the ipaddress to stdout for a given app container // TriggerNetworkGetIppaddr writes the ipaddress to stdout for a given app container
func TriggerNetworkGetIppaddr(appName string, processType string, containerID string) { func TriggerNetworkGetIppaddr(appName string, processType string, containerID string) error {
ipAddress := GetContainerIpaddress(appName, processType, containerID) ipAddress := GetContainerIpaddress(appName, processType, containerID)
fmt.Println(ipAddress) fmt.Println(ipAddress)
return nil
} }
// TriggerNetworkGetListeners returns the listeners (host:port combinations) for a given app container // TriggerNetworkGetListeners returns the listeners (host:port combinations) for a given app container
func TriggerNetworkGetListeners(appName string, processType string) { func TriggerNetworkGetListeners(appName string, processType string) error {
if processType == "" { if processType == "" {
common.LogWarn("Deprecated: Please specify a processType argument for the network-get-listeners plugin trigger") common.LogWarn("Deprecated: Please specify a processType argument for the network-get-listeners plugin trigger")
processType = "web" processType = "web"
} }
listeners := GetListeners(appName, processType) listeners := GetListeners(appName, processType)
fmt.Println(strings.Join(listeners, " ")) fmt.Println(strings.Join(listeners, " "))
return nil
} }
// TriggerNetworkGetPort writes the port to stdout for a given app container // TriggerNetworkGetPort writes the port to stdout for a given app container
func TriggerNetworkGetPort(appName string, processType string, containerID string, isHerokuishContainer bool) { func TriggerNetworkGetPort(appName string, processType string, containerID string, isHerokuishContainer bool) error {
port := GetContainerPort(appName, processType, containerID, isHerokuishContainer) port := GetContainerPort(appName, processType, containerID, isHerokuishContainer)
fmt.Println(port) fmt.Println(port)
return nil
} }
// TriggerNetworkGetProperty writes the network property to stdout for a given app container // TriggerNetworkGetProperty writes the network property to stdout for a given app container
func TriggerNetworkGetProperty(appName string, property string) { func TriggerNetworkGetProperty(appName string, property string) error {
defaultValue := GetDefaultValue(property) defaultValue := GetDefaultValue(property)
value := common.PropertyGetDefault("network", appName, property, defaultValue) value := common.PropertyGetDefault("network", appName, property, defaultValue)
fmt.Println(value) fmt.Println(value)
return nil
} }
// TriggerNetworkWriteIpaddr writes the ip to disk // TriggerNetworkWriteIpaddr writes the ip to disk
func TriggerNetworkWriteIpaddr(appName string, processType string, containerIndex string, ip string) { func TriggerNetworkWriteIpaddr(appName string, processType string, containerIndex string, ip string) error {
appRoot := common.AppRoot(appName) appRoot := common.AppRoot(appName)
filename := fmt.Sprintf("%v/IP.%v.%v", appRoot, processType, containerIndex) filename := fmt.Sprintf("%v/IP.%v.%v", appRoot, processType, containerIndex)
f, err := os.Create(filename) f, err := os.Create(filename)
if err != nil { if err != nil {
common.LogFail(err.Error()) return err
} }
defer f.Close() defer f.Close()
ipBytes := []byte(ip) ipBytes := []byte(ip)
_, err = f.Write(ipBytes) _, err = f.Write(ipBytes)
if err != nil { if err != nil {
common.LogFail(err.Error()) return err
} }
return nil
} }
// TriggerNetworkWritePort writes the port to disk // TriggerNetworkWritePort writes the port to disk
func TriggerNetworkWritePort(appName string, processType string, containerIndex string, port string) { func TriggerNetworkWritePort(appName string, processType string, containerIndex string, port string) error {
appRoot := common.AppRoot(appName) appRoot := common.AppRoot(appName)
filename := fmt.Sprintf("%v/PORT.%v.%v", appRoot, processType, containerIndex) filename := fmt.Sprintf("%v/PORT.%v.%v", appRoot, processType, containerIndex)
f, err := os.Create(filename) f, err := os.Create(filename)
if err != nil { if err != nil {
common.LogFail(err.Error()) return err
} }
defer f.Close() defer f.Close()
portBytes := []byte(port) portBytes := []byte(port)
_, err = f.Write(portBytes) _, err = f.Write(portBytes)
if err != nil { if err != nil {
common.LogFail(err.Error()) return err
} }
return nil
} }
// TriggerPostAppCloneSetup creates new network files // TriggerPostAppCloneSetup creates new network files
@@ -170,75 +184,84 @@ func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
} }
// TriggerPostContainerCreate associates the container with a specified network // TriggerPostContainerCreate associates the container with a specified network
func TriggerPostContainerCreate(containerType string, containerID string, appName string, phase string, processType string) { func TriggerPostContainerCreate(containerType string, containerID string, appName string, phase string, processType string) error {
if containerType != "app" { if containerType != "app" {
return return nil
} }
property := "attach-post-create" property := "attach-post-create"
defaultValue := GetDefaultValue(property) defaultValue := GetDefaultValue(property)
networkName := common.PropertyGetDefault("network", appName, property, defaultValue) networkName := common.PropertyGetDefault("network", appName, property, defaultValue)
if networkName == "" { if networkName == "" {
return return nil
} }
exists, err := networkExists(networkName) exists, err := networkExists(networkName)
if err != nil { if err != nil {
common.LogFail(err.Error()) return err
} }
if !exists { if !exists {
common.LogFail(fmt.Sprintf("Network %v does not exist", networkName)) return fmt.Errorf("Network %v does not exist", networkName)
} }
attachAppToNetwork(containerID, networkName, appName, phase, processType) return attachAppToNetwork(containerID, networkName, appName, phase, processType)
} }
// TriggerPostCreate sets bind-all-interfaces to false by default // TriggerPostCreate sets bind-all-interfaces to false by default
func TriggerPostCreate(appName string) { func TriggerPostCreate(appName string) error {
err := common.PropertyWrite("network", appName, "bind-all-interfaces", "false") err := common.PropertyWrite("network", appName, "bind-all-interfaces", "false")
if err != nil { if err != nil {
common.LogWarn(err.Error()) common.LogWarn(err.Error())
} }
return nil
} }
// TriggerPostDelete destroys the network property for a given app container // TriggerPostDelete destroys the network property for a given app container
func TriggerPostDelete(appName string) { func TriggerPostDelete(appName string) error {
err := common.PropertyDestroy("network", appName) err := common.PropertyDestroy("network", appName)
if err != nil { if err != nil {
common.LogFail(err.Error()) return err
} }
return nil
} }
// TriggerCorePostDeploy associates the container with a specified network // TriggerCorePostDeploy associates the container with a specified network
func TriggerCorePostDeploy(appName string) { func TriggerCorePostDeploy(appName string) error {
property := "attach-post-deploy" property := "attach-post-deploy"
defaultValue := GetDefaultValue(property) defaultValue := GetDefaultValue(property)
networkName := common.PropertyGetDefault("network", appName, property, defaultValue) networkName := common.PropertyGetDefault("network", appName, property, defaultValue)
if networkName == "" { if networkName == "" {
return return nil
} }
common.LogInfo1Quiet(fmt.Sprintf("Associating app with network %s", networkName)) common.LogInfo1Quiet(fmt.Sprintf("Associating app with network %s", networkName))
containerIDs, err := common.GetAppRunningContainerIDs(appName, "") containerIDs, err := common.GetAppRunningContainerIDs(appName, "")
if err != nil { if err != nil {
common.LogFail(err.Error()) return err
} }
exists, err := networkExists(networkName) exists, err := networkExists(networkName)
if err != nil { if err != nil {
common.LogFail(err.Error()) return err
} }
if !exists { if !exists {
common.LogFail(fmt.Sprintf("Network %v does not exist", networkName)) return fmt.Errorf("Network %v does not exist", networkName)
} }
for _, containerID := range containerIDs { for _, containerID := range containerIDs {
processType, err := common.DockerInspect(containerID, "{{ index .Config.Labels \"com.dokku.process-type\"}}") processType, err := common.DockerInspect(containerID, "{{ index .Config.Labels \"com.dokku.process-type\"}}")
if err != nil { if err != nil {
common.LogFail(err.Error()) return err
}
if err := attachAppToNetwork(containerID, networkName, appName, "deploy", processType); err != nil {
return err
} }
attachAppToNetwork(containerID, networkName, appName, "deploy", processType)
} }
return nil
} }
+2 -2
View File
@@ -83,10 +83,10 @@ func main() {
proxyType := args.Arg(1) proxyType := args.Arg(1)
err = proxy.CommandSet(appName, proxyType) err = proxy.CommandSet(appName, proxyType)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+6 -6
View File
@@ -20,24 +20,24 @@ func main() {
switch trigger { switch trigger {
case "proxy-is-enabled": case "proxy-is-enabled":
appName := flag.Arg(0) appName := flag.Arg(0)
proxy.TriggerProxyIsEnabled(appName) err = proxy.TriggerProxyIsEnabled(appName)
case "proxy-type": case "proxy-type":
appName := flag.Arg(0) appName := flag.Arg(0)
proxy.TriggerProxyType(appName) err = proxy.TriggerProxyType(appName)
case "post-certs-remove": case "post-certs-remove":
appName := flag.Arg(0) appName := flag.Arg(0)
proxy.TriggerPostCertsRemove(appName) err = proxy.TriggerPostCertsRemove(appName)
case "post-certs-update": case "post-certs-update":
appName := flag.Arg(0) appName := flag.Arg(0)
proxy.TriggerPostCertsUpdate(appName) err = proxy.TriggerPostCertsUpdate(appName)
case "report": case "report":
appName := flag.Arg(0) appName := flag.Arg(0)
err = proxy.ReportSingleApp(appName, "", "") err = proxy.ReportSingleApp(appName, "", "")
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) err = fmt.Errorf("Invalid plugin trigger call: %s", trigger)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+2 -2
View File
@@ -86,10 +86,10 @@ func main() {
appName := args.Arg(0) appName := args.Arg(0)
err = ps.CommandStop(appName, *allApps, *parallelCount) err = ps.CommandStop(appName, *allApps, *parallelCount)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+2 -2
View File
@@ -75,10 +75,10 @@ func main() {
appName := flag.Arg(0) appName := flag.Arg(0)
err = ps.ReportSingleApp(appName, "", "") err = ps.ReportSingleApp(appName, "", "")
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) err = fmt.Errorf("Invalid plugin trigger call: %s", trigger)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+2 -2
View File
@@ -29,10 +29,10 @@ func main() {
appName := args.Arg(0) appName := args.Arg(0)
err = repo.CommandPurgeCache(appName) err = repo.CommandPurgeCache(appName)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+2 -2
View File
@@ -25,10 +25,10 @@ func main() {
appName := flag.Arg(0) appName := flag.Arg(0)
err = repo.PurgeCache(appName) err = repo.PurgeCache(appName)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) err = fmt.Errorf("Invalid plugin trigger call: %s", trigger)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
@@ -88,10 +88,10 @@ func main() {
appName := args.Arg(0) appName := args.Arg(0)
err = resource.CommandReserveClear(appName, *processType) err = resource.CommandReserveClear(appName, *processType)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin subcommand call: %s", subcommand)) err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }
+2 -2
View File
@@ -45,10 +45,10 @@ func main() {
key := flag.Arg(3) key := flag.Arg(3)
err = resource.TriggerResourceGetProperty(appName, processType, resourceType, key) err = resource.TriggerResourceGetProperty(appName, processType, resourceType, key)
default: default:
common.LogFail(fmt.Sprintf("Invalid plugin trigger call: %s", trigger)) err = fmt.Errorf("Invalid plugin trigger call: %s", trigger)
} }
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFailWithError(err)
} }
} }