From 348a593ee85221b501fce31c3d2a3a00cfb1fd33 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 27 Nov 2022 19:50:57 -0500 Subject: [PATCH] refactor trigger proxy-build-config from nginx#core-post-deploy This reduces the duplicated code in the plugin. --- plugins/nginx-vhosts/core-post-deploy | 15 +-------------- plugins/nginx-vhosts/proxy-build-config | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/plugins/nginx-vhosts/core-post-deploy b/plugins/nginx-vhosts/core-post-deploy index 00a9ceea1..5fdde3b94 100755 --- a/plugins/nginx-vhosts/core-post-deploy +++ b/plugins/nginx-vhosts/core-post-deploy @@ -14,20 +14,7 @@ trigger-nginx-vhosts-core-post-deploy() { return fi - HAS_NETWORK_CONFIG="$(plugn trigger network-config-exists "$APP")" - if [[ "$HAS_NETWORK_CONFIG" == "true" ]]; then - plugn trigger domains-setup "$APP" - nginx_build_config "$APP" - if [[ -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil.$DOKKU_PID" ]]; then - mv "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil.$DOKKU_PID" "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil" - fi - if [[ -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil.$DOKKU_PID.missing" ]]; then - rm -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil.$DOKKU_PID.missing" - rm -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil" - fi - else - nginx_clear_config "$APP" - fi + plugn trigger proxy-build-config "$APP" } trigger-nginx-vhosts-core-post-deploy "$@" diff --git a/plugins/nginx-vhosts/proxy-build-config b/plugins/nginx-vhosts/proxy-build-config index f69cb6447..4b860dad1 100755 --- a/plugins/nginx-vhosts/proxy-build-config +++ b/plugins/nginx-vhosts/proxy-build-config @@ -8,12 +8,28 @@ trigger-nginx-vhosts-proxy-build-config() { declare desc="build nginx config to proxy app containers from command line" declare trigger="proxy-build-config" declare APP="$1" + local HAS_NETWORK_CONFIG - [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on" - if [[ "$(plugn trigger proxy-type "$APP")" == "nginx" ]]; then + if [[ "$(plugn trigger proxy-type "$APP")" != "nginx" ]]; then + return + fi + + HAS_NETWORK_CONFIG="$(plugn trigger network-config-exists "$APP")" + if [[ "$HAS_NETWORK_CONFIG" == "true" ]]; then + plugn trigger domains-setup "$APP" plugn trigger network-build-config "$APP" nginx_build_config "$APP" + if [[ -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil.$DOKKU_PID" ]]; then + mv "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil.$DOKKU_PID" "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil" + fi + if [[ -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil.$DOKKU_PID.missing" ]]; then + rm -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil.$DOKKU_PID.missing" + rm -f "${DOKKU_LIB_ROOT}/data/nginx-vhosts/app-$APP/nginx.conf.sigil" + fi + else + nginx_clear_config "$APP" fi + } trigger-nginx-vhosts-proxy-build-config "$@"