Merge pull request #5604 from dokku/faster-nginx-rebuild

Trigger nginx proxy rebuild early to avoid downtime if deploying large numbers of processes
This commit is contained in:
josegonzalez
2023-01-23 16:13:31 -05:00
committed by GitHub
7 changed files with 64 additions and 14 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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 "$@"

View File

@@ -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

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"