Files
Cyrene_v2/scripts/dev-up.sh
T
Aska 265b207699
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled
chore(deploy): dev-up.sh 的 gateway 端口优先读 .env PORT,支持自定义端口
2026-09-06 13:12:22 +08:00

79 lines
3.4 KiB
Bash
Executable File
Raw 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
# Cyrene v2 本地一键开发启动:PG+pgvector → llama.cpp embedding → 前端 build → cyrene
# 用法:bash scripts/dev-up.sh (在仓库根目录;需 docker + go + node)
set -euo pipefail
REPO="$(cd "$(dirname "$0")/.." && pwd)"
MODEL_DIR="$HOME/.models"
LLAMA_DIR="$HOME/apps/llama.cpp"
APP_NAME="cyrene"
APP_BIN="$HOME/apps/cyrene/$APP_NAME"
EMB_MODEL="$MODEL_DIR/Qwen3-Embedding-0.6B-Q8_0.gguf"
EMB_PORT=11434
# gateway 端口优先读 .env 的 PORT(用户可改),找不到才回退 10080
GW_PORT="$(grep -E '^PORT=' "$REPO/.env" 2>/dev/null | head -1 | cut -d= -f2)"
GW_PORT="${GW_PORT:-10080}"
cd "$REPO"
echo "==> [1/4] PostgreSQL + pgvector (docker)"
if command -v docker >/dev/null 2>&1; then
# PG 已在跑则跳过
if curl -s --max-time 2 "http://127.0.0.1:5432" >/dev/null 2>&1 || docker ps --format '{{.Names}}' 2>/dev/null | grep -q '^cyrene-pg$'; then
echo " cyrene-pg 已在运行 (:5432),跳过"
else
# 有 compose 插件用 compose,否则回退 docker run
if docker compose version >/dev/null 2>&1; then
docker compose -f docker-compose.dev.yml up -d pg
else
echo " (docker compose 插件不可用,回退 docker run 拉起 cyrene-pg)"
docker run -d --name cyrene-pg \
-e POSTGRES_USER=cyrene -e POSTGRES_PASSWORD=cyrene_pass -e POSTGRES_DB=cyrene_ai \
-p 5432:5432 -v cyrene_pgdata:/var/lib/postgresql/data \
pgvector/pgvector:pg16 >/dev/null 2>&1 \
&& echo " cyrene-pg 已用 docker run 启动" \
|| echo " (cyrene-pg 启动失败,请手动检查端口/镜像)"
fi
fi
else
echo " (未检测到 docker;若用 SQLite 默认可不启动 PG)"
fi
echo "==> [2/4] llama.cpp embedding (Qwen3-Embedding,Vulkan)"
if [ -x "$LLAMA_DIR/llama-server" ] && [ -f "$EMB_MODEL" ]; then
# 已在跑则跳过
if ! curl -s --max-time 2 "http://127.0.0.1:$EMB_PORT/health" >/dev/null 2>&1; then
(cd "$LLAMA_DIR" && nohup ./llama-server -m "$EMB_MODEL" --embedding -ngl 99 --host 127.0.0.1 --port "$EMB_PORT" > "$HOME/cy-emb.log" 2>&1 &)
echo " llama-server 已启动: http://127.0.0.1:$EMB_PORT"
else
echo " llama-server 已在运行 (: $EMB_PORT),跳过"
fi
else
echo " (未找到 $LLAMA_DIR/llama-server 或模型 $EMB_MODEL;跳过。"
echo " llama.cpp 放 ~/apps/llama.cpp,GGUF 放 ~/.models/)"
fi
echo "==> [3/4] 前端构建 (go:embed 需要 dist)"
if [ -d frontend/web ]; then
(cd frontend/web && npm ci >/dev/null 2>&1 && npm run build >/dev/null 2>&1) || echo " (前端 build 跳过/失败——若已存在 dist 可忽略)"
fi
echo "==> [4/4] 构建并启动 cyrene"
if [ ! -f "$APP_BIN" ]; then
mkdir -p "$HOME/apps/cyrene"
echo " go build -> $APP_BIN"
go build -ldflags="-s -w" -trimpath -o "$APP_BIN" ./cmd/cyrene
fi
if ! curl -s --max-time 2 "http://127.0.0.1:$GW_PORT/api/v1/health" >/dev/null 2>&1; then
(cd "$REPO" && nohup "$APP_BIN" > "$HOME/cy.log" 2>&1 &)
echo " cyrene 已启动: http://localhost:$GW_PORT (日志 $HOME/cy.log)"
else
echo " cyrene 已在运行 (: $GW_PORT),跳过"
fi
echo
echo "完成。访问 http://localhost:$GW_PORT (.env 的 PORT 覆盖此值)"
echo " · LLM: .env 的 LLM_PROVIDER / ANTHROPIC_* 或 LLM_*"
echo " · 向量: EMBEDDING_API_URL=http://127.0.0.1:$EMB_PORT/v1/embeddings EMBEDDING_MODEL=Qwen3-Embedding-0.6B"
echo " · 停止: pkill -f llama-server ; pkill -f $APP_NAME"