diff --git a/plugins/common/common.go b/plugins/common/common.go index 26825054b..97a7b2e1e 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -158,7 +158,7 @@ func VerifyImage(image string) bool { // ContainerIsRunning checks to see if a container is running func ContainerIsRunning(containerId string) bool { - b, err := sh.Command("docker", "inspect", "--format", "'{{.State.Running}}'", containerId).Output() + b, err := DockerInspect(containerId, "'{{.State.Running}}'") if err != nil { return false } @@ -175,6 +175,20 @@ func DirectoryExists(filePath string) bool { return fi.IsDir() } +// DockerInspect runs an inspect command with a given format against a container id +func DockerInspect(containerId, format string) (string, error) { + b, err := sh.Command("docker", "inspect", "--format", format, containerId).Output() + if err != nil { + return "", err + } + output := strings.TrimSpace(string(b[:])) + if strings.HasPrefix(output, "'") && strings.HasSuffix(output, "'") { + output = strings.TrimSuffix(strings.TrimPrefix(output, "'"), "'") + } + return output, err + +} + // DokkuApps returns a list of all local apps func DokkuApps() ([]string, error) { var apps []string diff --git a/plugins/network/network.go b/plugins/network/network.go index cacb79001..832a8d25e 100644 --- a/plugins/network/network.go +++ b/plugins/network/network.go @@ -23,25 +23,10 @@ func GetContainerIpaddress(appName string, procType string, isHerokuishContainer return ipAddress } - imageCmd := common.NewShellCmd(strings.Join([]string{ - "docker", - "inspect", - "--format", - "'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'", - containerId, - }, " ")) - - b, err := imageCmd.Output() + b, err := common.DockerInspect(containerId, "'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'") if err != nil || len(b) == 0 { // docker < 1.9 compatibility - imageCmd = common.NewShellCmd(strings.Join([]string{ - "docker", - "inspect", - "--format", - "'{{ .NetworkSettings.IPAddress }}'", - containerId, - }, " ")) - b, err = imageCmd.Output() + b, err = common.DockerInspect(containerId, "'{{ .NetworkSettings.IPAddress }}'") } if err == nil { @@ -61,7 +46,10 @@ func GetContainerPort(appName string, procType string, isHerokuishContainer bool port := "" if isHerokuishContainer { - dockerfilePorts = strings.Split(config.GetWithDefault(appName, "DOKKU_DOCKERFILE_PORTS", ""), " ") + configValue := config.GetWithDefault(appName, "DOKKU_DOCKERFILE_PORTS", "") + if configValue != "" { + dockerfilePorts = strings.Split(configValue, " ") + } } if len(dockerfilePorts) > 0 { @@ -79,13 +67,7 @@ func GetContainerPort(appName string, procType string, isHerokuishContainer bool } if !proxy.IsAppProxyEnabled(appName) { - portCmd := common.NewShellCmd(strings.Join([]string{ - "docker", - "port", - containerId, - port, - }, " ")) - b, err := portCmd.Output() + b, err := sh.Command("docker", "port", containerId, port).Output() if err == nil { port = strings.Split(string(b[:]), ":")[1] }