feat: allow all network properties to be globally set
Global settings are cool if managed in a standard way (ugh env vars) so we'll add them back for golang plugins as necessary.
This commit is contained in:
@@ -148,12 +148,22 @@ dokku network:set node-js-app attach-post-deploy
|
|||||||
dokku network:set node-js-app initial-network
|
dokku network:set node-js-app initial-network
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, the `initial-network` property can be set globally by using the `--global` flag in place of the app name.
|
The network properties can also be set globally. The global default is emty string, and the global value is used when no app-specific value is set.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
dokku network:set --global attach-post-create global-create-network
|
||||||
|
dokku network:set --global attach-post-deploy global-deploy-network
|
||||||
dokku network:set --global initial-network global-network
|
dokku network:set --global initial-network global-network
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The default value may be set by passing an empty value for the option.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dokku network:set --global attach-post-create
|
||||||
|
dokku network:set --global attach-post-deploy
|
||||||
|
dokku network:set --global initial-network
|
||||||
|
```
|
||||||
|
|
||||||
#### Network Aliases
|
#### Network Aliases
|
||||||
|
|
||||||
When a container created for a deployment is being attached to a network - regardless of which `attach` property was used - a network alias of the pattern `APP.PROC_TYPE` will be added to all containers. This can be used to load-balance requests between containers. For an application named `node-js-app` with a process type of web, the network alias - or resolvable DNS record within the network - will be:
|
When a container created for a deployment is being attached to a network - regardless of which `attach` property was used - a network alias of the pattern `APP.PROC_TYPE` will be added to all containers. This can be used to load-balance requests between containers. For an application named `node-js-app` with a process type of web, the network alias - or resolvable DNS record within the network - will be:
|
||||||
@@ -172,7 +182,7 @@ Dockerfile-based applications may listen on other ports. For more information on
|
|||||||
|
|
||||||
#### Specifying a custom TLD
|
#### Specifying a custom TLD
|
||||||
|
|
||||||
When attaching applications to networks, a custom TLD can be specified via the `network:set` command. This TLD is suffixed to the network alias for the application/process-type combination for _all_ networks to which the application is attached, and cannot be customized per network.
|
When attaching applications to networks, a custom TLD can be specified via the `network:set` command. This TLD is suffixed to the network alias for the application/process-type combination for _all_ networks to which the application is attached, and cannot be customized per network. The default value is an empty string.
|
||||||
|
|
||||||
To specify a TLD of `svc.cluster.local` for your application, run the following command:
|
To specify a TLD of `svc.cluster.local` for your application, run the following command:
|
||||||
|
|
||||||
@@ -189,6 +199,24 @@ node-js-app.web.svc.cluster.local
|
|||||||
|
|
||||||
Note that this has no impact on container port handling, and users must still specify the container port when making internal network requests.
|
Note that this has no impact on container port handling, and users must still specify the container port when making internal network requests.
|
||||||
|
|
||||||
|
The default value may be set by passing an empty value for the option:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dokku network:set node-js-app tld
|
||||||
|
```
|
||||||
|
|
||||||
|
The `tld` property can also be set globally. The global default is emty string, and the global value is used when no app-specific value is set.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dokku network:set --global tld svc.cluster.local
|
||||||
|
```
|
||||||
|
|
||||||
|
The default value may be set by passing an empty value for the option.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dokku network:set --global tld
|
||||||
|
```
|
||||||
|
|
||||||
#### When to attach containers to a network
|
#### When to attach containers to a network
|
||||||
|
|
||||||
Containers can be attached to a network for a variety of reasons:
|
Containers can be attached to a network for a variety of reasons:
|
||||||
@@ -297,6 +325,18 @@ CONTAINER ID IMAGE COMMAND CREATED
|
|||||||
d6499edb0edb dokku/node-js-app:latest "/bin/bash -c '/star About a minute ago Up About a minute 0.0.0.0:49153->5000/tcp node-js-app.web.1
|
d6499edb0edb dokku/node-js-app:latest "/bin/bash -c '/star About a minute ago Up About a minute 0.0.0.0:49153->5000/tcp node-js-app.web.1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The `bind-all-interfaces` property can also be set globally. The global default is `false`, and the global value is used when no app-specific value is set.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dokku network:set --global bind-all-interfaces true
|
||||||
|
```
|
||||||
|
|
||||||
|
The default value may be set by passing an empty value for the option.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dokku network:set --global bind-all-interfaces
|
||||||
|
```
|
||||||
|
|
||||||
### Displaying network reports for an app
|
### Displaying network reports for an app
|
||||||
|
|
||||||
You can get a report about the app's network status using the `network:report` command:
|
You can get a report about the app's network status using the `network:report` command:
|
||||||
@@ -307,14 +347,56 @@ dokku network:report
|
|||||||
|
|
||||||
```
|
```
|
||||||
=====> node-js-app network information
|
=====> node-js-app network information
|
||||||
Network bind all interfaces: false
|
Network attach post create:
|
||||||
Network listeners: 172.17.0.1:5000
|
Network attach post deploy:
|
||||||
|
Network bind all interfaces: false
|
||||||
|
Network computed attach post create:
|
||||||
|
Network computed attach post deploy:
|
||||||
|
Network computed bind all interfaces:false
|
||||||
|
Network computed initial network:
|
||||||
|
Network computed tld:
|
||||||
|
Network global attach post create:
|
||||||
|
Network global attach post deploy:
|
||||||
|
Network global bind all interfaces:false
|
||||||
|
Network global initial network:
|
||||||
|
Network global tld:
|
||||||
|
Network initial network:
|
||||||
|
Network tld:
|
||||||
|
Network web listeners: 172.17.0.1:5000
|
||||||
=====> python-sample network information
|
=====> python-sample network information
|
||||||
Network bind all interfaces: false
|
Network attach post create:
|
||||||
Network listeners: 172.17.0.2:5000
|
Network attach post deploy:
|
||||||
|
Network bind all interfaces: false
|
||||||
|
Network computed attach post create:
|
||||||
|
Network computed attach post deploy:
|
||||||
|
Network computed bind all interfaces:false
|
||||||
|
Network computed initial network:
|
||||||
|
Network computed tld:
|
||||||
|
Network global attach post create:
|
||||||
|
Network global attach post deploy:
|
||||||
|
Network global bind all interfaces:false
|
||||||
|
Network global initial network:
|
||||||
|
Network global tld:
|
||||||
|
Network initial network:
|
||||||
|
Network tld:
|
||||||
|
Network web listeners: 172.17.0.2:5000
|
||||||
=====> ruby-sample network information
|
=====> ruby-sample network information
|
||||||
Network bind all interfaces: true
|
Network attach post create:
|
||||||
Network listeners:
|
Network attach post deploy:
|
||||||
|
Network bind all interfaces: false
|
||||||
|
Network computed attach post create:
|
||||||
|
Network computed attach post deploy:
|
||||||
|
Network computed bind all interfaces:false
|
||||||
|
Network computed initial network:
|
||||||
|
Network computed tld:
|
||||||
|
Network global attach post create:
|
||||||
|
Network global attach post deploy:
|
||||||
|
Network global bind all interfaces:false
|
||||||
|
Network global initial network:
|
||||||
|
Network global tld:
|
||||||
|
Network initial network:
|
||||||
|
Network tld:
|
||||||
|
Network web listeners:
|
||||||
```
|
```
|
||||||
|
|
||||||
You can run the command for a specific app also.
|
You can run the command for a specific app also.
|
||||||
@@ -325,8 +407,22 @@ dokku network:report node-js-app
|
|||||||
|
|
||||||
```
|
```
|
||||||
=====> node-js-app network information
|
=====> node-js-app network information
|
||||||
Network bind all interfaces: false
|
Network attach post create:
|
||||||
Network listeners: 172.17.0.1:5000
|
Network attach post deploy:
|
||||||
|
Network bind all interfaces: false
|
||||||
|
Network computed attach post create:
|
||||||
|
Network computed attach post deploy:
|
||||||
|
Network computed bind all interfaces:false
|
||||||
|
Network computed initial network:
|
||||||
|
Network computed tld:
|
||||||
|
Network global attach post create:
|
||||||
|
Network global attach post deploy:
|
||||||
|
Network global bind all interfaces:false
|
||||||
|
Network global initial network:
|
||||||
|
Network global tld:
|
||||||
|
Network initial network:
|
||||||
|
Network tld:
|
||||||
|
Network web listeners: 172.17.0.1:5000
|
||||||
```
|
```
|
||||||
|
|
||||||
You can pass flags which will output only the value of the specific information you want. For example:
|
You can pass flags which will output only the value of the specific information you want. For example:
|
||||||
|
|||||||
@@ -20,9 +20,7 @@ func attachAppToNetwork(containerID string, networkName string, appName string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if phase == "deploy" {
|
if phase == "deploy" {
|
||||||
property := "tld"
|
tld := reportComputedTld(appName)
|
||||||
defaultValue := GetDefaultValue(property)
|
|
||||||
tld := common.PropertyGetDefault("network", appName, property, defaultValue)
|
|
||||||
|
|
||||||
networkAlias := fmt.Sprintf("%v.%v", appName, processType)
|
networkAlias := fmt.Sprintf("%v.%v", appName, processType)
|
||||||
if tld != "" {
|
if tld != "" {
|
||||||
@@ -62,14 +60,13 @@ func isConflictingPropertyValue(appName string, property string, value string) b
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
otherProperty := "attach-post-create"
|
otherValue := ""
|
||||||
if property == otherProperty {
|
if property == "attach-post-create" {
|
||||||
otherProperty = "attach-post-deploy"
|
otherValue = reportComputedAttachPostDeploy(appName)
|
||||||
|
} else {
|
||||||
|
otherValue = reportComputedAttachPostCreate(appName)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultValue := GetDefaultValue(otherProperty)
|
|
||||||
otherValue := common.PropertyGetDefault("network", appName, otherProperty, defaultValue)
|
|
||||||
|
|
||||||
return value == otherValue
|
return value == otherValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
// DefaultProperties is a map of all valid network properties with corresponding default property values
|
// DefaultProperties is a map of all valid network properties with corresponding default property values
|
||||||
DefaultProperties = map[string]string{
|
DefaultProperties = map[string]string{
|
||||||
"bind-all-interfaces": "false",
|
"bind-all-interfaces": "",
|
||||||
"attach-post-create": "",
|
"attach-post-create": "",
|
||||||
"attach-post-deploy": "",
|
"attach-post-deploy": "",
|
||||||
"initial-network": "",
|
"initial-network": "",
|
||||||
@@ -26,7 +26,11 @@ var (
|
|||||||
|
|
||||||
// GlobalProperties is a map of all valid global network properties
|
// GlobalProperties is a map of all valid global network properties
|
||||||
GlobalProperties = map[string]bool{
|
GlobalProperties = map[string]bool{
|
||||||
"initial-network": true,
|
"bind-all-interfaces": true,
|
||||||
|
"attach-post-create": true,
|
||||||
|
"attach-post-deploy": true,
|
||||||
|
"initial-network": true,
|
||||||
|
"tld": true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -13,13 +13,22 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
flags := map[string]common.ReportFunc{
|
flags := map[string]common.ReportFunc{
|
||||||
"--network-bind-all-interfaces": reportBindAllInterfaces,
|
"--network-bind-all-interfaces": reportBindAllInterfaces,
|
||||||
"--network-attach-post-create": reportAttachPostCreate,
|
"--network-attach-post-create": reportAttachPostCreate,
|
||||||
"--network-attach-post-deploy": reportAttachPostDeploy,
|
"--network-attach-post-deploy": reportAttachPostDeploy,
|
||||||
"--network-computed-initial-network": reportComputedInitialNetwork,
|
"--network-computed-attach-post-create": reportComputedAttachPostCreate,
|
||||||
"--network-global-initial-network": reportGlobalInitialNetwork,
|
"--network-computed-attach-post-deploy": reportComputedAttachPostDeploy,
|
||||||
"--network-initial-network": reportInitialNetwork,
|
"--network-computed-bind-all-interfaces": reportComputedBindAllInterfaces,
|
||||||
"--network-web-listeners": reportWebListeners,
|
"--network-computed-initial-network": reportComputedInitialNetwork,
|
||||||
|
"--network-computed-tld": reportComputedTld,
|
||||||
|
"--network-global-attach-post-create": reportGlobalAttachPostCreate,
|
||||||
|
"--network-global-attach-post-deploy": reportGlobalAttachPostDeploy,
|
||||||
|
"--network-global-bind-all-interfaces": reportGlobalBindAllInterfaces,
|
||||||
|
"--network-global-initial-network": reportGlobalInitialNetwork,
|
||||||
|
"--network-global-tld": reportGlobalTld,
|
||||||
|
"--network-initial-network": reportInitialNetwork,
|
||||||
|
"--network-tld": reportTld,
|
||||||
|
"--network-web-listeners": reportWebListeners,
|
||||||
}
|
}
|
||||||
|
|
||||||
flagKeys := []string{}
|
flagKeys := []string{}
|
||||||
@@ -33,10 +42,6 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
|||||||
return common.ReportSingleApp("network", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
|
return common.ReportSingleApp("network", appName, infoFlag, infoFlags, flagKeys, format, trimPrefix, uppercaseFirstCharacter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func reportBindAllInterfaces(appName string) string {
|
|
||||||
return common.PropertyGet("network", appName, "bind-all-interfaces")
|
|
||||||
}
|
|
||||||
|
|
||||||
func reportAttachPostCreate(appName string) string {
|
func reportAttachPostCreate(appName string) string {
|
||||||
return common.PropertyGet("network", appName, "attach-post-create")
|
return common.PropertyGet("network", appName, "attach-post-create")
|
||||||
}
|
}
|
||||||
@@ -45,6 +50,37 @@ func reportAttachPostDeploy(appName string) string {
|
|||||||
return common.PropertyGet("network", appName, "attach-post-deploy")
|
return common.PropertyGet("network", appName, "attach-post-deploy")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reportBindAllInterfaces(appName string) string {
|
||||||
|
return common.PropertyGet("network", appName, "bind-all-interfaces")
|
||||||
|
}
|
||||||
|
|
||||||
|
func reportComputedAttachPostCreate(appName string) string {
|
||||||
|
value := reportAttachPostCreate(appName)
|
||||||
|
if value == "" {
|
||||||
|
value = reportGlobalAttachPostCreate(appName)
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
func reportComputedAttachPostDeploy(appName string) string {
|
||||||
|
value := reportAttachPostDeploy(appName)
|
||||||
|
if value == "" {
|
||||||
|
value = reportGlobalAttachPostDeploy(appName)
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
func reportComputedBindAllInterfaces(appName string) string {
|
||||||
|
value := reportBindAllInterfaces(appName)
|
||||||
|
if value == "" {
|
||||||
|
value = reportGlobalBindAllInterfaces(appName)
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
func reportComputedInitialNetwork(appName string) string {
|
func reportComputedInitialNetwork(appName string) string {
|
||||||
value := reportInitialNetwork(appName)
|
value := reportInitialNetwork(appName)
|
||||||
if value == "" {
|
if value == "" {
|
||||||
@@ -54,14 +90,43 @@ func reportComputedInitialNetwork(appName string) string {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reportComputedTld(appName string) string {
|
||||||
|
value := reportTld(appName)
|
||||||
|
if value == "" {
|
||||||
|
value = reportGlobalTld(appName)
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
func reportGlobalAttachPostCreate(appName string) string {
|
||||||
|
return common.PropertyGet("network", "--global", "attach-post-create")
|
||||||
|
}
|
||||||
|
|
||||||
|
func reportGlobalAttachPostDeploy(appName string) string {
|
||||||
|
return common.PropertyGet("network", "--global", "attach-post-deploy")
|
||||||
|
}
|
||||||
|
|
||||||
|
func reportGlobalBindAllInterfaces(appName string) string {
|
||||||
|
return common.PropertyGetDefault("network", "--global", "bind-all-interfaces", "false")
|
||||||
|
}
|
||||||
|
|
||||||
func reportGlobalInitialNetwork(appName string) string {
|
func reportGlobalInitialNetwork(appName string) string {
|
||||||
return common.PropertyGet("network", "--global", "initial-network")
|
return common.PropertyGet("network", "--global", "initial-network")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reportGlobalTld(appName string) string {
|
||||||
|
return common.PropertyGet("network", "--global", "tld")
|
||||||
|
}
|
||||||
|
|
||||||
func reportInitialNetwork(appName string) string {
|
func reportInitialNetwork(appName string) string {
|
||||||
return common.PropertyGet("network", appName, "initial-network")
|
return common.PropertyGet("network", appName, "initial-network")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reportTld(appName string) string {
|
||||||
|
return common.PropertyGet("network", appName, "tld")
|
||||||
|
}
|
||||||
|
|
||||||
func reportWebListeners(appName string) string {
|
func reportWebListeners(appName string) string {
|
||||||
return strings.Join(GetListeners(appName, "web"), " ")
|
return strings.Join(GetListeners(appName, "web"), " ")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,9 +123,20 @@ func TriggerNetworkGetPort(appName string, processType string, containerID strin
|
|||||||
|
|
||||||
// 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) error {
|
func TriggerNetworkGetProperty(appName string, property string) error {
|
||||||
defaultValue := GetDefaultValue(property)
|
computedValueMap := map[string]common.ReportFunc{
|
||||||
value := common.PropertyGetDefault("network", appName, property, defaultValue)
|
"attach-post-create": reportComputedAttachPostCreate,
|
||||||
fmt.Println(value)
|
"attach-post-deploy": reportComputedAttachPostDeploy,
|
||||||
|
"bind-all-interfaces": reportComputedBindAllInterfaces,
|
||||||
|
"initial-network": reportComputedInitialNetwork,
|
||||||
|
"tld": reportComputedTld,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn, ok := computedValueMap[property]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Invalid network property specified: %v", property)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(fn(appName))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,9 +218,7 @@ func TriggerPostContainerCreate(containerType string, containerID string, appNam
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
property := "attach-post-create"
|
networkName := reportComputedAttachPostCreate(appName)
|
||||||
defaultValue := GetDefaultValue(property)
|
|
||||||
networkName := common.PropertyGetDefault("network", appName, property, defaultValue)
|
|
||||||
if networkName == "" {
|
if networkName == "" {
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
@@ -249,9 +258,7 @@ func TriggerPostDelete(appName string) error {
|
|||||||
|
|
||||||
// TriggerCorePostDeploy associates the container with a specified network
|
// TriggerCorePostDeploy associates the container with a specified network
|
||||||
func TriggerCorePostDeploy(appName string) error {
|
func TriggerCorePostDeploy(appName string) error {
|
||||||
property := "attach-post-deploy"
|
networkName := reportComputedAttachPostDeploy(appName)
|
||||||
defaultValue := GetDefaultValue(property)
|
|
||||||
networkName := common.PropertyGetDefault("network", appName, property, defaultValue)
|
|
||||||
if networkName == "" {
|
if networkName == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user