diff --git a/plugins/common/common.go b/plugins/common/common.go index 091f15451..cfadb36fd 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -74,6 +74,29 @@ func CommandUsage(helpHeader string, helpContent string) { fmt.Println(columnize.Format(content, config)) } +// EnvWrap wraps a func with a setenv call and resets the value at the end +func EnvWrap(fn func() error, environ map[string]string) error { + oldEnviron := map[string]string{} + for key, value := range environ { + oldEnviron[key] = os.Getenv(key) + if err := os.Setenv(key, value); err != nil { + return err + } + } + + if err := fn(); err != nil { + return err + } + + for key, value := range oldEnviron { + if err := os.Setenv(key, value); err != nil { + return err + } + } + + return nil +} + // GetAppScheduler fetches the scheduler for a given application func GetAppScheduler(appName string) string { appScheduler := "" @@ -308,7 +331,10 @@ func IsDeployed(appName string) bool { deployed = "true" } - CommandPropertySet("common", appName, "deployed", deployed, DefaultProperties, GlobalProperties) + EnvWrap(func() error { + CommandPropertySet("common", appName, "deployed", deployed, DefaultProperties, GlobalProperties) + return nil + }, map[string]string{"DOKKU_QUIET_OUTPUT": "1"}) } return deployed == "true" diff --git a/plugins/common/triggers.go b/plugins/common/triggers.go index e904c525a..813a22d45 100644 --- a/plugins/common/triggers.go +++ b/plugins/common/triggers.go @@ -2,7 +2,6 @@ package common import ( "fmt" - "os" ) // TriggerAppList outputs each app name to stdout on a newline @@ -23,11 +22,10 @@ func TriggerAppList(filtered bool) error { // TriggerCorePostDeploy associates the container with a specified network func TriggerCorePostDeploy(appName string) error { - quiet := os.Getenv("DOKKU_QUIET_OUTPUT") - os.Setenv("DOKKU_QUIET_OUTPUT", "1") - CommandPropertySet("common", appName, "deployed", "true", DefaultProperties, GlobalProperties) - os.Setenv("DOKKU_QUIET_OUTPUT", quiet) - return nil + return EnvWrap(func() error { + CommandPropertySet("common", appName, "deployed", "true", DefaultProperties, GlobalProperties) + return nil + }, map[string]string{"DOKKU_QUIET_OUTPUT": "1"}) } // TriggerInstall runs the install step for the common plugin diff --git a/plugins/nginx-vhosts/scheduler-post-deploy-process b/plugins/nginx-vhosts/scheduler-post-deploy-process new file mode 100755 index 000000000..2d2be1d3a --- /dev/null +++ b/plugins/nginx-vhosts/scheduler-post-deploy-process @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" +source "$PLUGIN_AVAILABLE_PATH/nginx-vhosts/functions" + +trigger-nginx-vhosts-scheduler-post-deploy-process() { + declare desc="nginx-vhosts scheduler-post-deploy-process plugin trigger" + declare trigger="scheduler-post-deploy-process" + declare APP="$1" PROCESS_TYPE="$2" + + if [[ "$PROCESS_TYPE" != "web" ]]; then + return + fi + + if [[ "$(plugn trigger proxy-type "$APP")" != "nginx" ]]; then + return + fi + + dokku_log_info2 "Triggering early nginx proxy rebuild" + plugn trigger proxy-build-config "$APP" +} + +trigger-nginx-vhosts-scheduler-post-deploy-process "$@" diff --git a/plugins/scheduler-docker-local/bin/scheduler-deploy-process b/plugins/scheduler-docker-local/bin/scheduler-deploy-process index 32f86f263..27d59889e 100755 --- a/plugins/scheduler-docker-local/bin/scheduler-deploy-process +++ b/plugins/scheduler-docker-local/bin/scheduler-deploy-process @@ -51,6 +51,8 @@ main() { PARALLEL_DEPLOY_COUNT="$(plugn trigger "app-json-process-deploy-parallelism" "$APP" "$PROC_TYPE")" DOKKU_CHECKS_DISABLED="$DOKKU_CHECKS_DISABLED" INJECT_INIT_FLAG="$INJECT_INIT_FLAG" parallel --will-cite --halt soon,fail=1 --jobs "$PARALLEL_DEPLOY_COUNT" --ungroup <"$PROCESS_TMP_FILE" + plugn trigger scheduler-post-deploy-process "$APP" "$PROC_TYPE" + # cleanup when we scale down if [[ "$PROC_COUNT" == 0 ]]; then local CONTAINER_IDX_OFFSET=0 diff --git a/tests/unit/nginx-vhosts_11.bats b/tests/unit/nginx-vhosts_11.bats index dab13fb79..7bf263dfe 100644 --- a/tests/unit/nginx-vhosts_11.bats +++ b/tests/unit/nginx-vhosts_11.bats @@ -178,7 +178,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output_contains "Overriding default nginx.conf with detected nginx.conf.sigil" + assert_output_contains "Overriding default nginx.conf with detected nginx.conf.sigil" 2 mv "$CUSTOM_TMP/nginx.conf.sigil" "$CUSTOM_TMP/nginx.conf.sigil-2" @@ -207,7 +207,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output_contains "Overriding default nginx.conf with detected nginx.conf.sigil" + assert_output_contains "Overriding default nginx.conf with detected nginx.conf.sigil" 2 popd rm -rf "$TMP" diff --git a/tests/unit/nginx-vhosts_12.bats b/tests/unit/nginx-vhosts_12.bats index 1fd0fd2d3..159526f6b 100644 --- a/tests/unit/nginx-vhosts_12.bats +++ b/tests/unit/nginx-vhosts_12.bats @@ -56,7 +56,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output_contains "Overriding default nginx.conf with detected nginx.conf.sigil" + assert_output_contains "Overriding default nginx.conf with detected nginx.conf.sigil" 2 run /bin/bash -c "dokku nginx:set --global nginx-conf-sigil-path dokku/nginx.conf.sigil" echo "output: $output" @@ -103,7 +103,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output_contains "Overriding default nginx.conf with detected nginx.conf.sigil" + assert_output_contains "Overriding default nginx.conf with detected nginx.conf.sigil" 2 run /bin/bash -c "dokku nginx:set --global nginx-conf-sigil-path" echo "output: $output" @@ -125,7 +125,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output_contains "Overriding default nginx.conf with detected nginx.conf.sigil" + assert_output_contains "Overriding default nginx.conf with detected nginx.conf.sigil" 2 run /bin/bash -c "docker image rm dokku-test/$TEST_APP:latest dokku-test/$TEST_APP:v2" echo "output: $output" diff --git a/tests/unit/nginx-vhosts_6.bats b/tests/unit/nginx-vhosts_6.bats index 0e01a5b3e..5af64cdc9 100644 --- a/tests/unit/nginx-vhosts_6.bats +++ b/tests/unit/nginx-vhosts_6.bats @@ -30,7 +30,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output_contains "Enabling HSTS" + assert_output_contains "Enabling HSTS" 2 run /bin/bash -c "test -f $HSTS_CONF" echo "output: $output" @@ -113,7 +113,7 @@ teardown() { echo "output: $output" echo "status: $status" assert_success - assert_output_contains "Enabling HSTS" + assert_output_contains "Enabling HSTS" 2 # disable hsts globally run /bin/bash -c "dokku nginx:set --global hsts false"