feat: allow users to bind to all interfaces when a proxy is enabled
- use a plugin trigger to see whether we should bind to all interfaces - create a generic way of setting properties for a plugin - migrate proxy-enabled to the new network property "bind-all-interfaces" - add network:set subcommand
This commit is contained in:
committed by
Michael Hobbs
parent
7a4464a8ae
commit
acde3d60a7
@@ -20,6 +20,7 @@ Additional commands:`
|
||||
helpContent = `
|
||||
network:rebuild <app>, Rebuilds network settings for an app
|
||||
network:rebuildall, Rebuild network settings for all apps
|
||||
network:set <app> <property> (<value>), Set or clear a network property for an app
|
||||
`
|
||||
)
|
||||
|
||||
|
||||
22
plugins/network/src/subcommands/set/set.go
Normal file
22
plugins/network/src/subcommands/set/set.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
network "github.com/dokku/dokku/plugins/network"
|
||||
)
|
||||
|
||||
// set or clear a network property for an app
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(1)
|
||||
property := flag.Arg(2)
|
||||
value := flag.Arg(3)
|
||||
|
||||
if property == "bind-all-interfaces" && value == "" {
|
||||
value = "false"
|
||||
}
|
||||
|
||||
common.CommandPropertySet("network", appName, property, value, network.ValidProperties)
|
||||
}
|
||||
33
plugins/network/src/triggers/install/install.go
Normal file
33
plugins/network/src/triggers/install/install.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
proxy "github.com/dokku/dokku/plugins/proxy"
|
||||
)
|
||||
|
||||
// runs the install step for the network plugin
|
||||
func main() {
|
||||
err := common.PropertySetup("network")
|
||||
if err != nil {
|
||||
common.LogFail(fmt.Sprintf("Unable to install the network plugin: %s", err.Error()))
|
||||
}
|
||||
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, appName := range apps {
|
||||
if common.PropertyExists("network", appName, "bind-all-interfaces") {
|
||||
continue
|
||||
}
|
||||
if proxy.IsAppProxyEnabled(appName) {
|
||||
common.LogVerboseQuiet("Setting %s network property 'bind-all-interfaces' to false")
|
||||
common.PropertyWrite("network", appName, "bind-all-interfaces", "false")
|
||||
} else {
|
||||
common.LogVerboseQuiet("Setting %s network property 'bind-all-interfaces' to true")
|
||||
common.PropertyWrite("network", appName, "bind-all-interfaces", "true")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
network "github.com/dokku/dokku/plugins/network"
|
||||
)
|
||||
|
||||
// write the port to stdout for a given app container
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
property := flag.Arg(1)
|
||||
|
||||
defaultValue := network.GetDefaultValue(property)
|
||||
common.PropertyGetDefault("network", appName, property, defaultValue)
|
||||
}
|
||||
15
plugins/network/src/triggers/post-create/post-create.go
Normal file
15
plugins/network/src/triggers/post-create/post-create.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// set bind-all-interfaces to false by default
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
|
||||
common.PropertyWrite("network", appName, "bind-all-interfaces", "false")
|
||||
}
|
||||
15
plugins/network/src/triggers/post-delete/post-delete.go
Normal file
15
plugins/network/src/triggers/post-delete/post-delete.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
common "github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// write the port to stdout for a given app container
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
|
||||
common.PropertyDestroy("network", appName)
|
||||
}
|
||||
Reference in New Issue
Block a user