fix(deploy): force staging=dev and production=main regardless of deploy.env
This commit is contained in:
+15
-6
@@ -48,14 +48,19 @@ load_env() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load_env
|
||||||
|
|
||||||
|
# CLI 覆盖 deploy.env(须在 load_env 之后解析)
|
||||||
|
CLI_ENV=""
|
||||||
|
CLI_BRANCH=""
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--env) DUKANG_DEPLOY_ENV="$2"; shift 2 ;;
|
--env) CLI_ENV="$2"; shift 2 ;;
|
||||||
--host) DEPLOY_HOST="$2"; shift 2 ;;
|
--host) DEPLOY_HOST="$2"; shift 2 ;;
|
||||||
--user) DEPLOY_USER="$2"; shift 2 ;;
|
--user) DEPLOY_USER="$2"; shift 2 ;;
|
||||||
--port) DEPLOY_PORT="$2"; shift 2 ;;
|
--port) DEPLOY_PORT="$2"; shift 2 ;;
|
||||||
--key) DEPLOY_SSH_KEY="$2"; shift 2 ;;
|
--key) DEPLOY_SSH_KEY="$2"; shift 2 ;;
|
||||||
--branch) GIT_BRANCH="$2"; shift 2 ;;
|
--branch) CLI_BRANCH="$2"; shift 2 ;;
|
||||||
--check) CHECK_ONLY=true; shift ;;
|
--check) CHECK_ONLY=true; shift ;;
|
||||||
-h|--help) usage; exit 0 ;;
|
-h|--help) usage; exit 0 ;;
|
||||||
--)
|
--)
|
||||||
@@ -67,11 +72,13 @@ while [[ $# -gt 0 ]]; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
load_env
|
if [[ -n "$CLI_ENV" ]]; then
|
||||||
|
DUKANG_DEPLOY_ENV="$CLI_ENV"
|
||||||
|
fi
|
||||||
|
|
||||||
# 兼容旧调用:未传 --env 时,若 GIT_BRANCH=main 视为生产,否则 staging
|
# 兼容旧调用:未传 --env 时,若 GIT_BRANCH=main 视为生产,否则 staging
|
||||||
if [[ -z "$DUKANG_DEPLOY_ENV" ]]; then
|
if [[ -z "$DUKANG_DEPLOY_ENV" ]]; then
|
||||||
if [[ "${GIT_BRANCH:-}" == "main" || "${GIT_BRANCH:-}" == "master" ]]; then
|
if [[ "${CLI_BRANCH:-${GIT_BRANCH:-}}" == "main" || "${CLI_BRANCH:-${GIT_BRANCH:-}}" == "master" ]]; then
|
||||||
DUKANG_DEPLOY_ENV=production
|
DUKANG_DEPLOY_ENV=production
|
||||||
else
|
else
|
||||||
DUKANG_DEPLOY_ENV=staging
|
DUKANG_DEPLOY_ENV=staging
|
||||||
@@ -96,7 +103,8 @@ if [[ "$DUKANG_DEPLOY_ENV" == "staging" ]]; then
|
|||||||
elif [[ "$APP_ROOT" == "/opt/dukang" ]]; then
|
elif [[ "$APP_ROOT" == "/opt/dukang" ]]; then
|
||||||
APP_ROOT="/opt/dukang-staging"
|
APP_ROOT="/opt/dukang-staging"
|
||||||
fi
|
fi
|
||||||
GIT_BRANCH="${GIT_BRANCH:-dev}"
|
# 测试固定默认 dev;CLI --branch 优先,忽略 deploy.env 里误配的 main
|
||||||
|
GIT_BRANCH="${CLI_BRANCH:-dev}"
|
||||||
PORT_GREP='819[0-4]'
|
PORT_GREP='819[0-4]'
|
||||||
else
|
else
|
||||||
APP_ROOT="${PROD_APP_ROOT:-${APP_ROOT:-/opt/dukang}}"
|
APP_ROOT="${PROD_APP_ROOT:-${APP_ROOT:-/opt/dukang}}"
|
||||||
@@ -105,7 +113,8 @@ else
|
|||||||
elif [[ "$APP_ROOT" == "/opt/dukang-staging" ]]; then
|
elif [[ "$APP_ROOT" == "/opt/dukang-staging" ]]; then
|
||||||
APP_ROOT="/opt/dukang"
|
APP_ROOT="/opt/dukang"
|
||||||
fi
|
fi
|
||||||
GIT_BRANCH="${GIT_BRANCH:-main}"
|
# 生产固定默认 main;CLI --branch 优先,忽略 deploy.env 里误配的 dev
|
||||||
|
GIT_BRANCH="${CLI_BRANCH:-main}"
|
||||||
PORT_GREP='809[0-4]'
|
PORT_GREP='809[0-4]'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user