nginx-vhosts rewrite
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/checks/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
APP="$1"; DOKKU_APP_CONTAINER_ID="$2"; DOKKU_APP_CONTAINER_TYPE="$3"; DOKKU_APP_LISTEN_PORT="$4"; DOKKU_APP_LISTEN_IP="$5"
|
||||
@@ -55,6 +56,11 @@ fi
|
||||
eval "$(config_export global)"
|
||||
eval "$(config_export app $APP)"
|
||||
|
||||
if [[ "$(is_app_checks_enabled $APP)" == "false" ]];then
|
||||
dokku_log_info2_quiet "Zero downtime checks for app ($APP) have been disabled. moving on..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Wait this many seconds (default 5) for server to start before running checks.
|
||||
WAIT="${DOKKU_CHECKS_WAIT:-5}"
|
||||
# Wait this many seconds (default 30) for each response.
|
||||
@@ -80,11 +86,6 @@ cleanup() {
|
||||
trap cleanup EXIT
|
||||
|
||||
if [[ ! -s "${TMPDIR}/CHECKS" ]] || [[ "$DOKKU_APP_CONTAINER_TYPE" != "web" ]]; then
|
||||
if [[ "$DOKKU_SKIP_DEFAULT_CHECKS" = "true" ]]; then
|
||||
dokku_log_verbose "Skipping default check..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# We allow custom check for web instances only
|
||||
if [[ "$DOKKU_APP_CONTAINER_TYPE" == "web" ]]; then
|
||||
dokku_log_verbose "For more efficient zero downtime deployments, create a file CHECKS."
|
||||
|
||||
75
plugins/checks/commands
Executable file
75
plugins/checks/commands
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
[[ " checks checks:enable checks:disable help ps:help " == *" $1 "* ]] || exit $DOKKU_NOT_IMPLEMENTED_EXIT
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/checks/functions"
|
||||
|
||||
checks_main() {
|
||||
local desc="displays app zero-downtime status"
|
||||
local ALL_APPS=$(dokku_apps)
|
||||
if [[ -n "$1" ]]; then
|
||||
local APP="$1"
|
||||
fi
|
||||
local APPS=${APP:="$ALL_APPS"}
|
||||
|
||||
dokku_col_log_info1_quiet "App Name" "Zero-Downtime Status"
|
||||
for app in $APPS; do
|
||||
verify_app_name "$app"
|
||||
dokku_col_log_msg "$app" "$(is_app_checks_enabled $app)"
|
||||
done
|
||||
}
|
||||
|
||||
checks_enable() {
|
||||
local desc="enable zero-downtime for app"
|
||||
local APP="$1"; verify_app_name "$APP"
|
||||
|
||||
if [[ "$(is_app_checks_enabled $APP)" == "false" ]]; then
|
||||
dokku_log_info1 "Enabling zero downtime for app ($APP)"
|
||||
[[ "$2" == "--no-restart" ]] && local CONFIG_SET_ARGS=$2
|
||||
config_set $CONFIG_SET_ARGS $APP DOKKU_CHECKS_ENABLED=1
|
||||
else
|
||||
dokku_log_info1 "zero downtime is already enabled for app ($APP)"
|
||||
fi
|
||||
}
|
||||
|
||||
checks_disable() {
|
||||
local desc="disable zero-downtime for app"
|
||||
local APP="$1"; verify_app_name "$APP"
|
||||
|
||||
if [[ "$(is_app_checks_enabled $APP)" == "true" ]]; then
|
||||
dokku_log_info1 "Disabling zero downtime for app ($APP)"
|
||||
[[ "$2" == "--no-restart" ]] && local CONFIG_SET_ARGS=$2
|
||||
config_set $CONFIG_SET_ARGS $APP DOKKU_CHECKS_ENABLED=0
|
||||
else
|
||||
dokku_log_info1 "zero downtime is already disable for app ($APP)"
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
checks)
|
||||
checks_main $2
|
||||
;;
|
||||
|
||||
checks:enable)
|
||||
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||
checks_enable $2 --no-restart
|
||||
;;
|
||||
|
||||
checks:disable)
|
||||
[[ -z $2 ]] && dokku_log_fail "Please specify an app to run the command on"
|
||||
checks_disable $2 --no-restart
|
||||
;;
|
||||
|
||||
help | ps:help)
|
||||
cat<<EOF
|
||||
checks <app>, Show zero-downtime status
|
||||
checks:enable <app>, Enable zero-downtime checks
|
||||
checks:disable <app>, Disable zero-downtime checks
|
||||
EOF
|
||||
;;
|
||||
|
||||
*)
|
||||
exit $DOKKU_NOT_IMPLEMENTED_EXIT
|
||||
;;
|
||||
|
||||
esac
|
||||
18
plugins/checks/functions
Executable file
18
plugins/checks/functions
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
is_app_checks_enabled() {
|
||||
local desc="return app zero-downtime checks status"
|
||||
local APP="$1"; verify_app_name "$APP"
|
||||
local DOKKU_CHECKS_ENABLED=$(config_get $APP DOKKU_CHECKS_ENABLED)
|
||||
|
||||
if [[ -z "$DOKKU_CHECKS_ENABLED" ]] || [[ "$DOKKU_CHECKS_ENABLED" == "1" ]];then
|
||||
local status=true
|
||||
else
|
||||
local status=false
|
||||
fi
|
||||
|
||||
echo $status
|
||||
}
|
||||
40
plugins/checks/install
Executable file
40
plugins/checks/install
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
migrate_checks_vars() {
|
||||
local APPS="$(dokku_apps)"
|
||||
local GLOBAL_SKIP_ALL_CHECKS=$(dokku config:get --global DOKKU_SKIP_ALL_CHECKS || true)
|
||||
local GLOBAL_SKIP_DEFAULT_CHECKS=$(dokku config:get --global DOKKU_SKIP_DEFAULT_CHECKS || true)
|
||||
|
||||
local app
|
||||
|
||||
dokku_log_info1 "Migrating zero downtime env variables. The following variables have been deprecated"
|
||||
dokku_log_info2 "DOKKU_SKIP_ALL_CHECKS DOKKU_SKIP_DEFAULT_CHECKS"
|
||||
dokku_log_info2 "Please use dokku checks:[disable|enable] <app> to control zero downtime functionality"
|
||||
|
||||
for app in $APPS; do
|
||||
local APP_SKIP_ALL_CHECKS=$(dokku config:get $app DOKKU_SKIP_ALL_CHECKS || true)
|
||||
local APP_SKIP_DEFAULT_CHECKS=$(dokku config:get $app DOKKU_SKIP_DEFAULT_CHECKS || true)
|
||||
|
||||
if [[ "$APP_SKIP_ALL_CHECKS" == "true" ]] || [[ "$APP_SKIP_DEFAULT_CHECKS" == "true" ]] || \
|
||||
[[ "$GLOBAL_SKIP_ALL_CHECKS" == "true" ]] || [[ "$GLOBAL_SKIP_DEFAULT_CHECKS" == "true" ]]; then
|
||||
dokku_log_info2 ""
|
||||
dokku_log_info2 "zero downtime disabled for app ($app)"
|
||||
config_set --no-restart $app DOKKU_CHECKS_ENABLED=0
|
||||
fi
|
||||
if [[ -n "$APP_SKIP_ALL_CHECKS" ]] || [[ -n "$APP_SKIP_DEFAULT_CHECKS" ]]; then
|
||||
config_unset --no-restart $app DOKKU_SKIP_ALL_CHECKS DOKKU_SKIP_DEFAULT_CHECKS
|
||||
fi
|
||||
dokku_log_info2 "Migration complete"
|
||||
dokku_log_info2 ""
|
||||
done
|
||||
|
||||
if [[ -n "$GLOBAL_SKIP_ALL_CHECKS" ]] || [[ -n "$GLOBAL_SKIP_DEFAULT_CHECKS" ]]; then
|
||||
dokku_log_info1 "Removing global zero downtime settings"
|
||||
config_unset --global DOKKU_SKIP_ALL_CHECKS DOKKU_SKIP_DEFAULT_CHECKS
|
||||
fi
|
||||
}
|
||||
|
||||
migrate_checks_vars "$@"
|
||||
@@ -1,4 +1,4 @@
|
||||
[plugin]
|
||||
description = "dokku core checks plugin"
|
||||
version = "0.4.0"
|
||||
version = "0.5.0"
|
||||
[plugin.config]
|
||||
|
||||
Reference in New Issue
Block a user