refactor: move the proxy port map from config to property
Also remove all direct references to DOKKU_PROXY_PORT_MAP from outside of ports.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
SUBCOMMANDS = subcommands/list subcommands/add subcommands/clear subcommands/remove subcommands/set subcommands/report
|
||||
TRIGGERS = triggers/ports-clear triggers/ports-configure triggers/ports-dockerfile-raw-tcp-ports triggers/ports-get triggers/ports-get-available triggers/post-certs-remove triggers/post-certs-update triggers/report
|
||||
TRIGGERS = triggers/install triggers/ports-clear triggers/ports-configure triggers/ports-dockerfile-raw-tcp-ports triggers/ports-get triggers/ports-get-available triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-certs-remove triggers/post-certs-update triggers/post-delete triggers/report
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = ports
|
||||
|
||||
|
||||
@@ -23,10 +23,7 @@ func addPortMaps(appName string, portMaps []PortMap) error {
|
||||
}
|
||||
|
||||
func clearPorts(appName string) error {
|
||||
return common.EnvWrap(func() error {
|
||||
keys := []string{"DOKKU_PROXY_PORT_MAP"}
|
||||
return config.UnsetMany(appName, keys, false)
|
||||
}, map[string]string{"DOKKU_QUIET_OUTPUT": "1"})
|
||||
return common.PropertyDelete("ports", appName, "port-map")
|
||||
}
|
||||
|
||||
func doesCertExist(appName string) bool {
|
||||
@@ -118,8 +115,12 @@ func getGlobalProxySSLPort() int {
|
||||
}
|
||||
|
||||
func getPortMaps(appName string) []PortMap {
|
||||
value := config.GetWithDefault(appName, "DOKKU_PROXY_PORT_MAP", "")
|
||||
portMaps, _ := parsePortMapString(value)
|
||||
value, err := common.PropertyListGet("ports", appName, "port-map")
|
||||
if err != nil {
|
||||
return []PortMap{}
|
||||
}
|
||||
|
||||
portMaps, _ := parsePortMapString(strings.Join(value, " "))
|
||||
return portMaps
|
||||
}
|
||||
|
||||
@@ -363,8 +364,7 @@ func removePortMaps(appName string, portMaps []PortMap) error {
|
||||
}
|
||||
|
||||
if len(toSet) == 0 {
|
||||
keys := []string{"DOKKU_PROXY_PORT_MAP"}
|
||||
return config.UnsetMany(appName, keys, false)
|
||||
return common.PropertyDelete("ports", appName, "port-map")
|
||||
}
|
||||
|
||||
return setPortMaps(appName, toSet)
|
||||
@@ -380,13 +380,8 @@ func setPortMaps(appName string, portMaps []PortMap) error {
|
||||
value = append(value, portMap.String())
|
||||
}
|
||||
|
||||
return common.EnvWrap(func() error {
|
||||
sort.Strings(value)
|
||||
entries := map[string]string{
|
||||
"DOKKU_PROXY_PORT_MAP": strings.Join(value, " "),
|
||||
}
|
||||
return config.SetMany(appName, entries, false)
|
||||
}, map[string]string{"DOKKU_QUIET_OUTPUT": "1"})
|
||||
sort.Strings(value)
|
||||
return common.PropertyListWrite("ports", appName, "port-map", value)
|
||||
}
|
||||
|
||||
func setProxyPort(appName string, port int) error {
|
||||
|
||||
@@ -18,6 +18,8 @@ func main() {
|
||||
|
||||
var err error
|
||||
switch trigger {
|
||||
case "install":
|
||||
err = ports.TriggerInstall()
|
||||
case "ports-clear":
|
||||
appName := flag.Arg(0)
|
||||
err = ports.TriggerPortsClear(appName)
|
||||
@@ -32,12 +34,23 @@ func main() {
|
||||
err = ports.TriggerPortsGet(appName)
|
||||
case "ports-get-available":
|
||||
err = ports.TriggerPortsGetAvailable()
|
||||
case "post-app-clone-setup":
|
||||
oldAppName := flag.Arg(0)
|
||||
newAppName := flag.Arg(1)
|
||||
err = ports.TriggerPostAppCloneSetup(oldAppName, newAppName)
|
||||
case "post-app-rename-setup":
|
||||
oldAppName := flag.Arg(0)
|
||||
newAppName := flag.Arg(1)
|
||||
err = ports.TriggerPostAppRenameSetup(oldAppName, newAppName)
|
||||
case "post-certs-remove":
|
||||
appName := flag.Arg(0)
|
||||
err = ports.TriggerPostCertsRemove(appName)
|
||||
case "post-certs-update":
|
||||
appName := flag.Arg(0)
|
||||
err = ports.TriggerPostCertsUpdate(appName)
|
||||
case "post-delete":
|
||||
appName := flag.Arg(0)
|
||||
err = ports.TriggerPostDelete(appName)
|
||||
case "report":
|
||||
appName := flag.Arg(0)
|
||||
err = ports.ReportSingleApp(appName, "", "")
|
||||
|
||||
@@ -7,6 +7,43 @@ import (
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
)
|
||||
|
||||
// TriggerInstall migrates the ports config to properties
|
||||
func TriggerInstall() error {
|
||||
if err := common.PropertySetup("ports"); err != nil {
|
||||
return fmt.Errorf("Unable to install the ports plugin: %s", err.Error())
|
||||
}
|
||||
|
||||
apps, err := common.UnfilteredDokkuApps()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, appName := range apps {
|
||||
if common.PropertyExists("ports", appName, "port-map") {
|
||||
continue
|
||||
}
|
||||
|
||||
common.LogInfo1(fmt.Sprintf("Migrating DOKKU_PROXY_PORT_MAP to port-map property for %s", appName))
|
||||
portMapString := config.GetWithDefault(appName, "DOKKU_PROXY_PORT_MAP", "")
|
||||
portMaps, _ := parsePortMapString(portMapString)
|
||||
|
||||
propertyValue := []string{}
|
||||
for _, portMap := range portMaps {
|
||||
propertyValue = append(propertyValue, portMap.String())
|
||||
}
|
||||
|
||||
if err := common.PropertyListWrite("ports", appName, "port-map", propertyValue); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := config.UnsetMany(appName, []string{"DOKKU_PROXY_PORT_MAP"}, false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPortsClear removes all ports for the specified app
|
||||
func TriggerPortsClear(appName string) error {
|
||||
return clearPorts(appName)
|
||||
@@ -64,6 +101,29 @@ func TriggerPortsGetAvailable() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPostAppCloneSetup creates new ports files
|
||||
func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
|
||||
err := common.PropertyClone("ports", oldAppName, newAppName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPostAppRenameSetup renames ports files
|
||||
func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
||||
if err := common.PropertyClone("ports", oldAppName, newAppName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := common.PropertyDestroy("ports", oldAppName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPostCertsRemove unsets port config vars after SSL cert is added
|
||||
func TriggerPostCertsRemove(appName string) error {
|
||||
keys := []string{"DOKKU_PROXY_SSL_PORT"}
|
||||
@@ -129,3 +189,12 @@ func TriggerPostCertsUpdate(appName string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPostDelete is the ports post-delete plugin trigger
|
||||
func TriggerPostDelete(appName string) error {
|
||||
if err := common.PropertyDestroy("ports", appName); err != nil {
|
||||
common.LogWarn(err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user