refactor: move all port management code to standalone ports plugin
This change makes interacting with port mappings more clear - folks might previously set the port mapping to the proxy type or vice-versa. The existing proxy:ports* commands still exist but will show a deprecation warning for a single minor release.
This commit is contained in:
1 parent
a0b84d52ef
commit
64f0f2674d
43 files changed
+894
-553
No files matched your search
@@ -0,0 +1,116 @@
|
||||
package ports
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
)
|
||||
|
||||
// CommandList is a cmd wrapper to list port mappings for an app
|
||||
func CommandList(appName string) error {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return listAppPortMaps(appName)
|
||||
}
|
||||
|
||||
// CommandAdd adds port mappings to an app
|
||||
func CommandAdd(appName string, portMapStrings []string) error {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(portMapStrings) == 0 {
|
||||
return errors.New("No port mapping specified")
|
||||
}
|
||||
|
||||
portMaps, err := parsePortMapString(strings.Join(portMapStrings, " "))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := addPortMaps(appName, portMaps); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "add"}...)
|
||||
}
|
||||
|
||||
// CommandClear clears all port mappings for an app
|
||||
func CommandClear(appName string) error {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
keys := []string{"DOKKU_PROXY_PORT_MAP"}
|
||||
if err := config.UnsetMany(appName, keys, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "clear"}...)
|
||||
}
|
||||
|
||||
// CommandRemove removes specific port mappings from an app
|
||||
func CommandRemove(appName string, portMapStrings []string) error {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(portMapStrings) == 0 {
|
||||
return errors.New("No port mapping specified")
|
||||
}
|
||||
|
||||
portMaps, err := parsePortMapString(strings.Join(portMapStrings, " "))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := removePortMaps(appName, portMaps); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "remove"}...)
|
||||
}
|
||||
|
||||
// CommandSet sets port mappings for an app
|
||||
func CommandSet(appName string, portMapStrings []string) error {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(portMapStrings) == 0 {
|
||||
return errors.New("No port mapping specified")
|
||||
}
|
||||
|
||||
portMaps, err := parsePortMapString(strings.Join(portMapStrings, " "))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := setPortMaps(appName, portMaps); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return common.PlugnTrigger("post-proxy-ports-update", []string{appName, "set"}...)
|
||||
}
|
||||
|
||||
// CommandReport displays a ports report for one or more apps
|
||||
func CommandReport(appName string, format string, infoFlag string) error {
|
||||
if len(appName) == 0 {
|
||||
apps, err := common.DokkuApps()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, appName := range apps {
|
||||
if err := ReportSingleApp(appName, format, infoFlag); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return ReportSingleApp(appName, format, infoFlag)
|
||||
}
|
||||
Reference in new issue
Block a user