Files
AI-Testing/start.sh
2026-04-18 20:20:38 +08:00

49 lines
1.2 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
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
if [[ ! -f ".env" ]]; then
if [[ -f ".env.example" ]]; then
cp .env.example .env
echo "==> 已根据 .env.example 创建 .env请编辑 .env 填写 QWEN_API_KEY 等敏感项)"
else
echo "==> 警告: 未找到 .env.example无法自动生成 .env"
fi
else
echo "==> 已存在 .env"
fi
echo "==> 构建并启动所有服务..."
docker compose up --build -d
echo "==> 当前容器状态"
docker compose ps
echo "==> 环境变量:容器内 backend 会加载 .env.example 与 .env后者覆盖前者项目根 .env 供 Compose 插值与本地配置"
wait_http() {
local url=$1
local label=$2
local i=0
while [[ $i -lt 45 ]]; do
if curl -sf "$url" >/dev/null 2>&1; then
echo "${label}: ok"
return 0
fi
sleep 1
i=$((i + 1))
done
echo "${label}: unreachable请确认容器已就绪或执行: curl -v ${url}"
return 1
}
echo "==> 健康检查(后端 8866前端 Nginx 8173最多等待约 45s"
wait_http "http://localhost:8866/health" "backend" || true
wait_http "http://localhost:8173/health" "frontend (nginx)" || true
echo "==> 启动完成"