feat: implement global support for setting proxy type

This commit is contained in:
Jose Diaz-Gonzalez committed 2024-01-19 06:31:19 -05:00
1 parent ea28367689
commit 7fbb86093b
6 files changed
+73 -8

No files matched your search

+27 -1
View File
@@ -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:disable [--parallel count] [--all|<app>] # Disable proxy for app
proxy:enable [--parallel count] [--all|<app>] # Enable 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: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. 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 ## 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 ### 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. 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.
+14 -1
View File
@@ -5,5 +5,18 @@ import (
) )
func getAppProxyType(appName string) string { 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 := getGlobalProxyType()
if proxyType == "" {
proxyType = getAppProxyType(appName)
}
return proxyType
}
func getGlobalProxyType() string {
return config.GetWithDefault("--global", "DOKKU_PROXY_TYPE", "nginx")
} }
+17 -2
View File
@@ -11,8 +11,10 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
} }
flags := map[string]common.ReportFunc{ flags := map[string]common.ReportFunc{
"--proxy-enabled": reportEnabled, "--proxy-enabled": reportEnabled,
"--proxy-type": reportType, "--proxy-computed-type": reportComputedType,
"--proxy-global-type": reportGlobalType,
"--proxy-type": reportType,
} }
flagKeys := []string{} flagKeys := []string{}
@@ -35,6 +37,19 @@ func reportEnabled(appName string) string {
return proxyEnabled 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 { func reportType(appName string) string {
return getAppProxyType(appName) return getAppProxyType(appName)
} }
@@ -56,9 +56,14 @@ func main() {
} }
case "set": case "set":
args := flag.NewFlagSet("proxy:set", flag.ExitOnError) args := flag.NewFlagSet("proxy:set", flag.ExitOnError)
global := args.Bool("global", false, "--global: set a global property")
args.Parse(os.Args[2:]) args.Parse(os.Args[2:])
appName := args.Arg(0) appName := args.Arg(0)
proxyType := args.Arg(1) proxyType := args.Arg(1)
if *global {
appName = "--global"
proxyType = args.Arg(0)
}
err = proxy.CommandSet(appName, proxyType) err = proxy.CommandSet(appName, proxyType)
default: default:
err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand) err = fmt.Errorf("Invalid plugin subcommand call: %s", subcommand)
+9 -3
View File
@@ -79,16 +79,22 @@ func CommandReport(appName string, format string, infoFlag string) error {
// CommandSet sets a proxy for an app // CommandSet sets a proxy for an app
func CommandSet(appName string, proxyType string) error { func CommandSet(appName string, proxyType string) error {
if err := common.VerifyAppName(appName); err != nil { if appName != "--global" {
return err if err := common.VerifyAppName(appName); err != nil {
return err
}
} }
if len(proxyType) < 2 { if len(proxyType) < 2 {
return errors.New("Please specify a proxy type") return errors.New("Please specify a proxy type")
} }
key := "DOKKU_APP_PROXY_TYPE"
if appName == "--global" {
key = "DOKKU_PROXY_TYPE"
}
entries := map[string]string{ entries := map[string]string{
"DOKKU_APP_PROXY_TYPE": proxyType, key: proxyType,
} }
return config.SetMany(appName, entries, false) return config.SetMany(appName, entries, false)
} }
+1 -1
View File
@@ -17,7 +17,7 @@ func TriggerProxyIsEnabled(appName string) error {
// TriggerProxyType prints out the current proxy type, defaulting to nginx // TriggerProxyType prints out the current proxy type, defaulting to nginx
func TriggerProxyType(appName string) error { func TriggerProxyType(appName string) error {
proxyType := getAppProxyType(appName) proxyType := getComputedProxyType(appName)
fmt.Println(proxyType) fmt.Println(proxyType)
return nil return nil