Files
2026-03-29 09:08:01 +08:00

93 lines
2.7 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 真机一键验收入口:可选铺栈 + 矩阵全量验收verify.sh full
# 默认:只做验收(不强制重装/重铺栈),避免误伤现有环境。
#
# 开关(环境变量):
# ACCEPT_DEPLOY=1 先执行 deploy-lab默认 0
# ACCEPT_DEPLOY_K3S=1 部署/复验 K3s默认 1仅在 ACCEPT_DEPLOY=1 时生效)
# ACCEPT_DEPLOY_LONGHORN=1 部署 Longhorn默认 0
# ACCEPT_DEPLOY_NGINX_MATRIX=1 部署 nginx 矩阵(默认 0
# ACCEPT_DEPLOY_NGINX_MATRIX_TLS=1 部署 TLS nginx 矩阵(默认 0
# VERIFY_TEARDOWN=1 验收后清理临时资源(沿用 verify.sh 默认;可设 0 保留现场)
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
load_env() {
if [[ -f "${ROOT}/ansible/env/.env.verify" ]]; then
set -a
# shellcheck disable=SC1091
source "${ROOT}/ansible/env/.env.verify"
set +a
echo "[OK] 已加载 ansible/env/.env.verify"
fi
}
usage() {
cat <<'EOF'
用法scripts/acceptance.sh
说明:
- 真机「一键验收」可选先铺栈deploy-lab再跑矩阵全量验收verify.sh full
- 默认不铺栈(避免误改现网);只执行 ./ansible/bin/verify.sh full
常用示例:
# 只验收(推荐默认)
./scripts/acceptance.sh
# 先复验/安装 K3s再全量验收
ACCEPT_DEPLOY=1 ./scripts/acceptance.sh
# 铺栈K3s + Longhorn + nginx-matrix然后全量验收
ACCEPT_DEPLOY=1 ACCEPT_DEPLOY_LONGHORN=1 ACCEPT_DEPLOY_NGINX_MATRIX=1 ./scripts/acceptance.sh
# 验收不清理(保留现场排障)
VERIFY_TEARDOWN=0 ./scripts/acceptance.sh
EOF
}
need_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "[ERR] 未找到命令:$1" >&2
exit 1
fi
}
main() {
load_env
local cmd="${1:-}"
case "$cmd" in
"" ) ;;
-h|--help|help) usage; exit 0 ;;
*) echo "[ERR] unknown arg: $cmd" >&2; usage; exit 1 ;;
esac
need_cmd bash
need_cmd python3
need_cmd ansible-playbook
if [[ "${ACCEPT_DEPLOY:-0}" == "1" ]]; then
echo "########################################## deploy (optional)"
if [[ "${ACCEPT_DEPLOY_K3S:-1}" == "1" ]]; then
./ansible/bin/deploy-lab.sh k3s
fi
if [[ "${ACCEPT_DEPLOY_LONGHORN:-0}" == "1" ]]; then
./ansible/bin/deploy-lab.sh longhorn
fi
if [[ "${ACCEPT_DEPLOY_NGINX_MATRIX:-0}" == "1" ]]; then
./ansible/bin/deploy-lab.sh nginx-matrix
fi
if [[ "${ACCEPT_DEPLOY_NGINX_MATRIX_TLS:-0}" == "1" ]]; then
./ansible/bin/deploy-lab.sh nginx-matrix-tls
fi
fi
echo ""
echo "########################################## verify full (matrix)"
./ansible/bin/verify.sh full
}
main "$@"