Files
deploy-test/setup.sh
2026-04-13 01:27:34 +07:00

88 lines
4.3 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
# =============================================================================
# setup.sh — 一键完整部署(首次使用)
#
# 按顺序执行:
# 01-init-env.sh → 生成 .env.local
# 02-patch-config.sh → 写入服务 YAML 配置
# 03-start-infra.sh → 启动 Docker 容器
# 04-build.sh → 编译所有 Go 服务
# 05-start.sh → 启动所有后端服务
#
# 各步骤均可独立重新执行,不必从头来过。
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/common.sh"
init_dirs
init_script_log # ← 脚本执行日志
header "一键完整部署(首次使用)"
echo -e "${BOLD}基础设施策略:${NC}"
echo " Redis / Kafka / Etcd → Docker 容器(本地)"
echo " MongoDB → 远程服务"
echo " 文件存储 → Amazon S3"
echo ""
# ── 步骤 1初始化 .env.local ─────────────────────────────────────────────────
step "[1/5] 初始化 .env.local"
bash "$SCRIPT_DIR/01-init-env.sh"
echo ""
warn "请确认 .env.local 中的 MongoDB 和 AWS S3 配置已正确填写!"
echo -e " ${CYAN}vim $ENV_FILE${NC}"
echo ""
read -p "配置已填写好,继续执行?(y/N): " -n 1 -r REPLY; echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
info "已暂停,编辑完成后重新执行: ./deploy-test/setup.sh"
info "或跳过此步直接从步骤 2 开始: ./deploy-test/02-patch-config.sh"
exit 0
fi
# ── 步骤 2写入服务配置 ──────────────────────────────────────────────────────
step "[2/5] 修改服务配置文件"
bash "$SCRIPT_DIR/02-patch-config.sh"
# ── 步骤 3启动 Docker 基础设施 ─────────────────────────────────────────────
step "[3/5] 启动 Docker 基础设施"
bash "$SCRIPT_DIR/03-start-infra.sh"
info "等待基础设施就绪 (5s)..."
sleep 5
# ── 步骤 4编译 ──────────────────────────────────────────────────────────────
step "[4/5] 编译所有后端服务"
bash "$SCRIPT_DIR/04-build.sh"
# ── 步骤 5启动 ──────────────────────────────────────────────────────────────
step "[5/5] 启动所有后端服务"
bash "$SCRIPT_DIR/05-start.sh"
# ── 完成汇总 ─────────────────────────────────────────────────────────────────
echo ""
echo -e "${BOLD}${GREEN}╔══════════════════════════════════════════╗${NC}"
echo -e "${BOLD}${GREEN}║ 本地环境部署完成! ║${NC}"
echo -e "${BOLD}${GREEN}╚══════════════════════════════════════════╝${NC}"
echo ""
echo -e "${BOLD}服务地址:${NC}"
echo " IM API: http://localhost:10002"
echo " IM WebSocket: ws://localhost:10001"
echo " Chat API: http://localhost:10008"
echo " Admin API: http://localhost:10009"
echo " MeetingMsg WS: ws://localhost:8000"
echo " Livecloud: http://localhost:8080"
echo " Livestream: http://localhost:8081"
echo ""
echo -e "${BOLD}日常命令:${NC}"
echo " ./deploy-test/status.sh # 查看全部状态"
echo " ./deploy-test/logs.sh <service> # 实时日志"
echo " ./deploy-test/restart.sh <service> # 重启服务"
echo " ./deploy-test/restart.sh <svc> --build # 重编译并重启"
echo " ./deploy-test/check-conn.sh # 验证 MongoDB/S3"
echo ""
echo -e "${BOLD}停止服务:${NC}"
echo " ./deploy-test/stop.sh # 停止后端进程"
echo " ./deploy-test/stop-infra.sh # 停止 Docker 容器"
echo ""