refactor: remove special env override from schema

EMQX_NODE_NAME and EMQX_NODE_COOKIE are translated into
EMQX_NODE__NAME and EMQX_NODE__COOKIE
This commit is contained in:
Zaiming (Stone) Shi 2021-12-03 20:33:39 +01:00
parent 2a3f58f8ed
commit a681079ba7
2 changed files with 17 additions and 9 deletions

View File

@ -257,14 +257,12 @@ fields("node") ->
[ {"name", [ {"name",
sc(string(), sc(string(),
#{ default => "emqx@127.0.0.1" #{ default => "emqx@127.0.0.1"
, override_env => "EMQX_NODE_NAME"
})} })}
, {"cookie", , {"cookie",
sc(string(), sc(string(),
#{ mapping => "vm_args.-setcookie", #{ mapping => "vm_args.-setcookie",
default => "emqxsecretcookie", default => "emqxsecretcookie",
sensitive => true, sensitive => true
override_env => "EMQX_NODE_COOKIE"
})} })}
, {"data_dir", , {"data_dir",
sc(string(), sc(string(),

View File

@ -454,18 +454,23 @@ case "${COMMAND}" in
;; ;;
esac esac
## make EMQX_NODE_COOKIE right
if [ -n "${EMQX_NODE_NAME:-}" ]; then
export EMQX_NODE__NAME="${EMQX_NODE_NAME}"
unset EMQX_NODE_NAME
fi
## Possible ways to configure emqx node name: ## Possible ways to configure emqx node name:
## 1. configure node.name in emqx.conf ## 1. configure node.name in emqx.conf
## 2. override with environment variable EMQX_NODE_NAME ## 2. override with environment variable EMQX_NODE__NAME
## Node name is either short-name (without '@'), e.g. 'emqx' ## Node name is either short-name (without '@'), e.g. 'emqx'
## or long name (with '@') e.g. 'emqx@example.net' or 'emqx@127.0.0.1' ## or long name (with '@') e.g. 'emqx@example.net' or 'emqx@127.0.0.1'
NAME="${EMQX_NODE_NAME:-}" NAME="${EMQX_NODE__NAME:-}"
if [ -z "$NAME" ]; then if [ -z "$NAME" ]; then
if [ "$IS_BOOT_COMMAND" = 'yes' ]; then if [ "$IS_BOOT_COMMAND" = 'yes' ]; then
# for boot commands, inspect emqx.conf for node name # for boot commands, inspect emqx.conf for node name
NAME="$(call_hocon -s $SCHEMA_MOD -I "$CONFIGS_DIR/" -c "$RUNNER_ETC_DIR"/emqx.conf get node.name | tr -d \")" NAME="$(call_hocon -s $SCHEMA_MOD -I "$CONFIGS_DIR/" -c "$RUNNER_ETC_DIR"/emqx.conf get node.name | tr -d \")"
else else
vm_args_file="$(latest_vm_args 'EMQX_NODE_NAME')" vm_args_file="$(latest_vm_args 'EMQX_NODE__NAME')"
NAME="$(grep -E '^-s?name' "${vm_args_file}" | awk '{print $2}')" NAME="$(grep -E '^-s?name' "${vm_args_file}" | awk '{print $2}')"
fi fi
fi fi
@ -486,18 +491,23 @@ export ESCRIPT_NAME="$SHORT_NAME"
PIPE_DIR="${PIPE_DIR:-/$RUNNER_DATA_DIR/${WHOAMI}_erl_pipes/$NAME/}" PIPE_DIR="${PIPE_DIR:-/$RUNNER_DATA_DIR/${WHOAMI}_erl_pipes/$NAME/}"
COOKIE="${EMQX_NODE_COOKIE:-}" ## make EMQX_NODE_COOKIE right
if [ -n "${EMQX_NODE_COOKIE:-}" ]; then
export EMQX_NODE__COOKIE="${EMQX_NODE_COOKIE}"
unset EMQX_NODE_COOKIE
fi
COOKIE="${EMQX_NODE__COOKIE:-}"
if [ -z "$COOKIE" ]; then if [ -z "$COOKIE" ]; then
if [ "$IS_BOOT_COMMAND" = 'yes' ]; then if [ "$IS_BOOT_COMMAND" = 'yes' ]; then
COOKIE="$(call_hocon -s $SCHEMA_MOD -I "$CONFIGS_DIR/" -c "$RUNNER_ETC_DIR"/emqx.conf get node.cookie | tr -d \")" COOKIE="$(call_hocon -s $SCHEMA_MOD -I "$CONFIGS_DIR/" -c "$RUNNER_ETC_DIR"/emqx.conf get node.cookie | tr -d \")"
else else
vm_args_file="$(latest_vm_args 'EMQX_NODE_COOKIE')" vm_args_file="$(latest_vm_args 'EMQX_NODE__COOKIE')"
COOKIE="$(grep -E '^-setcookie' "${vm_args_file}" | awk '{print $2}')" COOKIE="$(grep -E '^-setcookie' "${vm_args_file}" | awk '{print $2}')"
fi fi
fi fi
if [ -z "$COOKIE" ]; then if [ -z "$COOKIE" ]; then
die "Please set node.cookie in $RUNNER_ETC_DIR/emqx.conf or override from environment variable EMQX_NODE_COOKIE" die "Please set node.cookie in $RUNNER_ETC_DIR/emqx.conf or override from environment variable EMQX_NODE__COOKIE"
fi fi
cd "$ROOTDIR" cd "$ROOTDIR"