Merge pull request #6468 from dokku/global-proxy-type
Implement global support for setting proxy type
This commit is contained in:
@@ -9,13 +9,39 @@ proxy:clear-config [--all|<app>] # Clears config for given app
|
||||
proxy:disable [--parallel count] [--all|<app>] # Disable proxy for app
|
||||
proxy:enable [--parallel count] [--all|<app>] # Enable proxy for app
|
||||
proxy:report [<app>] [<flag>] # Displays a proxy report for one or more apps
|
||||
proxy:set <app> <proxy-type> # Set proxy type for app
|
||||
proxy:set [<app>|--global] <proxy-type> # Set proxy type for app
|
||||
```
|
||||
|
||||
In Dokku 0.5.0, port proxying was decoupled from the `nginx-vhosts` plugin into the proxy plugin. Dokku 0.6.0 introduced the ability to map host ports to specific container ports. In the future this will allow other proxy software - such as HAProxy or Caddy - to be used in place of nginx.
|
||||
|
||||
## Usage
|
||||
|
||||
### Changing the proxy
|
||||
|
||||
The default proxy shipped with Dokku is `nginx`. It can be changed via the `proxy:set` command.
|
||||
|
||||
```shell
|
||||
dokku proxy:set node-js-app caddy
|
||||
```
|
||||
|
||||
```
|
||||
-----> Setting config vars
|
||||
DOKKU_APP_PROXY_TYPE: caddy
|
||||
```
|
||||
|
||||
The proxy may also be set on a global basis. This is usually preferred as running multiple proxy implementations may cause port collision issues.
|
||||
|
||||
```shell
|
||||
dokku proxy:set --global caddy
|
||||
```
|
||||
|
||||
```
|
||||
-----> Setting config vars
|
||||
DOKKU_PROXY_TYPE: caddy
|
||||
```
|
||||
|
||||
Changing the proxy does not stop or start any given proxy implementation. Please see the documentation for your proxy implementation for details on how to perform a change.
|
||||
|
||||
### Regenerating proxy config
|
||||
|
||||
In certain cases, your app proxy configs may drift from the correct config for your app. You may regenerate the config at any point via the `proxy:build-config` command. This command will trigger a rebuild for the configured proxy implementation (default: nginx) for a given app. The command may fail if there are no current web listeners for your app.
|
||||
|
||||
@@ -5,5 +5,18 @@ import (
|
||||
)
|
||||
|
||||
func getAppProxyType(appName string) string {
|
||||
return config.GetWithDefault(appName, "DOKKU_APP_PROXY_TYPE", "nginx")
|
||||
return config.GetWithDefault(appName, "DOKKU_APP_PROXY_TYPE", "")
|
||||
}
|
||||
|
||||
func getComputedProxyType(appName string) string {
|
||||
proxyType := getAppProxyType(appName)
|
||||
if proxyType == "" {
|
||||
proxyType = getGlobalProxyType()
|
||||
}
|
||||
|
||||
return proxyType
|
||||
}
|
||||
|
||||
func getGlobalProxyType() string {
|
||||
return config.GetWithDefault("--global", "DOKKU_PROXY_TYPE", "nginx")
|
||||
}
|
||||
|
||||
@@ -11,8 +11,10 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
||||
}
|
||||
|
||||
flags := map[string]common.ReportFunc{
|
||||
"--proxy-enabled": reportEnabled,
|
||||
"--proxy-type": reportType,
|
||||
"--proxy-enabled": reportEnabled,
|
||||
"--proxy-computed-type": reportComputedType,
|
||||
"--proxy-global-type": reportGlobalType,
|
||||
"--proxy-type": reportType,
|
||||
}
|
||||
|
||||
flagKeys := []string{}
|
||||
@@ -35,6 +37,19 @@ func reportEnabled(appName string) string {
|
||||
return proxyEnabled
|
||||
}
|
||||
|
||||
func reportComputedType(appName string) string {
|
||||
proxyType := getGlobalProxyType()
|
||||
if proxyType == "" {
|
||||
proxyType = getAppProxyType(appName)
|
||||
}
|
||||
|
||||
return proxyType
|
||||
}
|
||||
|
||||
func reportGlobalType(appName string) string {
|
||||
return getGlobalProxyType()
|
||||
}
|
||||
|
||||
func reportType(appName string) string {
|
||||
return getAppProxyType(appName)
|
||||
}
|
||||
|
||||
@@ -56,9 +56,14 @@ func main() {
|
||||
}
|
||||
case "set":
|
||||
args := flag.NewFlagSet("proxy:set", flag.ExitOnError)
|
||||
global := args.Bool("global", false, "--global: set a global property")
|
||||
args.Parse(os.Args[2:])
|
||||
appName := args.Arg(0)
|
||||
proxyType := args.Arg(1)
|
||||
if *global {
|
||||
appName = "--global"
|
||||
proxyType = args.Arg(0)
|
||||
}
|
||||
err = proxy.CommandSet(appName, proxyType)
|
||||
default:
|
||||
err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
|
||||
|
||||
@@ -79,16 +79,22 @@ func CommandReport(appName string, format string, infoFlag string) error {
|
||||
|
||||
// CommandSet sets a proxy for an app
|
||||
func CommandSet(appName string, proxyType string) error {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
if appName != "--global" {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if len(proxyType) < 2 {
|
||||
return errors.New("Please specify a proxy type")
|
||||
}
|
||||
|
||||
key := "DOKKU_APP_PROXY_TYPE"
|
||||
if appName == "--global" {
|
||||
key = "DOKKU_PROXY_TYPE"
|
||||
}
|
||||
entries := map[string]string{
|
||||
"DOKKU_APP_PROXY_TYPE": proxyType,
|
||||
key: proxyType,
|
||||
}
|
||||
return config.SetMany(appName, entries, false)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func TriggerProxyIsEnabled(appName string) error {
|
||||
|
||||
// TriggerProxyType prints out the current proxy type, defaulting to nginx
|
||||
func TriggerProxyType(appName string) error {
|
||||
proxyType := getAppProxyType(appName)
|
||||
proxyType := getComputedProxyType(appName)
|
||||
fmt.Println(proxyType)
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user