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 parent
977b4567f8
commit
f842869c3d
10 files changed
+157
-31
No files matched your search
@@ -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