refactor: bubble up error handling so that standard exit codes can be set at the top-level
LogFail shouldn't be called internally if at all possible.
This commit is contained in:
1 parent
ccdbaa84f9
commit
d09a7506df
26 files changed
+113
-80
No files matched your search
@@ -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}...)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ 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 {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ 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 {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ 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 {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ 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 {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ 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 {
|
||||||
|
|||||||
@@ -515,6 +515,14 @@ 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")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AppDoesNotExist struct {
|
||||||
|
appName string
|
||||||
|
}
|
||||||
|
|
||||||
|
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 +534,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
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ 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 {
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ 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 {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ 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 {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ 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 {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ 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 {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ 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 {
|
||||||
|
|||||||
@@ -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,7 +68,7 @@ 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 {
|
||||||
|
|||||||
@@ -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,21 +76,21 @@ 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 {
|
||||||
|
|||||||
@@ -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
@@ -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
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ 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 {
|
||||||
|
|||||||
@@ -20,21 +20,21 @@ 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 {
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ 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 {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ 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 {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ 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 {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ 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 {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ 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 {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ 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 {
|
||||||
|
|||||||
Reference in new issue
Block a user