-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstart.ps1
More file actions
120 lines (106 loc) · 4.68 KB
/
Copy pathstart.ps1
File metadata and controls
120 lines (106 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# GitHub Bot 项目启动脚本 (PowerShell)
# 使用方法: 右键点击 -> 使用 PowerShell 运行
# 设置错误处理
$ErrorActionPreference = "Stop"
# 设置控制台编码为 UTF-8
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Write-Host "🚀 启动 GitHub Bot 项目..." -ForegroundColor Green
Write-Host ""
try {
# 检查 Docker 是否安装
Write-Host "🔍 检查 Docker 安装状态..." -ForegroundColor Yellow
$null = docker --version
Write-Host "✅ Docker 已安装" -ForegroundColor Green
} catch {
Write-Host "❌ Docker 未安装,请先安装 Docker Desktop" -ForegroundColor Red
Write-Host "下载地址: https://www.docker.com/products/docker-desktop" -ForegroundColor Cyan
Read-Host "按任意键退出"
exit 1
}
# 检查 Docker Compose(优先用新版)
$composeCmd = ""
try {
$null = docker compose version
$composeCmd = "docker compose"
Write-Host "✅ 使用 Docker Compose (新版)" -ForegroundColor Green
} catch {
try {
$null = docker-compose --version
$composeCmd = "docker-compose"
Write-Host "✅ 使用 Docker Compose (传统版)" -ForegroundColor Green
} catch {
Write-Host "❌ 未检测到 Docker Compose,请先安装 Docker Compose" -ForegroundColor Red
Read-Host "按任意键退出"
exit 1
}
}
# 检查 .env 文件
if (-not (Test-Path ".env")) {
Write-Host "⚠️ .env 文件不存在,正在从 .env.example 复制..." -ForegroundColor Yellow
Copy-Item ".env.example" ".env"
Write-Host "📝 请编辑 .env 文件,填入您的 API 密钥" -ForegroundColor Cyan
Write-Host " 至少需要设置一个 LLM API 密钥(如 OPENAI_API_KEY)" -ForegroundColor Cyan
$editEnv = Read-Host "是否现在编辑 .env 文件? (y/N)"
if ($editEnv -eq "y" -or $editEnv -eq "Y") {
notepad .env
Write-Host "请保存并关闭记事本后继续..." -ForegroundColor Yellow
Read-Host "按任意键继续"
}
}
# 创建 Docker 网络(如果不存在)
Write-Host "🌐 检查并创建 Docker 网络..." -ForegroundColor Yellow
try {
$networkExists = docker network ls --filter name=github_bot_network --format "{{.Name}}" | Select-String -Pattern "^github_bot_network$"
if (-not $networkExists) {
docker network create github_bot_network
Write-Host "✅ Docker 网络 github_bot_network 创建成功" -ForegroundColor Green
} else {
Write-Host "✅ Docker 网络 github_bot_network 已存在" -ForegroundColor Green
}
} catch {
Write-Host "⚠️ 创建网络时出现警告,继续执行..." -ForegroundColor Yellow
}
# 构建并启动服务
Write-Host "🐳 构建和启动 Docker 容器..." -ForegroundColor Yellow
try {
Invoke-Expression "$composeCmd up --build -d"
Write-Host "✅ Docker 容器启动成功" -ForegroundColor Green
} catch {
Write-Host "❌ Docker 容器启动失败" -ForegroundColor Red
Write-Host "错误信息: $($_.Exception.Message)" -ForegroundColor Red
Read-Host "按任意键退出"
exit 1
}
# 等待服务启动
Write-Host "⏳ 等待服务启动..." -ForegroundColor Yellow
Start-Sleep -Seconds 10
# 检查服务状态
Write-Host "📊 检查服务状态..." -ForegroundColor Yellow
Invoke-Expression "$composeCmd ps"
# 显示访问信息
Write-Host ""
Write-Host "✅ GitHub Bot 启动完成!" -ForegroundColor Green
Write-Host ""
Write-Host "🌐 访问地址:" -ForegroundColor Cyan
Write-Host " - API 文档: http://localhost:8000/docs" -ForegroundColor White
Write-Host " - API 根路径: http://localhost:8000" -ForegroundColor White
Write-Host " - Flower 监控: http://localhost:5555" -ForegroundColor White
Write-Host ""
Write-Host "📋 常用命令:" -ForegroundColor Cyan
Write-Host " - 查看日志: $composeCmd logs -f" -ForegroundColor White
Write-Host " - 停止服务: $composeCmd down" -ForegroundColor White
Write-Host " - 重启服务: $composeCmd restart" -ForegroundColor White
Write-Host ""
Write-Host "🔧 如果遇到问题,请检查:" -ForegroundColor Cyan
Write-Host " 1. .env 文件中的 API 密钥是否正确" -ForegroundColor White
Write-Host " 2. 端口 8000、5555 是否被占用" -ForegroundColor White
Write-Host " 3. Docker Desktop 是否正常运行" -ForegroundColor White
Write-Host " 4. WSL2 是否已启用(Docker Desktop 需要)" -ForegroundColor White
Write-Host " 5. 防火墙是否阻止了 Docker 网络" -ForegroundColor White
Write-Host ""
# 询问是否打开浏览器
$openBrowser = Read-Host "是否打开浏览器查看 API 文档? (y/N)"
if ($openBrowser -eq "y" -or $openBrowser -eq "Y") {
Start-Process "http://localhost:8000/docs"
}
Read-Host "按任意键退出"