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:
Jose Diaz-Gonzalez
2017-09-03 20:36:09 -04:00
committed by Michael Hobbs
parent 7a4464a8ae
commit acde3d60a7
19 changed files with 477 additions and 53 deletions

View File

@@ -1,3 +1,6 @@
/commands
/subcommands/*
/network-*
/install
/post-create
/post-delete

View File

@@ -8,17 +8,23 @@ build-in-docker: clean
bash -c "make build" || exit $$?
build: commands subcommands triggers
subcommands: subcommands/rebuild subcommands/rebuildall
triggers: network-build-config network-compute-ports network-config-exists network-get-ipaddr network-get-listeners network-get-port network-write-ipaddr network-write-port
subcommands: subcommands/rebuild subcommands/rebuildall subcommands/set
triggers: install network-build-config network-compute-ports network-config-exists network-get-ipaddr network-get-listeners network-get-port network-get-property network-write-ipaddr network-write-port post-create post-delete
commands: **/**/commands.go
go build -a -o commands src/commands/commands.go
subcommands/rebuild: **/**/**/rebuild.go
go build -a -o subcommands/rebuild src/subcommands/rebuild/rebuild.go
go build -a -o subcommands/rebuild src/subcommands/rebuild/rebuild.go
subcommands/rebuildall: **/**/**/rebuildall.go
go build -a -o subcommands/rebuildall src/subcommands/rebuildall/rebuildall.go
subcommands/set: **/**/**/set.go
go build -a -o subcommands/set src/subcommands/set/set.go
install: **/**/**/install.go
go build -a -o install src/triggers/install/install.go
network-build-config: **/**/**/network-build-config.go
go build -a -o network-build-config src/triggers/network-build-config/network-build-config.go
@@ -37,14 +43,23 @@ network-get-listeners: **/**/**/network-get-listeners.go
network-get-port: **/**/**/network-get-port.go
go build -a -o network-get-port src/triggers/network-get-port/network-get-port.go
network-get-property: **/**/**/network-get-property.go
go build -a -o network-get-property src/triggers/network-get-property/network-get-property.go
network-write-ipaddr: **/**/**/network-write-ipaddr.go
go build -a -o network-write-ipaddr src/triggers/network-write-ipaddr/network-write-ipaddr.go
network-write-port: **/**/**/network-write-port.go
go build -a -o network-write-port src/triggers/network-write-port/network-write-port.go
post-create: **/**/**/post-create.go
go build -a -o post-create src/triggers/post-create/post-create.go
post-delete: **/**/**/post-delete.go
go build -a -o post-delete src/triggers/post-delete/post-delete.go
clean:
rm -rf commands subcommands network-*
rm -rf commands subcommands network-* install post-create post-delete
src-clean:
rm -rf .gitignore src vendor Makefile

View File

@@ -12,6 +12,16 @@ import (
sh "github.com/codeskyblue/go-sh"
)
// ValidProperties is a map of all valid network properties
var ValidProperties = map[string]bool{
"bind-all-interfaces": true,
}
// DefaultPropertyValues is a map of all valid network properties with corresponding default property values
var DefaultPropertyValues = map[string]string{
"bind-all-interfaces": "false",
}
// BuildConfig builds network config files
func BuildConfig(appName string) {
err := common.VerifyAppName(appName)
@@ -147,6 +157,14 @@ func GetContainerPort(appName string, procType string, isHerokuishContainer bool
return port
}
// GetDefaultValue returns the default value for a given property
func GetDefaultValue(property string) string {
if ValidProperties[property] {
return DefaultPropertyValues[property]
}
return ""
}
// HasNetworkConfig returns whether the network configuration for a given app exists
func HasNetworkConfig(appName string) bool {
appRoot := strings.Join([]string{common.MustGetEnv("DOKKU_ROOT"), appName}, "/")

View File

@@ -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
`
)

View 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)
}

View 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")
}
}
}

View File

@@ -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)
}

View 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")
}

View 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)
}