feat: add ability to specify the initial container network
Closes #4477
This commit is contained in:
@@ -20,11 +20,14 @@ var (
|
||||
"bind-all-interfaces": "false",
|
||||
"attach-post-create": "",
|
||||
"attach-post-deploy": "",
|
||||
"initial-network": "",
|
||||
"tld": "",
|
||||
}
|
||||
|
||||
// GlobalProperties is a map of all valid global network properties
|
||||
GlobalProperties = map[string]bool{}
|
||||
GlobalProperties = map[string]bool{
|
||||
"initial-network": true,
|
||||
}
|
||||
)
|
||||
|
||||
// BuildConfig builds network config files
|
||||
|
||||
@@ -13,10 +13,13 @@ 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-web-listeners": reportWebListeners,
|
||||
"--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,
|
||||
}
|
||||
|
||||
flagKeys := []string{}
|
||||
@@ -42,6 +45,23 @@ func reportAttachPostDeploy(appName string) string {
|
||||
return common.PropertyGet("network", appName, "attach-post-deploy")
|
||||
}
|
||||
|
||||
func reportComputedInitialNetwork(appName string) string {
|
||||
value := reportInitialNetwork(appName)
|
||||
if value == "" {
|
||||
value = reportGlobalInitialNetwork(appName)
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
func reportGlobalInitialNetwork(appName string) string {
|
||||
return common.PropertyGet("network", "--global", "initial-network")
|
||||
}
|
||||
|
||||
func reportInitialNetwork(appName string) string {
|
||||
return common.PropertyGet("network", appName, "initial-network")
|
||||
}
|
||||
|
||||
func reportWebListeners(appName string) string {
|
||||
return strings.Join(GetListeners(appName, "web"), " ")
|
||||
}
|
||||
|
||||
@@ -18,6 +18,15 @@ func main() {
|
||||
|
||||
var err error
|
||||
switch trigger {
|
||||
case "docker-args-process-build":
|
||||
appName := flag.Arg(0)
|
||||
err = network.TriggerDockerArgsProcess(appName)
|
||||
case "docker-args-process-deploy":
|
||||
appName := flag.Arg(0)
|
||||
err = network.TriggerDockerArgsProcess(appName)
|
||||
case "docker-args-process-run":
|
||||
appName := flag.Arg(0)
|
||||
err = network.TriggerDockerArgsProcess(appName)
|
||||
case "install":
|
||||
err = network.TriggerInstall()
|
||||
case "network-build-config":
|
||||
|
||||
@@ -2,6 +2,7 @@ package network
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
@@ -10,6 +11,22 @@ import (
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
)
|
||||
|
||||
// TriggerDockerArgsProcess outputs the network plugin docker options for an app
|
||||
func TriggerDockerArgsProcess(appName string) error {
|
||||
stdin, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
initialNetwork := reportComputedInitialNetwork(appName)
|
||||
if initialNetwork != "" {
|
||||
fmt.Printf(" --network=%s ", initialNetwork)
|
||||
}
|
||||
|
||||
fmt.Print(string(stdin))
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerInstall runs the install step for the network plugin
|
||||
func TriggerInstall() error {
|
||||
if err := common.PropertySetup("network"); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user