From 5c856749c187f6b47aaf0ecc622217c04c5424e3 Mon Sep 17 00:00:00 2001 From: wangbolhr Date: Fri, 10 Apr 2026 17:09:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20=E6=B5=85=E5=85=8B=E9=9A=86?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=E3=80=81README=20=E7=B2=BE=E7=AE=80=E4=B8=8E?= =?UTF-8?q?=20Docker=20=E8=87=AA=E5=8A=A8=E5=AE=89=E8=A3=85=E5=8F=AF?= =?UTF-8?q?=E8=A7=82=E6=B5=8B=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - README: Windows 一条 PowerShell 命令,保留脚本权限说明;合并重复段落 - start.sh/ps1: git clone --depth 1 示例 - start.ps1: 选 [2] 时输出 winget/choco 日志与退出码,失败原因可辨;Read-Host Trim;winget 后若 docker 可用则视为成功 Made-with: Cursor --- README.md | 57 ++++++++++++--------------------------------------- start.ps1 | 61 +++++++++++++++++++++++++++++++++++++++++++++---------- start.sh | 4 ++-- 3 files changed, 65 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 6d9b0f3..f3c7ae4 100644 --- a/README.md +++ b/README.md @@ -3,23 +3,15 @@ ### Linux/Mac ```bash -git clone https://git.51easyai.com/wangbo/easyai.git && cd easyai && chmod +x start.sh && ./start.sh +git clone --depth 1 https://git.51easyai.com/wangbo/easyai.git && cd easyai && chmod +x start.sh && ./start.sh ``` ### Windows -在 PowerShell 中**分行执行**下面三行(不要与 `git clone` 粘成一行且漏掉分号,否则 `-ExecutionPolicy` 可能被当成 `git` 的参数,出现 `error: unknown switch 'E'`): +在 **PowerShell** 中执行: ```powershell -git clone "https://git.51easyai.com/wangbo/easyai.git" "easyai" -Set-Location ".\easyai" -powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" -``` - -若必须单行粘贴,请用分号分隔整条命令链: - -```powershell -git clone "https://git.51easyai.com/wangbo/easyai.git" "easyai"; Set-Location "easyai"; powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" +git clone --depth 1 "https://git.51easyai.com/wangbo/easyai.git" "easyai"; Set-Location "easyai"; powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" ``` > **Windows 脚本权限说明**:PowerShell 默认禁止运行脚本,直接双击 `start.ps1` 会闪退。 @@ -422,7 +414,7 @@ start.sh 脚本用于服务器一键安装启动EasyAI应用 ### 首次安装部署步骤,并使用服务器公网IP进行访问 1. 克隆脚本和相关文件到服务器 ```bash -git clone https://git.51easyai.com/wangbo/easyai.git +git clone --depth 1 https://git.51easyai.com/wangbo/easyai.git # 进入easyai目录 cd easyai ``` @@ -445,45 +437,22 @@ chmod +x start.sh ## Windows 一键启动 -start.ps1 脚本用于 Windows 本机/局域网一键部署 EasyAI 应用。**不要直接双击运行**(会闪退),请按以下方式执行: +**不要双击** `start.ps1`(易闪退)。在 **PowerShell** 中执行: -### 权限配置(首次执行必做) +```powershell +git clone --depth 1 "https://git.51easyai.com/wangbo/easyai.git" "easyai"; Set-Location "easyai"; powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" +``` -PowerShell 默认可能禁止运行脚本,需先执行以下任一方式: +已在 `easyai` 目录内时: -**方式一:临时允许本次运行(推荐)** ```powershell powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" ``` -**方式二:为当前用户永久放开脚本执行权限** -```powershell -Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -``` -执行后再运行 `.\start.ps1` 即可。 - -### 启动步骤 - -1. 克隆并进入目录(**请分行执行**,避免把后续命令当成 `git` 的参数) - -```powershell -git clone "https://git.51easyai.com/wangbo/easyai.git" "easyai" -Set-Location ".\easyai" -``` - -2. 在 PowerShell 或 CMD 中运行(二选一) - -```powershell -# 若已设置 ExecutionPolicy,可直接执行 -.\start.ps1 - -# 未设置时使用 Bypass 方式(推荐带引号的路径) -powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" -``` - -3. 按提示选择 [1] 本地访问 或 [2] 局域网访问,脚本将自动配置并启动 Docker 服务。 - -4. 若窗口闪退,可查看日志 `start.ps1.log`(与 start.ps1 同目录,或 `%TEMP%\start.ps1.log`)获取退出原因。 +> **Windows 脚本权限说明**:PowerShell 默认禁止运行脚本,直接双击 `start.ps1` 会闪退。 +> +> - **推荐**:使用 `powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1"` 执行,无需修改系统策略 +> - **或**:以管理员身份打开 PowerShell,执行 `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`,之后可直接运行 `.\start.ps1` ### 启用HTTPS 1. [更改为你的域名]修改`easyai-proxy.conf`中域名`51easyai.com`为你的域名[可以使用Ctrl+F批量替换51easyai.com为你的域名] diff --git a/start.ps1 b/start.ps1 index 9488a5e..3eb86f4 100644 --- a/start.ps1 +++ b/start.ps1 @@ -1,12 +1,12 @@ #Requires -Version 5.1 # -# 从 Git 克隆后首次部署(推荐分行复制执行,避免参数被误传给 git): -# git clone "https://git.51easyai.com/wangbo/easyai.git" "easyai" +# 从 Git 克隆后首次部署(推荐分行复制执行,避免参数被误传给 git;浅克隆加 --depth 1): +# git clone --depth 1 "https://git.51easyai.com/wangbo/easyai.git" "easyai" # Set-Location ".\easyai" # powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" # # 若必须一行,请用分号分隔整条链,且 -File 后必须是带引号的脚本路径(不要用 Istart.ps1,应为 .\start.ps1): -# git clone "https://git.51easyai.com/wangbo/easyai.git" "easyai"; Set-Location "easyai"; powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" +# git clone --depth 1 "https://git.51easyai.com/wangbo/easyai.git" "easyai"; Set-Location "easyai"; powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" # # 若出现 error: unknown switch 'E':说明 -ExecutionPolicy 被交给了 git(可复现:git clone URL -ExecutionPolicy)。 # 常见原因:整段命令未用分号分隔、或把 powershell 与 git 写在同一行且参数被 git 解析。 @@ -208,18 +208,57 @@ function Ensure-DockerRunning { } function Install-DockerDesktop { - if (Get-Command winget -ErrorAction SilentlyContinue) { + function Test-Winget { + return [bool](Get-Command winget -ErrorAction SilentlyContinue) + } + function Test-Choco { + return [bool](Get-Command choco -ErrorAction SilentlyContinue) + } + if (Test-Winget) { Step "Installing Docker Desktop via winget..." - winget install --id Docker.DockerDesktop -e --accept-source-agreements --accept-package-agreements - if ($LASTEXITCODE -eq 0) { Ok "Install started. Reopen terminal and rerun script."; exit 0 } + Write-Log "winget install Docker.DockerDesktop" + $wingetOut = & winget install --id Docker.DockerDesktop -e --accept-source-agreements --accept-package-agreements 2>&1 + $wingetOut | ForEach-Object { Write-Host $_ } + $wingetCode = $LASTEXITCODE + Write-Log "winget exit code: $wingetCode" + if ($wingetCode -eq 0) { + Ok "Install started. Reopen terminal and rerun script." + Write-Log "winget reported success" + exit 0 + } + if (Test-DockerInstalled) { + Ok "Docker CLI detected after winget. Reopen terminal if docker commands fail, then rerun script." + Write-Log "winget exit $wingetCode but docker is available" + exit 0 + } + Warn "winget did not report success (exit code: $wingetCode). Trying Chocolatey if available..." + } else { + Warn "winget not found (install 'App Installer' from Microsoft Store or use Windows 11 / recent Windows 10). Trying Chocolatey if available..." } - if (Get-Command choco -ErrorAction SilentlyContinue) { + + if (Test-Choco) { Step "Installing Docker Desktop via choco..." - choco install docker-desktop -y - if ($LASTEXITCODE -eq 0) { Ok "Install started. Reopen terminal and rerun script."; exit 0 } + Write-Log "choco install docker-desktop" + $chocoOut = & choco install docker-desktop -y 2>&1 + $chocoOut | ForEach-Object { Write-Host $_ } + $chocoCode = $LASTEXITCODE + Write-Log "choco exit code: $chocoCode" + if ($chocoCode -eq 0) { + Ok "Install started. Reopen terminal and rerun script." + exit 0 + } + if (Test-DockerInstalled) { + Ok "Docker CLI detected after choco. Reopen terminal if docker commands fail, then rerun script." + exit 0 + } + Warn "choco did not report success (exit code: $chocoCode)." + } else { + Warn "Chocolatey (choco) not found." } - Warn "Please install Docker Desktop manually:" + + Warn "Automatic install was not completed. Please install Docker Desktop manually:" Write-Host " $script:DockerDesktopUrl" + Write-Log "Docker auto-install failed (winget/choco unavailable or non-zero exit)" Wait-ForExit exit 1 } @@ -241,7 +280,7 @@ function Test-Docker { Write-Host "Choose:" Write-Host " [1] Manual install (open URL and exit)" Write-Host " [2] Auto install (winget/choco)" - $choice = Read-Host "Select [1/2]" + $choice = (Read-Host "Select [1/2]").Trim() switch ($choice) { "1" { Start-Process $script:DockerDesktopUrl; Wait-ForExit; exit 1 } "2" { Install-DockerDesktop } diff --git a/start.sh b/start.sh index eb45963..139da83 100755 --- a/start.sh +++ b/start.sh @@ -1,7 +1,7 @@ #!/bin/bash # EasyAI 一键部署脚本 # 支持交互式问答配置,兼容 IP 与域名两种访问方式 -# 一行命令: git clone https://git.51easyai.com/wangbo/easyai && cd easyai && chmod +x ./start.sh && ./start.sh +# 一行命令: git clone --depth 1 https://git.51easyai.com/wangbo/easyai.git && cd easyai && chmod +x ./start.sh && ./start.sh set -e @@ -18,7 +18,7 @@ init_project_dir() { return 0 fi echo "❌ 未找到 docker-compose.yml,请在 easyai 项目目录下运行 start.sh" - echo " 启动命令: git clone https://git.51easyai.com/wangbo/easyai && cd easyai && chmod +x ./start.sh && ./start.sh" + echo " 启动命令: git clone --depth 1 https://git.51easyai.com/wangbo/easyai.git && cd easyai && chmod +x ./start.sh && ./start.sh" exit 1 }