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
|
||||
```
|
||||
|
||||
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
|
||||
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
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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:
|
||||
|
||||
@@ -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.
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
Network bind all interfaces: false
|
||||
Network listeners: 172.17.0.1:5000
|
||||
Network attach post create:
|
||||
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
|
||||
Network bind all interfaces: false
|
||||
Network listeners: 172.17.0.2:5000
|
||||
Network attach post create:
|
||||
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
|
||||
Network bind all interfaces: true
|
||||
Network listeners:
|
||||
Network attach post create:
|
||||
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.
|
||||
@@ -325,8 +407,22 @@ dokku network:report node-js-app
|
||||
|
||||
```
|
||||
=====> node-js-app network information
|
||||
Network bind all interfaces: false
|
||||
Network listeners: 172.17.0.1:5000
|
||||
Network attach post create:
|
||||
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:
|
||||
|
||||
@@ -20,9 +20,7 @@ func attachAppToNetwork(containerID string, networkName string, appName string,
|
||||
}
|
||||
|
||||
if phase == "deploy" {
|
||||
property := "tld"
|
||||
defaultValue := GetDefaultValue(property)
|
||||
tld := common.PropertyGetDefault("network", appName, property, defaultValue)
|
||||
tld := reportComputedTld(appName)
|
||||
|
||||
networkAlias := fmt.Sprintf("%v.%v", appName, processType)
|
||||
if tld != "" {
|
||||
@@ -62,14 +60,13 @@ func isConflictingPropertyValue(appName string, property string, value string) b
|
||||
return false
|
||||
}
|
||||
|
||||
otherProperty := "attach-post-create"
|
||||
if property == otherProperty {
|
||||
otherProperty = "attach-post-deploy"
|
||||
otherValue := ""
|
||||
if property == "attach-post-create" {
|
||||
otherValue = reportComputedAttachPostDeploy(appName)
|
||||
} else {
|
||||
otherValue = reportComputedAttachPostCreate(appName)
|
||||
}
|
||||
|
||||
defaultValue := GetDefaultValue(otherProperty)
|
||||
otherValue := common.PropertyGetDefault("network", appName, otherProperty, defaultValue)
|
||||
|
||||
return value == otherValue
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
var (
|
||||
// DefaultProperties is a map of all valid network properties with corresponding default property values
|
||||
DefaultProperties = map[string]string{
|
||||
"bind-all-interfaces": "false",
|
||||
"bind-all-interfaces": "",
|
||||
"attach-post-create": "",
|
||||
"attach-post-deploy": "",
|
||||
"initial-network": "",
|
||||
@@ -26,7 +26,11 @@ var (
|
||||
|
||||
// GlobalProperties is a map of all valid global network properties
|
||||
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{
|
||||
"--network-bind-all-interfaces": reportBindAllInterfaces,
|
||||
"--network-attach-post-create": reportAttachPostCreate,
|
||||
"--network-attach-post-deploy": reportAttachPostDeploy,
|
||||
"--network-computed-initial-network": reportComputedInitialNetwork,
|
||||
"--network-global-initial-network": reportGlobalInitialNetwork,
|
||||
"--network-initial-network": reportInitialNetwork,
|
||||
"--network-web-listeners": reportWebListeners,
|
||||
"--network-bind-all-interfaces": reportBindAllInterfaces,
|
||||
"--network-attach-post-create": reportAttachPostCreate,
|
||||
"--network-attach-post-deploy": reportAttachPostDeploy,
|
||||
"--network-computed-attach-post-create": reportComputedAttachPostCreate,
|
||||
"--network-computed-attach-post-deploy": reportComputedAttachPostDeploy,
|
||||
"--network-computed-bind-all-interfaces": reportComputedBindAllInterfaces,
|
||||
"--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{}
|
||||
@@ -33,10 +42,6 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
||||
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 {
|
||||
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")
|
||||
}
|
||||
|
||||
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 {
|
||||
value := reportInitialNetwork(appName)
|
||||
if value == "" {
|
||||
@@ -54,14 +90,43 @@ func reportComputedInitialNetwork(appName string) string {
|
||||
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 {
|
||||
return common.PropertyGet("network", "--global", "initial-network")
|
||||
}
|
||||
|
||||
func reportGlobalTld(appName string) string {
|
||||
return common.PropertyGet("network", "--global", "tld")
|
||||
}
|
||||
|
||||
func reportInitialNetwork(appName string) string {
|
||||
return common.PropertyGet("network", appName, "initial-network")
|
||||
}
|
||||
|
||||
func reportTld(appName string) string {
|
||||
return common.PropertyGet("network", appName, "tld")
|
||||
}
|
||||
|
||||
func reportWebListeners(appName string) string {
|
||||
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
|
||||
func TriggerNetworkGetProperty(appName string, property string) error {
|
||||
defaultValue := GetDefaultValue(property)
|
||||
value := common.PropertyGetDefault("network", appName, property, defaultValue)
|
||||
fmt.Println(value)
|
||||
computedValueMap := map[string]common.ReportFunc{
|
||||
"attach-post-create": reportComputedAttachPostCreate,
|
||||
"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
|
||||
}
|
||||
|
||||
@@ -207,9 +218,7 @@ func TriggerPostContainerCreate(containerType string, containerID string, appNam
|
||||
|
||||
}
|
||||
|
||||
property := "attach-post-create"
|
||||
defaultValue := GetDefaultValue(property)
|
||||
networkName := common.PropertyGetDefault("network", appName, property, defaultValue)
|
||||
networkName := reportComputedAttachPostCreate(appName)
|
||||
if networkName == "" {
|
||||
return nil
|
||||
|
||||
@@ -249,9 +258,7 @@ func TriggerPostDelete(appName string) error {
|
||||
|
||||
// TriggerCorePostDeploy associates the container with a specified network
|
||||
func TriggerCorePostDeploy(appName string) error {
|
||||
property := "attach-post-deploy"
|
||||
defaultValue := GetDefaultValue(property)
|
||||
networkName := common.PropertyGetDefault("network", appName, property, defaultValue)
|
||||
networkName := reportComputedAttachPostDeploy(appName)
|
||||
if networkName == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user