From eaf0d9af55e47920b5a8d89e90d6848097b3bb9d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 29 Jun 2020 20:17:23 -0400 Subject: [PATCH] feat: create proxy:build-config command Closes #4024 --- docs/appendices/0.21.0-migration-guide.md | 1 + docs/configuration/nginx.md | 13 ++++--------- docs/networking/proxy-management.md | 9 +++++++++ plugins/nginx-vhosts/help-functions | 1 - plugins/nginx-vhosts/subcommands/build-config | 1 + plugins/proxy/Makefile | 2 +- plugins/proxy/src/commands/commands.go | 1 + plugins/proxy/src/subcommands/subcommands.go | 5 +++++ plugins/proxy/subcommands.go | 13 +++++++++++++ tests/unit/test_helper.bash | 2 +- 10 files changed, 36 insertions(+), 12 deletions(-) diff --git a/docs/appendices/0.21.0-migration-guide.md b/docs/appendices/0.21.0-migration-guide.md index ccdeb9122..2f16cdb6e 100644 --- a/docs/appendices/0.21.0-migration-guide.md +++ b/docs/appendices/0.21.0-migration-guide.md @@ -9,6 +9,7 @@ The `tls` name is no longer a reserved app name, and can be used by applications - `git#git_deploy_branch()` is deprecated in favor of `plugn trigger git-deploy-branch`. - The `config` command is deprecated in favor of `config:show`. - Usage of this command in conjunction with either the `--export` or `--shell` flag is deprecated in favor of `config:export --format` with the correct format value (`exports` or `shell`, respectively). +- The `nginx:build-config` command is deprecated in favor of `proxy:build-config`. ## Removals diff --git a/docs/configuration/nginx.md b/docs/configuration/nginx.md index 9bd4f6df6..c0dc6a9bb 100644 --- a/docs/configuration/nginx.md +++ b/docs/configuration/nginx.md @@ -4,7 +4,6 @@ Dokku uses nginx as its server for routing requests to specific applications. By ``` nginx:access-logs [-t] # Show the nginx access logs for an application (-t follows) -nginx:build-config # (Re)builds nginx config for given app nginx:error-logs [-t] # Show the nginx error logs for an application (-t follows) nginx:report [] [] # Displays a nginx report for one or more apps nginx:set () # Set or clear an nginx property for an app @@ -107,14 +106,6 @@ dokku nginx:set node-js-app error-log-path In all cases, the nginx config must be regenerated after setting the above values. -## Regenerating nginx config - -In certain cases, your app nginx configs may drift from the correct config for your app. You may regenerate the config at any point via the `nginx:build-config` command. This may fail if there are no current web listeners for your app. - -```shell -dokku nginx:build-config node-js-app -``` - ## Showing the nginx config For debugging purposes, it may be useful to show the nginx config. This can be achieved via the `nginx:show-config` command. @@ -296,3 +287,7 @@ See the [proxy documentation](/docs/advanced-usage/proxy-management.md) for more ## Managing Proxy Port mappings See the [proxy documentation](/docs/advanced-usage/proxy-management.md#proxy-port-mapping) for more information on how to manage ports proxied for your app. + +## Regenerating nginx config + +See the [proxy documentation](/docs/advanced-usage/proxy-management.md#regenerating-proxy-config) for more information on how to rebuild the nginx proxy configuration for your app. diff --git a/docs/networking/proxy-management.md b/docs/networking/proxy-management.md index 42d865082..1a8b24ae8 100644 --- a/docs/networking/proxy-management.md +++ b/docs/networking/proxy-management.md @@ -3,6 +3,7 @@ > New as of 0.5.0, Enhanced in 0.6.0 ``` +proxy:build-config # (Re)builds config for given app proxy:disable # Disable proxy for app proxy:enable # Enable proxy for app proxy:report [] [] # Displays a proxy report for one or more apps @@ -13,6 +14,14 @@ In Dokku 0.5.0, port proxying was decoupled from the `nginx-vhosts` plugin into ## Usage +### 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. + +```shell +dokku proxy:build-config node-js-app +``` + ### Container network interface binding > Changed as of 0.11.0 diff --git a/plugins/nginx-vhosts/help-functions b/plugins/nginx-vhosts/help-functions index e7efed5d5..ad8ba634b 100755 --- a/plugins/nginx-vhosts/help-functions +++ b/plugins/nginx-vhosts/help-functions @@ -28,7 +28,6 @@ fn-help-content() { declare desc="return help content" cat < [-t], Show the nginx access logs for an application (-t follows) - nginx:build-config , (Re)builds nginx config for given app nginx:error-logs [-t], Show the nginx error logs for an application (-t follows) nginx:report [] [], Displays an nginx report for one or more apps nginx:set (), Set or clear an nginx property for an app diff --git a/plugins/nginx-vhosts/subcommands/build-config b/plugins/nginx-vhosts/subcommands/build-config index 42c06e959..efcbb3b35 100755 --- a/plugins/nginx-vhosts/subcommands/build-config +++ b/plugins/nginx-vhosts/subcommands/build-config @@ -8,6 +8,7 @@ cmd-nginx-build-config() { declare cmd="nginx:build-config" [[ "$1" == "$cmd" ]] && shift 1 declare APP="$1" + dokku_log_warn "Deprecated: Please use proxy:build-config" [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" local PROXY_APP_TYPE diff --git a/plugins/proxy/Makefile b/plugins/proxy/Makefile index 0376ee9b4..ed3e6f036 100644 --- a/plugins/proxy/Makefile +++ b/plugins/proxy/Makefile @@ -1,4 +1,4 @@ -SUBCOMMANDS = subcommands/disable subcommands/enable subcommands/ports subcommands/ports-add subcommands/ports-clear subcommands/ports-remove subcommands/ports-set subcommands/report subcommands/set +SUBCOMMANDS = subcommands/build-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/post-certs-remove triggers/post-certs-update triggers/report BUILD = commands subcommands triggers PLUGIN_NAME = proxy diff --git a/plugins/proxy/src/commands/commands.go b/plugins/proxy/src/commands/commands.go index 894a9013e..d2622eb9b 100644 --- a/plugins/proxy/src/commands/commands.go +++ b/plugins/proxy/src/commands/commands.go @@ -18,6 +18,7 @@ Manage the proxy integration for an app Additional commands:` helpContent = ` + proxy:build-config , (Re)builds config for a given app proxy:disable , Disable proxy for app proxy:enable , Enable proxy for app proxy:ports , List proxy port mappings for app diff --git a/plugins/proxy/src/subcommands/subcommands.go b/plugins/proxy/src/subcommands/subcommands.go index bc2c49fa7..fa320b175 100644 --- a/plugins/proxy/src/subcommands/subcommands.go +++ b/plugins/proxy/src/subcommands/subcommands.go @@ -17,6 +17,11 @@ func main() { var err error switch subcommand { + case "build-config": + args := flag.NewFlagSet("proxy:build-config", flag.ExitOnError) + args.Parse(os.Args[2:]) + appName := args.Arg(0) + err = proxy.CommandBuildConfig(appName) case "disable": args := flag.NewFlagSet("proxy:disable", flag.ExitOnError) skipRestart := args.Bool("no-restart", false, "--no-restart: skip restart of the app") diff --git a/plugins/proxy/subcommands.go b/plugins/proxy/subcommands.go index 7252fb19d..9db5cfd24 100644 --- a/plugins/proxy/subcommands.go +++ b/plugins/proxy/subcommands.go @@ -8,6 +8,19 @@ import ( "github.com/dokku/dokku/plugins/config" ) +// CommandBuildConfig rebuilds config for a given app +func CommandBuildConfig(appName string) error { + if appName == "" { + return errors.New("Please specify an app to run the command on") + } + + if err := common.VerifyAppName(appName); err != nil { + return err + } + + return common.PlugnTrigger("proxy-build-config", []string{appName}...) +} + // CommandDisable disables the proxy for app via command line func CommandDisable(appName string, skipRestart bool) error { if appName == "" { diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 9e3535580..edf4994bb 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -453,7 +453,7 @@ EOF build_nginx_config() { # simulate nginx post-deploy dokku domains:setup "$TEST_APP" - dokku nginx:build-config "$TEST_APP" + dokku proxy:build-config "$TEST_APP" } create_network() {