From ab509a7424d4956a9577203f26b0d13d62748b11 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 9 Feb 2020 01:21:42 -0500 Subject: [PATCH] feat: ensure network exists before attempting to attach it to a container This will give better feedback to developers than a potentially generic error. --- plugins/network/triggers.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/network/triggers.go b/plugins/network/triggers.go index 184b1a02a..8fa11724a 100644 --- a/plugins/network/triggers.go +++ b/plugins/network/triggers.go @@ -174,6 +174,15 @@ func TriggerPostContainerCreate(containerType string, containerID string, appNam return } + exists, err := networkExists(networkName) + if err != nil { + common.LogFail(err.Error()) + } + + if !exists { + common.LogFail(fmt.Sprintf("Network %v does not exist", networkName)) + } + attachAppToNetwork(containerID, networkName, appName, phase, processType) } @@ -208,6 +217,15 @@ func TriggerCorePostDeploy(appName string) { common.LogFail(err.Error()) } + exists, err := networkExists(networkName) + if err != nil { + common.LogFail(err.Error()) + } + + if !exists { + common.LogFail(fmt.Sprintf("Network %v does not exist", networkName)) + } + for _, containerID := range containerIDs { processType, err := common.DockerInspect(containerID, "{{ index .Config.Labels \"com.dokku.process-type\"}}") if err != nil {