diff --git a/README.md b/README.md index 9091eb2..895df32 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,44 @@ chmod +x start.sh ``` 6. 脚本运行完成无错误,并且提示`EasyAI应用启动成功`表示应用启动成功,打开浏览器输入服务器的公网ip:3010或者局域网IP:3010,即可访问EasyAI应用 +## Windows 一键启动 + +start.ps1 脚本用于 Windows 本机/局域网一键部署 EasyAI 应用。**不要直接双击运行**(会闪退),请按以下方式执行: + +### 权限配置(首次执行必做) + +PowerShell 默认可能禁止运行脚本,需先执行以下任一方式: + +**方式一:临时允许本次运行(推荐)** +```powershell +powershell -ExecutionPolicy Bypass -File .\start.ps1 +``` + +**方式二:为当前用户永久放开脚本执行权限** +```powershell +Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser +``` +执行后再运行 `.\start.ps1` 即可。 + +### 启动步骤 + +1. 克隆并进入目录 +```powershell +git clone https://git.51easyai.com/wangbo/easyai.git +cd easyai +``` + +2. 在 PowerShell 或 CMD 中运行(二选一) +```powershell +# 若已设置 ExecutionPolicy,可直接执行 +.\start.ps1 + +# 未设置时使用 Bypass 方式 +powershell -ExecutionPolicy Bypass -File .\start.ps1 +``` + +3. 按提示选择 [1] 本地访问 或 [2] 局域网访问,脚本将自动配置并启动 Docker 服务。 + ### 启用HTTPS 1. [更改为你的域名]修改`easyai-proxy.conf`中域名`51easyai.com`为你的域名[可以使用Ctrl+F批量替换51easyai.com为你的域名] 2. [修改.env文件]修改如下两个环境变量为如下的对应的值 diff --git a/start.ps1 b/start.ps1 index 2783d71..105e8a2 100644 --- a/start.ps1 +++ b/start.ps1 @@ -4,6 +4,23 @@ # 一行命令: git clone https://git.51easyai.com/wangbo/easyai; cd easyai; .\start.ps1 $ErrorActionPreference = "Stop" +trap { + Write-Host "" + Write-Host "========================================" -ForegroundColor Red + Write-Host " 发生错误(便于 Debug)" -ForegroundColor Red + Write-Host "========================================" -ForegroundColor Red + Write-Host $_.Exception.Message -ForegroundColor Red + if ($_.ScriptStackTrace) { Write-Host "`n$($_.ScriptStackTrace)" } + Wait-ForExit + exit 1 +} + +# 结束时保持窗口不关闭,便于查看输出和 Debug(CI 环境自动跳过) +function Wait-ForExit { + if ($env:CI -eq "true") { return } + Write-Host "" + Read-Host "按 Enter 键退出" +} # 仅配置模式:DEPLOY_DRY_RUN=1 只生成配置文件,不执行 Docker 安装和启动 $script:DeployDryRun = if ($env:DEPLOY_DRY_RUN -eq "1") { $true } else { $false } @@ -15,12 +32,13 @@ $DockerDesktopUrl = "https://desktop.docker.com/win/main/amd64/Docker%20Desktop% function Write-Step { param($Msg) Write-Host $Msg } function Write-Ok { param($Msg) Write-Host " ✓ $Msg" -ForegroundColor Green } -function Write-Err { param($Msg) Write-Host "❌ $Msg" -ForegroundColor Red; exit 1 } +function Write-Err { param($Msg) Write-Host "❌ $Msg" -ForegroundColor Red; throw $Msg } function Write-Warn { param($Msg) Write-Host "⚠️ $Msg" -ForegroundColor Yellow } # ==================== 项目初始化 ==================== function Init-ProjectDir { - $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path + $scriptDir = $PSScriptRoot + if (-not $scriptDir) { throw "无法获取脚本所在目录。请在 easyai 目录下打开 PowerShell 执行: .\start.ps1" } $composePath = Join-Path $scriptDir "docker-compose.yml" if (Test-Path $composePath) { Set-Location $scriptDir @@ -122,7 +140,7 @@ function Install-DockerDesktop { if (-not $isWin) { Write-Warn "自动安装仅支持 Windows。请手动安装 Docker Desktop。" Write-Host "下载地址: $DockerDesktopUrl" - exit 1 + Wait-ForExit; exit 1 } # 优先 winget,其次 Chocolatey @@ -145,7 +163,7 @@ function Install-DockerDesktop { Write-Warn "未找到 winget 或 Chocolatey,请手动安装 Docker Desktop。" Write-Host "下载地址: $DockerDesktopUrl" - exit 1 + Wait-ForExit; exit 1 } function Test-Docker { @@ -179,7 +197,7 @@ function Test-Docker { if ($env:OS -eq "Windows_NT") { Start-Process $DockerDesktopUrl } - exit 1 + Wait-ForExit; exit 1 } "2" { Install-DockerDesktop @@ -259,6 +277,9 @@ function Main { $accessIp = if ($script:DeployIP) { $script:DeployIP } else { "127.0.0.1" } Write-Host "访问地址: http://${accessIp}:3010" Write-Host "" + Wait-ForExit } +Write-Host "EasyAI Windows 部署脚本启动中..." -ForegroundColor Cyan +Write-Host "" Main