Merge pull request #8498 from dokku/migrate-env-vars-to-properties
Migrate environment variables to plugin properties
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
SUBCOMMANDS = subcommands/build-config subcommands/clear-config subcommands/disable subcommands/enable subcommands/ports subcommands/ports-add subcommands/ports-clear subcommands/ports-remove subcommands/ports-set subcommands/report subcommands/set
|
||||
TRIGGERS = triggers/proxy-is-enabled triggers/proxy-type triggers/report
|
||||
TRIGGERS = triggers/install triggers/proxy-is-enabled triggers/proxy-type triggers/post-app-clone-setup triggers/post-app-rename-setup triggers/post-delete triggers/report
|
||||
BUILD = commands subcommands triggers
|
||||
PLUGIN_NAME = proxy
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
func getAppProxyType(appName string) string {
|
||||
return config.GetWithDefault(appName, "DOKKU_APP_PROXY_TYPE", "")
|
||||
return common.PropertyGet("proxy", appName, "type")
|
||||
}
|
||||
|
||||
func getComputedProxyType(appName string) string {
|
||||
@@ -18,5 +18,5 @@ func getComputedProxyType(appName string) string {
|
||||
}
|
||||
|
||||
func getGlobalProxyType() string {
|
||||
return config.GetWithDefault("--global", "DOKKU_PROXY_TYPE", "nginx")
|
||||
return common.PropertyGetDefault("proxy", "--global", "type", "nginx")
|
||||
}
|
||||
|
||||
@@ -2,13 +2,29 @@ package proxy
|
||||
|
||||
import (
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
)
|
||||
|
||||
// RunInSerial is the default value for whether to run a command in parallel or not
|
||||
// and defaults to -1 (false)
|
||||
const RunInSerial = 0
|
||||
|
||||
var (
|
||||
// DefaultProperties is a map of all valid proxy properties with corresponding default property values
|
||||
DefaultProperties = map[string]string{
|
||||
"disabled": "false",
|
||||
"proxy-port": "",
|
||||
"proxy-ssl-port": "",
|
||||
"type": "",
|
||||
}
|
||||
|
||||
// GlobalProperties is a map of all valid global proxy properties
|
||||
GlobalProperties = map[string]bool{
|
||||
"proxy-port": true,
|
||||
"proxy-ssl-port": true,
|
||||
"type": true,
|
||||
}
|
||||
)
|
||||
|
||||
// BuildConfig rebuilds the proxy config for the specified app
|
||||
func BuildConfig(appName string) error {
|
||||
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
@@ -37,11 +53,7 @@ func Disable(appName string) error {
|
||||
}
|
||||
|
||||
common.LogInfo1("Disabling proxy for app")
|
||||
entries := map[string]string{
|
||||
"DOKKU_DISABLE_PROXY": "1",
|
||||
}
|
||||
|
||||
if err := config.SetMany(appName, entries, false, false); err != nil {
|
||||
if err := common.PropertyWrite("proxy", appName, "disabled", "true"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -61,10 +73,10 @@ func Enable(appName string) error {
|
||||
}
|
||||
|
||||
common.LogInfo1("Enabling proxy for app")
|
||||
keys := []string{"DOKKU_DISABLE_PROXY"}
|
||||
if err := config.UnsetMany(appName, keys, false); err != nil {
|
||||
if err := common.PropertyDelete("proxy", appName, "disabled"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err := common.CallPlugnTrigger(common.PlugnTriggerInput{
|
||||
Trigger: "proxy-enable",
|
||||
Args: []string{appName},
|
||||
@@ -75,10 +87,5 @@ func Enable(appName string) error {
|
||||
|
||||
// IsAppProxyEnabled returns true if proxy is enabled; otherwise return false
|
||||
func IsAppProxyEnabled(appName string) bool {
|
||||
proxyEnabled := true
|
||||
disableProxy := config.GetWithDefault(appName, "DOKKU_DISABLE_PROXY", "")
|
||||
if disableProxy != "" {
|
||||
proxyEnabled = false
|
||||
}
|
||||
return proxyEnabled
|
||||
return common.PropertyGetDefault("proxy", appName, "disabled", "false") != "true"
|
||||
}
|
||||
|
||||
@@ -59,12 +59,14 @@ func main() {
|
||||
global := args.Bool("global", false, "--global: set a global property")
|
||||
args.Parse(os.Args[2:])
|
||||
appName := args.Arg(0)
|
||||
proxyType := args.Arg(1)
|
||||
property := args.Arg(1)
|
||||
value := args.Arg(2)
|
||||
if *global {
|
||||
appName = "--global"
|
||||
proxyType = args.Arg(0)
|
||||
property = args.Arg(0)
|
||||
value = args.Arg(1)
|
||||
}
|
||||
err = proxy.CommandSet(appName, proxyType)
|
||||
err = proxy.CommandSet(appName, property, value)
|
||||
default:
|
||||
err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
|
||||
}
|
||||
|
||||
@@ -18,12 +18,25 @@ func main() {
|
||||
|
||||
var err error
|
||||
switch trigger {
|
||||
case "install":
|
||||
err = proxy.TriggerInstall()
|
||||
case "proxy-is-enabled":
|
||||
appName := flag.Arg(0)
|
||||
err = proxy.TriggerProxyIsEnabled(appName)
|
||||
case "proxy-type":
|
||||
appName := flag.Arg(0)
|
||||
err = proxy.TriggerProxyType(appName)
|
||||
case "post-app-clone-setup":
|
||||
oldAppName := flag.Arg(0)
|
||||
newAppName := flag.Arg(1)
|
||||
err = proxy.TriggerPostAppCloneSetup(oldAppName, newAppName)
|
||||
case "post-app-rename-setup":
|
||||
oldAppName := flag.Arg(0)
|
||||
newAppName := flag.Arg(1)
|
||||
err = proxy.TriggerPostAppRenameSetup(oldAppName, newAppName)
|
||||
case "post-delete":
|
||||
appName := flag.Arg(0)
|
||||
err = proxy.TriggerPostDelete(appName)
|
||||
case "report":
|
||||
appName := flag.Arg(0)
|
||||
err = proxy.ReportSingleApp(appName, "", "")
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/config"
|
||||
)
|
||||
|
||||
// CommandBuildConfig rebuilds config for a given app
|
||||
@@ -82,29 +81,19 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
return ReportSingleApp(appName, format, infoFlag)
|
||||
}
|
||||
|
||||
// CommandSet sets a proxy for an app
|
||||
func CommandSet(appName string, proxyType string) error {
|
||||
if appName != "--global" {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
// CommandSet set or clear a proxy property for an app
|
||||
func CommandSet(appName string, property string, value string) error {
|
||||
// backward compatibility: `proxy:set <app> <proxy-type>` is treated as
|
||||
// `proxy:set <app> type <proxy-type>`
|
||||
if _, ok := DefaultProperties[property]; !ok && value == "" {
|
||||
if strings.Contains(property, ":") {
|
||||
common.LogWarn("Detected potential port mapping instead of proxy type")
|
||||
return errors.New("Consider using ports:set command or specifying a valid proxy")
|
||||
}
|
||||
value = property
|
||||
property = "type"
|
||||
}
|
||||
|
||||
if len(proxyType) < 2 {
|
||||
return errors.New("Please specify a proxy type")
|
||||
}
|
||||
|
||||
if strings.Contains(proxyType, ":") {
|
||||
common.LogWarn("Detected potential port mapping instead of proxy type")
|
||||
return errors.New("Consider using ports:set command or specifying a valid proxy")
|
||||
}
|
||||
|
||||
key := "DOKKU_APP_PROXY_TYPE"
|
||||
if appName == "--global" {
|
||||
key = "DOKKU_PROXY_TYPE"
|
||||
}
|
||||
entries := map[string]string{
|
||||
key: proxyType,
|
||||
}
|
||||
return config.SetMany(appName, entries, false, false)
|
||||
common.CommandPropertySet("proxy", appName, property, value, DefaultProperties, GlobalProperties)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,8 +2,49 @@ package proxy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
)
|
||||
|
||||
// TriggerInstall runs the install step for the proxy plugin
|
||||
func TriggerInstall() error {
|
||||
if err := common.PropertySetup("proxy"); err != nil {
|
||||
return fmt.Errorf("Unable to install the proxy plugin: %s", err.Error())
|
||||
}
|
||||
|
||||
if err := common.MigrateConfigToProperties("proxy", []common.MigrateConfigEntry{
|
||||
{
|
||||
ConfigVar: "DOKKU_APP_PROXY_TYPE",
|
||||
GlobalConfigVar: "DOKKU_PROXY_TYPE",
|
||||
Property: "type",
|
||||
},
|
||||
{
|
||||
ConfigVar: "DOKKU_DISABLE_PROXY",
|
||||
Property: "disabled",
|
||||
Transform: func(value string) string {
|
||||
if value != "" {
|
||||
return "true"
|
||||
}
|
||||
return value
|
||||
},
|
||||
},
|
||||
{
|
||||
ConfigVar: "DOKKU_PROXY_PORT",
|
||||
GlobalConfigVar: "DOKKU_PROXY_PORT",
|
||||
Property: "proxy-port",
|
||||
},
|
||||
{
|
||||
ConfigVar: "DOKKU_PROXY_SSL_PORT",
|
||||
GlobalConfigVar: "DOKKU_PROXY_SSL_PORT",
|
||||
Property: "proxy-ssl-port",
|
||||
},
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerProxyIsEnabled prints true or false depending on whether the proxy is enabled
|
||||
func TriggerProxyIsEnabled(appName string) error {
|
||||
if IsAppProxyEnabled(appName) {
|
||||
@@ -22,3 +63,22 @@ func TriggerProxyType(appName string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// TriggerPostAppCloneSetup creates new proxy files
|
||||
func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error {
|
||||
return common.PropertyClone("proxy", oldAppName, newAppName)
|
||||
}
|
||||
|
||||
// TriggerPostAppRenameSetup renames proxy files
|
||||
func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error {
|
||||
if err := common.PropertyClone("proxy", oldAppName, newAppName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return common.PropertyDestroy("proxy", oldAppName)
|
||||
}
|
||||
|
||||
// TriggerPostDelete destroys the proxy property for a given app container
|
||||
func TriggerPostDelete(appName string) error {
|
||||
return common.PropertyDestroy("proxy", appName)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user