From fbbf5d7b4f14d780438492a2d17273f3fdc101ee Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Wed, 1 Jul 2026 09:22:06 +0800 Subject: [PATCH] feat(toolkit): upgrade to Phase 1 Site Migration & Backup Toolkit --- .github/workflows/deploy-env-migration.yaml | 20 +++++---- Makefile | 17 +++++++ scripts/run_toolkit.sh | 50 +++++++++++++++++++++ 3 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 Makefile create mode 100755 scripts/run_toolkit.sh diff --git a/.github/workflows/deploy-env-migration.yaml b/.github/workflows/deploy-env-migration.yaml index 4de2a5a..088c1d1 100644 --- a/.github/workflows/deploy-env-migration.yaml +++ b/.github/workflows/deploy-env-migration.yaml @@ -18,7 +18,7 @@ on: source_host: description: "源环境 IP 或域名 (用于导出数据)" required: true - default: "install.svc.plus" + default: "console.svc.plus" type: string source_domain_base: description: "源环境域名后缀 (例如 svc.plus)" @@ -35,6 +35,12 @@ on: required: false default: true type: boolean + toolkit_action: + description: "Toolkit 执行动作" + required: false + default: "migrate" + type: choice + options: [migrate, backup, restore] terraform_action: description: "apply 创建/更新,destroy 销毁" required: false @@ -296,14 +302,10 @@ jobs: echo "[migration_target]" >> inventory_migration.ini echo "${TARGET_IP} ansible_user=root ansible_ssh_private_key_file=~/.ssh/id_deploy" >> inventory_migration.ini - - name: Run Ansible Site Migration Playbook - working-directory: ${{ env.PLAYBOOKS_DIR }} + - name: Run Toolkit Action (${{ github.event.inputs.toolkit_action }}) + working-directory: . run: | - ansible-playbook \ - -i ../inventory_migration.ini \ - migrate_site.yml \ - -e "target_domain=${{ github.event.inputs.target_domain_base }}" \ - -e "migration_flow.source.domain_base=${{ github.event.inputs.source_domain_base }}" + make ${{ github.event.inputs.toolkit_action }} RUN_ARGS="-e target_domain=${{ github.event.inputs.target_domain_base }} -e migration_flow.source.domain_base=${{ github.event.inputs.source_domain_base }}" switch_dns: name: Switch DNS Traffic (Manual Approval) @@ -345,4 +347,4 @@ jobs: CLOUDFLARE_DNS_API_TOKEN: ${{ steps.vault.outputs.CLOUDFLARE_DNS_API_TOKEN }} run: | cd infra/playbooks - ansible-playbook -i ../../cmdb/inventory update_cloudflare_svc_plus_dns.yml + ansible-playbook -i ../../cmdb/inventory update_site_dns.yml -e "target_domain=${{ github.event.inputs.target_domain_base }}" -e "source_domain=${{ github.event.inputs.source_domain_base }}" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a6f8cca --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +.PHONY: help migrate backup restore + +help: + @echo "AI Workspace Site Migration & Backup Toolkit" + @echo "Usage:" + @echo " make migrate - Execute full site migration (Source -> Target)" + @echo " make backup - Execute cold backup on the target host" + @echo " make restore - Execute offline restore on the target host" + +migrate: + @bash scripts/run_toolkit.sh migrate $(RUN_ARGS) + +backup: + @bash scripts/run_toolkit.sh backup $(RUN_ARGS) + +restore: + @bash scripts/run_toolkit.sh restore $(RUN_ARGS) diff --git a/scripts/run_toolkit.sh b/scripts/run_toolkit.sh new file mode 100755 index 0000000..1244bf2 --- /dev/null +++ b/scripts/run_toolkit.sh @@ -0,0 +1,50 @@ +#!/bin/bash +set -euo pipefail + +ACTION=$1 + +if [[ -z "$ACTION" ]]; then + echo "Usage: $0 " + exit 1 +fi + +PLAYBOOK_DIR="../playbooks" +INVENTORY_DIR="../cmdb" + +if [[ ! -d "$PLAYBOOK_DIR" ]]; then + echo "[ERROR] Cannot find playbooks directory at $PLAYBOOK_DIR" + echo "Make sure ai-workspace-infra/playbooks is checked out." + exit 1 +fi + +if [[ ! -f "$INVENTORY_DIR/inventory" ]] && [[ ! -f "$INVENTORY_DIR/inventory.ini" ]] && [[ ! -f "cmdb/inventory" ]]; then + echo "[WARNING] Cannot find cmdb/inventory. Assuming manual inventory or default." +fi + +# In GitHub Actions, cmdb is at the root of site-recovery. Locally it might be ../cmdb. +INV_PATH="cmdb/inventory" +if [[ ! -f "$INV_PATH" ]]; then + if [[ -f "../cmdb/inventory" ]]; then + INV_PATH="../cmdb/inventory" + elif [[ -f "../cmdb/inventory.ini" ]]; then + INV_PATH="../cmdb/inventory.ini" + fi +fi + +PLAYBOOK_FILE="${ACTION}_site.yml" + +echo "[INFO] Starting Toolkit Action: $ACTION" +echo "[INFO] Playbook: $PLAYBOOK_DIR/$PLAYBOOK_FILE" + +cd "$PLAYBOOK_DIR" + +if [[ -f "../site-recovery/$INV_PATH" ]]; then + ansible-playbook -i "../site-recovery/$INV_PATH" "$PLAYBOOK_FILE" "${@:2}" +elif [[ -f "../cmdb/inventory" ]]; then + ansible-playbook -i "../cmdb/inventory" "$PLAYBOOK_FILE" "${@:2}" +else + echo "[WARNING] No inventory found. Running playbook without explicit inventory flag." + ansible-playbook "$PLAYBOOK_FILE" "${@:2}" +fi + +echo "[INFO] Toolkit Action $ACTION completed."