nex_buddy/scripts/dev.sh

24 lines
766 B
Bash
Raw Normal View History

2026-11-13 06:38:19 +00:00
#!/usr/bin/env bash
# 开发期启动:scripts/dev.sh [端口]
2026-11-13 08:51:05 +00:00
# 后端端口默认取 .env 的 BACKEND_PORT(没有就用 8000);命令行参数优先级更高。
2026-11-13 06:38:19 +00:00
set -euo pipefail
cd "$(dirname "$0")/.."
PORT="${1:-}"
if [ -z "$PORT" ]; then
PORT="$(grep -E '^BACKEND_PORT=' .env 2>/dev/null | tail -1 | cut -d= -f2 | tr -d '[:space:]' || true)"
2026-11-13 08:51:05 +00:00
PORT="${PORT:-8000}"
2026-11-13 06:38:19 +00:00
fi
if [ ! -d .venv ]; then
echo ">> 创建虚拟环境"
python3 -m venv .venv
.venv/bin/python -m pip -q install -r requirements.txt
fi
echo ">> 迁移数据库"
(cd server && ../.venv/bin/python -m alembic upgrade head)
echo ">> 启动 http://0.0.0.0:${PORT} (文档 /docs)"
cd server && exec ../.venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port "$PORT" --reload