From 70d2f24e1df4b336c1cb3a47bb78161ff250095a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 9 Mar 2025 07:38:49 -0400 Subject: [PATCH 1/2] feat: add ability to disable vhosts for all apps Closes #6967 --- docs/configuration/domains.md | 15 +++++++- docs/networking/proxies/nginx.md | 2 +- plugins/domains/functions | 53 ++++++++++++++++++++++++++++- plugins/domains/subcommands/clear | 9 ++--- plugins/domains/subcommands/disable | 4 +-- plugins/domains/subcommands/enable | 4 +-- 6 files changed, 73 insertions(+), 14 deletions(-) diff --git a/docs/configuration/domains.md b/docs/configuration/domains.md index ef815b620ee..71ac8a98fe4 100644 --- a/docs/configuration/domains.md +++ b/docs/configuration/domains.md @@ -33,7 +33,7 @@ If an FQDN such as `dokku.org` is used as the application name, the global virtu You can optionally override this in a plugin by implementing the `nginx-hostname` plugin trigger. If the `nginx-hostname` plugin has no output, the normal hostname algorithm will be executed. See the [plugin trigger documentation](/docs/development/plugin-triggers.md#nginx-hostname) for more information. -## Disabling VHOSTS +## Enabling and disabling VHOSTS If desired, it is possible to disable vhosts with the domains plugin. @@ -41,8 +41,21 @@ If desired, it is possible to disable vhosts with the domains plugin. dokku domains:disable node-js-app ``` +Vhosts can also be disabled for all apps: + +```shell +dokku domains:disable --all +``` + On subsequent deploys, the nginx virtualhost will be discarded. This is useful when deploying internal-facing services that should not be publicly routeable. As of 0.4.0, nginx will still be configured to proxy your app on some random high port. This allows internal services to maintain the same port between deployments. You may change this port by setting `DOKKU_PROXY_PORT` and/or `DOKKU_PROXY_SSL_PORT` (for services configured to use SSL.) +To re-enable, run the `domains:enable` subcommand: + +```shell +dokku domains:enable node-js-app +dokku domains:enable --all +``` + The domains plugin allows you to specify custom domains for applications. This plugin is aware of any ssl certificates that are imported via `certs:add`. Be aware that disabling domains (with `domains:disable`) will override any custom domains. ```shell diff --git a/docs/networking/proxies/nginx.md b/docs/networking/proxies/nginx.md index 06222411654..ed1d64d4791 100644 --- a/docs/networking/proxies/nginx.md +++ b/docs/networking/proxies/nginx.md @@ -487,7 +487,7 @@ See the [customizing hostnames documentation](/docs/configuration/domains.md#cus ### Disabling VHOSTS -See the [disabling vhosts documentation](/docs/configuration/domains.md#disabling-vhosts) for more information on how to disable domain usage for your app. +See the [enabling and disabling vhosts documentation](/docs/configuration/domains.md#enabling-and-disabling-vhosts) for more information on how to disable domain usage for your app. ### SSL Configuration diff --git a/plugins/domains/functions b/plugins/domains/functions index 9241c70529d..77130383203 100755 --- a/plugins/domains/functions +++ b/plugins/domains/functions @@ -4,6 +4,57 @@ source "$PLUGIN_AVAILABLE_PATH/config/functions" set -eo pipefail [[ $DOKKU_TRACE ]] && set -x +fn-domains-clear() { + declare desc="clear all domains for one or more apps" + declare APP="$1" + + if [[ "$APP" == "--all" ]]; then + for APP in $(dokku_apps); do + fn-domains-clear-app "$APP" + done + else + fn-domains-clear-app "$APP" + fi +} + +fn-domains-clear-app() { + declare desc="clear all domains for an app" + declare APP="$1" + + local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" + + rm -f "$APP_VHOST_PATH" + domains_setup "$APP" + plugn trigger post-domains-update "$APP" "clear" + dokku_log_info1 "Cleared domains in $APP" +} + +fn-domains-disable() { + declare desc="disable domains/VHOST support" + declare APP="$1" + + if [[ "$APP" == "--all" ]]; then + for APP in $(dokku_apps); do + domains_disable "$APP" + done + else + domains_disable "$APP" + fi +} + +fn-domains-enable() { + declare desc="enable domains/VHOST support" + declare APP="$1" + + if [[ "$APP" == "--all" ]]; then + for APP in $(dokku_apps); do + domains_enable "$APP" + done + else + domains_enable "$APP" + fi +} + disable_app_vhost() { declare desc="disable vhost support for given application" declare APP=$1 RESTART_APP="$2" @@ -110,7 +161,7 @@ domains_disable() { touch "$APP_VHOST_PATH" if [[ "$(is_app_vhost_enabled "$APP")" == "true" ]]; then - disable_app_vhost "$APP" + disable_app_vhost "$APP" --no-restart else dokku_log_info1 "Domains (VHOST) support is already disabled for app ($APP)" fi diff --git a/plugins/domains/subcommands/clear b/plugins/domains/subcommands/clear index c0e7a6bce89..c6065abb2a6 100755 --- a/plugins/domains/subcommands/clear +++ b/plugins/domains/subcommands/clear @@ -10,13 +10,8 @@ cmd-domains-clear() { [[ "$1" == "$cmd" ]] && shift 1 declare APP="$1" - verify_app_name "$APP" - local APP_VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" - - rm -f "$APP_VHOST_PATH" - domains_setup "$APP" - plugn trigger post-domains-update "$APP" "clear" - dokku_log_info1 "Cleared domains in $APP" + [[ "$APP" == "--all" ]] || verify_app_name "$APP" + fn-domains-clear "$APP" } cmd-domains-clear "$@" diff --git a/plugins/domains/subcommands/disable b/plugins/domains/subcommands/disable index d0750a312b8..69b14b52843 100755 --- a/plugins/domains/subcommands/disable +++ b/plugins/domains/subcommands/disable @@ -10,8 +10,8 @@ cmd-domains-disable() { [[ "$1" == "$cmd" ]] && shift 1 declare APP="$1" - verify_app_name "$APP" - domains_disable "$APP" + [[ "$APP" == "--all" ]] && verify_app_name "$APP" + fn-domains-disable "$APP" } cmd-domains-disable "$@" diff --git a/plugins/domains/subcommands/enable b/plugins/domains/subcommands/enable index 90336df4a71..d996db25a12 100755 --- a/plugins/domains/subcommands/enable +++ b/plugins/domains/subcommands/enable @@ -10,8 +10,8 @@ cmd-domains-enable() { [[ "$1" == "$cmd" ]] && shift 1 declare APP="$1" - verify_app_name "$APP" - domains_enable "$APP" + [[ "$APP" == "--all" ]] && verify_app_name "$APP" + fn-domains-enable "$APP" } cmd-domains-enable "$@" From c5847184c090127678824eafb0308393216e5a7d Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 10 Mar 2025 12:50:25 -0400 Subject: [PATCH 2/2] fix: call post-domains-update when domains are enabled/disabled for an app --- plugins/domains/functions | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/domains/functions b/plugins/domains/functions index 77130383203..0798f48f32f 100755 --- a/plugins/domains/functions +++ b/plugins/domains/functions @@ -68,6 +68,9 @@ disable_app_vhost() { [[ "$RESTART_APP" == "--no-restart" ]] && local CONFIG_SET_ARGS=$RESTART_APP DOKKU_QUIET_OUTPUT=1 config_set $CONFIG_SET_ARGS $APP NO_VHOST=1 + if [[ "$RESTART_APP" == "--no-restart" ]]; then + plugn trigger post-domains-update "$APP" "disable" + fi } domains_setup() { @@ -247,6 +250,9 @@ enable_app_vhost() { plugn trigger pre-enable-vhost "$APP" [[ "$RESTART_APP" == "--no-restart" ]] && local CONFIG_SET_ARGS=$RESTART_APP DOKKU_QUIET_OUTPUT=1 config_set $CONFIG_SET_ARGS "$APP" NO_VHOST=0 + if [[ "$RESTART_APP" == "--no-restart" ]]; then + plugn trigger post-domains-update "$APP" "enable" + fi } get_app_domains() {