Files

68 lines
1.6 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.
#!/bin/bash
set -euo pipefail
wait_for_healthy() {
local timeout=120
local elapsed=0
while [ "$elapsed" -lt "$timeout" ]; do
local output
output="$(docker compose ps --format '{{.Name}} {{.Status}}' || true)"
if [ -n "$output" ] && ! echo "$output" | grep -Eiq 'unhealthy|starting|restarting|created|exited|dead'; then
echo "✅ docker compose 服务状态正常"
return 0
fi
sleep 3
elapsed=$((elapsed + 3))
done
echo "❌ 等待服务健康超时(${timeout}s)"
docker compose ps
return 1
}
if ! command -v docker >/dev/null 2>&1; then
echo "❌ 未检测到 docker"
exit 1
fi
if ! command -v uv >/dev/null 2>&1; then
echo "❌ 未检测到 uv"
exit 1
fi
if [ ! -f .env ]; then
echo "⚠️ 未发现 .env,请基于 .env.example 创建后重试。"
if [ -f .env.example ]; then
cp .env.example .env
echo "已自动复制 .env.example -> .env,请检查并修改敏感配置。"
fi
fi
echo "启动 Docker 服务..."
docker compose up -d --wait
wait_for_healthy
echo "同步依赖..."
uv sync --frozen
echo "执行数据库迁移..."
uv run alembic upgrade head
echo "执行种子数据脚本..."
uv run python scripts/seed_data.py
echo "运行单元测试..."
uv run pytest tests/unit/ -q
echo "✅ 环境初始化完成"
echo "服务访问地址:"
echo "- API: http://localhost:8000"
echo "- API Health: http://localhost:8000/health"
echo "- Grafana: http://localhost:3000"
echo "- Prometheus: http://localhost:9090"
echo "- MinIO Console: http://localhost:9001"
echo "- Milvus: localhost:19530"