feat: expose network listeners to nginx templates for all process types

This change allows users to specify a custom nginx.conf.sigil that can expose non-web process types to the outside world in addition to the web process type.

Closes #3258
This commit is contained in:
Jose Diaz-Gonzalez
2020-03-11 12:34:29 -04:00
parent 7d59b45fdb
commit 38a13ecd39
13 changed files with 93 additions and 52 deletions

View File

@@ -72,7 +72,7 @@ func BuildConfig(appName string) {
}
ipAddress := GetContainerIpaddress(appName, processType, containerID)
port := GetContainerPort(appName, processType, isHerokuishContainer, containerID)
port := GetContainerPort(appName, processType, containerID, isHerokuishContainer)
if ipAddress != "" {
args := []string{appName, processType, containerIndexString, ipAddress}
@@ -95,10 +95,6 @@ func BuildConfig(appName string) {
// GetContainerIpaddress returns the ipaddr for a given app container
func GetContainerIpaddress(appName, processType, containerID string) (ipAddr string) {
if processType != "web" {
return
}
if b, err := common.DockerInspect(containerID, "'{{ .HostConfig.NetworkMode }}'"); err == nil {
if string(b[:]) == "host" {
return "127.0.0.1"
@@ -119,11 +115,7 @@ func GetContainerIpaddress(appName, processType, containerID string) (ipAddr str
}
// GetContainerPort returns the port for a given app container
func GetContainerPort(appName, processType string, isHerokuishContainer bool, containerID string) (port string) {
if processType != "web" {
return
}
func GetContainerPort(appName, processType string, containerID string, isHerokuishContainer bool) (port string) {
dockerfilePorts := make([]string, 0)
if !isHerokuishContainer {
configValue := config.GetWithDefault(appName, "DOKKU_DOCKERFILE_PORTS", "")
@@ -165,14 +157,17 @@ func GetDefaultValue(property string) (value string) {
}
// GetListeners returns a string array of app listeners
func GetListeners(appName string) []string {
func GetListeners(appName string, processType string) []string {
appRoot := common.AppRoot(appName)
files, _ := filepath.Glob(appRoot + "/IP.web.*")
ipPrefix := fmt.Sprintf("/IP.%s.", processType)
portPrefix := fmt.Sprintf("/PORT.%s.", processType)
files, _ := filepath.Glob(appRoot + ipPrefix + "*")
var listeners []string
for _, ipfile := range files {
portfile := strings.Replace(ipfile, "/IP.web.", "/PORT.web.", 1)
portfile := strings.Replace(ipfile, ipPrefix, portPrefix, 1)
ipAddress := common.ReadFirstLine(ipfile)
port := common.ReadFirstLine(portfile)
listeners = append(listeners, fmt.Sprintf("%s:%s", ipAddress, port))
@@ -221,7 +216,7 @@ func ReportSingleApp(appName, infoFlag string) error {
"--network-bind-all-interfaces": common.PropertyGet("network", appName, "bind-all-interfaces"),
"--network-attach-post-create": common.PropertyGet("network", appName, "attach-post-create"),
"--network-attach-post-deploy": common.PropertyGet("network", appName, "attach-post-deploy"),
"--network-listeners": strings.Join(GetListeners(appName), " "),
"--network-web-listeners": strings.Join(GetListeners(appName, "web"), " "),
}
trimPrefix := false

View File

@@ -38,13 +38,14 @@ func main() {
network.TriggerNetworkGetIppaddr(appName, processType, containerID)
case "network-get-listeners":
appName := flag.Arg(0)
network.TriggerNetworkGetListeners(appName)
processType := flag.Arg(1)
network.TriggerNetworkGetListeners(appName, processType)
case "network-get-port":
appName := flag.Arg(0)
processType := flag.Arg(1)
isHerokuishContainer := common.ToBool(flag.Arg(2))
containerID := flag.Arg(3)
network.TriggerNetworkGetPort(appName, processType, isHerokuishContainer, containerID)
containerID := flag.Arg(2)
isHerokuishContainer := common.ToBool(flag.Arg(3))
network.TriggerNetworkGetPort(appName, processType, containerID, isHerokuishContainer)
case "network-get-property":
appName := flag.Arg(0)
property := flag.Arg(1)

View File

@@ -40,10 +40,6 @@ func TriggerInstall() {
// TriggerNetworkComputePorts computes the ports for a given app container
func TriggerNetworkComputePorts(appName string, processType string, isHerokuishContainer bool) {
if processType != "web" {
return
}
var dockerfilePorts []string
if !isHerokuishContainer {
dokkuDockerfilePorts := strings.Trim(config.GetWithDefault(appName, "DOKKU_DOCKERFILE_PORTS", ""), " ")
@@ -84,14 +80,18 @@ func TriggerNetworkGetIppaddr(appName string, processType string, containerID st
}
// TriggerNetworkGetListeners returns the listeners (host:port combinations) for a given app container
func TriggerNetworkGetListeners(appName string) {
listeners := GetListeners(appName)
func TriggerNetworkGetListeners(appName string, processType string) {
if processType == "" {
common.LogWarn("Deprecated: Please specify a processType argument for the network-get-listeners plugin trigger")
processType = "web"
}
listeners := GetListeners(appName, processType)
fmt.Println(strings.Join(listeners, " "))
}
// TriggerNetworkGetPort writes the port to stdout for a given app container
func TriggerNetworkGetPort(appName string, processType string, isHerokuishContainer bool, containerID string) {
port := GetContainerPort(appName, processType, isHerokuishContainer, containerID)
func TriggerNetworkGetPort(appName string, processType string, containerID string, isHerokuishContainer bool) {
port := GetContainerPort(appName, processType, containerID, isHerokuishContainer)
fmt.Println(port)
}