feat: add support for routing an app to a specified host:port
This is useful when there is a service not managed by Dokku but should be exposed via the Dokku routing layer. As an example, some binaries (consul, nomad, vault) expose web uis, and are traditionally run on the host directly vs in a container. Closes #4665
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
SUBCOMMANDS = subcommands/create subcommands/destroy subcommands/exists subcommands/info subcommands/list subcommands/rebuild subcommands/rebuildall subcommands/report subcommands/set
|
||||
TRIGGERS = triggers/core-post-deploy triggers/docker-args-process-build triggers/docker-args-process-deploy triggers/docker-args-process-run triggers/install triggers/network-build-config triggers/network-compute-ports triggers/network-config-exists triggers/network-get-ipaddr triggers/network-get-listeners triggers/network-get-port triggers/network-get-property triggers/network-write-ipaddr triggers/network-write-port triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-container-create triggers/post-create triggers/post-delete triggers/report
|
||||
TRIGGERS = triggers/core-post-deploy triggers/docker-args-process-build triggers/docker-args-process-deploy triggers/docker-args-process-run triggers/install triggers/network-build-config triggers/network-compute-ports triggers/network-config-exists triggers/network-get-ipaddr triggers/network-get-listeners triggers/network-get-port triggers/network-get-property triggers/network-get-static-listeners triggers/network-write-ipaddr triggers/network-write-port triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-container-create triggers/post-create triggers/post-delete triggers/report
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = network
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package network
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@@ -17,18 +18,19 @@ import (
|
||||
var (
|
||||
// DefaultProperties is a map of all valid network properties with corresponding default property values
|
||||
DefaultProperties = map[string]string{
|
||||
"bind-all-interfaces": "",
|
||||
"attach-post-create": "",
|
||||
"attach-post-deploy": "",
|
||||
"bind-all-interfaces": "",
|
||||
"initial-network": "",
|
||||
"static-web-listener": "",
|
||||
"tld": "",
|
||||
}
|
||||
|
||||
// GlobalProperties is a map of all valid global network properties
|
||||
GlobalProperties = map[string]bool{
|
||||
"bind-all-interfaces": true,
|
||||
"attach-post-create": true,
|
||||
"attach-post-deploy": true,
|
||||
"bind-all-interfaces": true,
|
||||
"initial-network": true,
|
||||
"tld": true,
|
||||
}
|
||||
@@ -40,6 +42,10 @@ func BuildConfig(appName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if staticWebListener := reportStaticWebListener(appName); staticWebListener != "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
appRoot := common.AppRoot(appName)
|
||||
s, err := common.PlugnTriggerOutput("ps-current-scale", []string{appName}...)
|
||||
if err != nil {
|
||||
@@ -97,6 +103,22 @@ func BuildConfig(appName string) error {
|
||||
|
||||
// GetContainerIpaddress returns the ipaddr for a given app container
|
||||
func GetContainerIpaddress(appName, processType, containerID string) (ipAddr string) {
|
||||
if processType == "web" {
|
||||
if staticWebListener := reportStaticWebListener(appName); staticWebListener != "" {
|
||||
ip, _, err := net.SplitHostPort(staticWebListener)
|
||||
if err == nil {
|
||||
return ip
|
||||
}
|
||||
|
||||
ip2 := net.ParseIP(staticWebListener)
|
||||
if ip2 != nil {
|
||||
return ip2.String()
|
||||
}
|
||||
|
||||
return "127.0.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
if b, err := common.DockerInspect(containerID, "{{ .HostConfig.NetworkMode }}"); err == nil {
|
||||
if string(b[:]) == "host" {
|
||||
return "127.0.0.1"
|
||||
@@ -123,6 +145,17 @@ func GetContainerIpaddress(appName, processType, containerID string) (ipAddr str
|
||||
|
||||
// GetContainerPort returns the port for a given app container
|
||||
func GetContainerPort(appName, processType string, containerID string, isHerokuishContainer bool) (port string) {
|
||||
if processType == "web" {
|
||||
if staticWebListener := reportStaticWebListener(appName); staticWebListener != "" {
|
||||
_, port, err := net.SplitHostPort(staticWebListener)
|
||||
if err == nil {
|
||||
return port
|
||||
}
|
||||
|
||||
return "80"
|
||||
}
|
||||
}
|
||||
|
||||
dockerfilePorts := make([]string, 0)
|
||||
if !isHerokuishContainer {
|
||||
configValue := config.GetWithDefault(appName, "DOKKU_DOCKERFILE_PORTS", "")
|
||||
@@ -156,6 +189,12 @@ func GetContainerPort(appName, processType string, containerID string, isHerokui
|
||||
|
||||
// GetListeners returns a string array of app listeners
|
||||
func GetListeners(appName string, processType string) []string {
|
||||
if processType == "web" {
|
||||
if staticWebListener := reportStaticWebListener(appName); staticWebListener != "" {
|
||||
return []string{staticWebListener}
|
||||
}
|
||||
}
|
||||
|
||||
appRoot := common.AppRoot(appName)
|
||||
|
||||
ipPrefix := fmt.Sprintf("/IP.%s.", processType)
|
||||
|
||||
@@ -27,6 +27,7 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
||||
"--network-global-initial-network": reportGlobalInitialNetwork,
|
||||
"--network-global-tld": reportGlobalTld,
|
||||
"--network-initial-network": reportInitialNetwork,
|
||||
"--network-static-web-listener": reportStaticWebListener,
|
||||
"--network-tld": reportTld,
|
||||
"--network-web-listeners": reportWebListeners,
|
||||
}
|
||||
@@ -123,6 +124,10 @@ func reportInitialNetwork(appName string) string {
|
||||
return common.PropertyGet("network", appName, "initial-network")
|
||||
}
|
||||
|
||||
func reportStaticWebListener(appName string) string {
|
||||
return common.PropertyGet("network", appName, "static-web-listener")
|
||||
}
|
||||
|
||||
func reportTld(appName string) string {
|
||||
return common.PropertyGet("network", appName, "tld")
|
||||
}
|
||||
|
||||
@@ -59,6 +59,10 @@ func main() {
|
||||
appName := flag.Arg(0)
|
||||
property := flag.Arg(1)
|
||||
err = network.TriggerNetworkGetProperty(appName, property)
|
||||
case "network-get-static-listeners":
|
||||
appName := flag.Arg(0)
|
||||
processType := flag.Arg(1)
|
||||
err = network.TriggerNetworkGetStaticListeners(appName, processType)
|
||||
case "network-write-ipaddr":
|
||||
appName := flag.Arg(0)
|
||||
processType := flag.Arg(1)
|
||||
|
||||
@@ -140,6 +140,13 @@ func TriggerNetworkGetProperty(appName string, property string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerNetworkGetStaticListeners fetches the static listener for the specified app/processType combination
|
||||
func TriggerNetworkGetStaticListeners(appName string, processType string) error {
|
||||
staticWebListener := reportStaticWebListener(appName)
|
||||
fmt.Println(staticWebListener)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerNetworkWriteIpaddr writes the ip to disk
|
||||
func TriggerNetworkWriteIpaddr(appName string, processType string, containerIndex string, ip string) error {
|
||||
appRoot := common.AppRoot(appName)
|
||||
|
||||
Reference in New Issue
Block a user