chore: 对齐 00-05 §2 的部署与验证脚本
- 新增 deploy-lab.sh(k3s/longhorn/nginx 铺栈)与 ssh/run-phase2-k3s-on-ylc61-as-jack.sh - verify.sh:flow/preflight、VERIFY_TEARDOWN 默认、注释与 §2 对应 - 更新 smoke-verify、README、.env.verify.example、根 README 与主要 playbook 头注释 - k3s-delete-lab-stacks 标明重度清场语义 Made-with: Cursor
This commit is contained in:
80
scripts/deploy-lab.sh
Normal file
80
scripts/deploy-lab.sh
Normal file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env bash
|
||||
# 实验室「正式部署」入口(对应 docs/00-05 §2 步骤 1~3,与 verify.sh 的逐条验收 teardown 不同)。
|
||||
# 在仓库根执行:./scripts/deploy-lab.sh <子命令>
|
||||
#
|
||||
# 步骤对应关系(详见 docs/00-05-测试与验证框架.md §2):
|
||||
# 1 接入 — 本机有 ansible-playbook、inventory 可达;可选加载 scripts/.env.verify
|
||||
# 2 前置 — 可选 k3s-prepare-storage(磁盘 → /storage),非 k3s-uninstall 类重度清理
|
||||
# 3 部署 — k3s-init-and-install 或其它子命令所列 playbook
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
load_env() {
|
||||
if [[ -f "${ROOT}/scripts/.env.verify" ]]; then
|
||||
set -a
|
||||
# shellcheck disable=SC1091
|
||||
source "${ROOT}/scripts/.env.verify"
|
||||
set +a
|
||||
echo "[OK] 已加载 scripts/.env.verify"
|
||||
fi
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
用法:scripts/deploy-lab.sh <子命令>
|
||||
|
||||
子命令:
|
||||
k3s 安装/复验 K3s(可选先跑数据盘准备,见环境变量)
|
||||
longhorn Helm 安装 Longhorn(ansible/playbooks/longhorn-install.yml)
|
||||
nginx-matrix 部署 HTTP nginx 矩阵(ansible/playbooks/nginx-matrix-deploy.yml)
|
||||
nginx-matrix-tls 部署 TLS nginx 矩阵(ansible/playbooks/nginx-matrix-tls-deploy.yml)
|
||||
|
||||
环境变量(节选,完整见 scripts/.env.verify.example):
|
||||
ANSIBLE_INVENTORY 默认 <仓库>/ansible/inventory.ini
|
||||
K3S_PREPARE_STORAGE 为 true 时先执行 k3s-prepare-storage.yml,并传 -e k3s_prepare_storage=true
|
||||
|
||||
说明:
|
||||
「矩阵级验收」请用 ./scripts/verify.sh run / run-all;本脚本只做安装/铺栈,不负责按 doc_id 做断言与 teardown。
|
||||
EOF
|
||||
}
|
||||
|
||||
ansible_wrap() {
|
||||
local inv="${ANSIBLE_INVENTORY:-${ROOT}/ansible/inventory.ini}"
|
||||
if [[ ! -f "$inv" ]]; then
|
||||
echo "[ERR] inventory 不存在:$inv" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! command -v ansible-playbook >/dev/null 2>&1; then
|
||||
echo "[ERR] 未找到 ansible-playbook,请先安装 Ansible" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "[RUN] ansible-playbook -i $inv $*"
|
||||
ansible-playbook -i "$inv" "$@"
|
||||
}
|
||||
|
||||
cmd_k3s() {
|
||||
if [[ "${K3S_PREPARE_STORAGE:-false}" == "true" ]]; then
|
||||
ansible_wrap "${ROOT}/ansible/playbooks/k3s-prepare-storage.yml" -e 'k3s_prepare_storage=true'
|
||||
fi
|
||||
ansible_wrap "${ROOT}/ansible/playbooks/k3s-init-and-install.yml"
|
||||
}
|
||||
|
||||
main() {
|
||||
load_env
|
||||
local sub="${1:-}"
|
||||
case "$sub" in
|
||||
""|-h|--help) usage ;;
|
||||
k3s) cmd_k3s ;;
|
||||
longhorn) ansible_wrap "${ROOT}/ansible/playbooks/longhorn-install.yml" ;;
|
||||
nginx-matrix) ansible_wrap "${ROOT}/ansible/playbooks/nginx-matrix-deploy.yml" ;;
|
||||
nginx-matrix-tls) ansible_wrap "${ROOT}/ansible/playbooks/nginx-matrix-tls-deploy.yml" ;;
|
||||
*)
|
||||
echo "[ERR] 未知子命令:$sub" >&2
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in New Issue
Block a user