Skip to content

Commit f1229a1

Browse files
authored
Merge pull request #146 from podcctv/codex/update-readme-with-windows-deployment-script
docs: add Windows PowerShell deployment
2 parents c353371 + 91864d0 commit f1229a1

2 files changed

Lines changed: 189 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,100 @@ docker run -d --name nodeprobe -p 8380:8380 \
9191

9292
Data will be saved to `/opt/NodeProbe/data/` by default.
9393

94+
### Windows one-click deployment
95+
96+
Windows users can deploy NodeProbe with the following PowerShell script. Run it in an elevated PowerShell session:
97+
98+
```powershell
99+
# === NodeProbe one-click deployment (Docker Desktop / Windows) ===
100+
$ErrorActionPreference = 'Stop'
101+
102+
# 1) Configurable variables
103+
$Repo = "https://github.com/podcctv/NodeProbe"
104+
$Branch = "main"
105+
$WorkDir = "$env:USERPROFILE\NodeProbe"
106+
$ZipTmp = "$env:TEMP\nodeprobe.zip"
107+
$Image = "nodeprobe:latest"
108+
$Container = "nodeprobe"
109+
$HostPort = 8000 # Change if port is occupied
110+
$AppPort = 8000 # Service port inside container
111+
112+
# 2) Check Docker availability
113+
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
114+
throw "Docker command not found. Install and start Docker Desktop first."
115+
}
116+
try { docker version | Out-Null } catch { throw "Docker Desktop is not running or has no permission to access the Docker engine." }
117+
118+
# 3) Prepare working directory
119+
if (Test-Path $WorkDir) {
120+
Write-Host "=> Directory exists: $WorkDir"
121+
} else {
122+
New-Item -ItemType Directory -Path $WorkDir | Out-Null
123+
Write-Host "=> Created directory: $WorkDir"
124+
}
125+
126+
# 4) Fetch source code (git preferred, ZIP fallback)
127+
if (Get-Command git -ErrorAction SilentlyContinue) {
128+
if (Test-Path (Join-Path $WorkDir ".git")) {
129+
Write-Host "=> Git repository detected, pulling updates..."
130+
git -C $WorkDir fetch --all --prune
131+
git -C $WorkDir checkout $Branch
132+
git -C $WorkDir reset --hard origin/$Branch
133+
} else {
134+
Write-Host "=> Using git clone..."
135+
git clone --depth 1 --branch $Branch $Repo $WorkDir
136+
}
137+
} else {
138+
Write-Host "=> Git not found, downloading ZIP..."
139+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
140+
Invoke-WebRequest "$Repo/archive/refs/heads/$Branch.zip" -OutFile $ZipTmp
141+
if (Test-Path $WorkDir) { Remove-Item -Recurse -Force $WorkDir }
142+
Expand-Archive -LiteralPath $ZipTmp -DestinationPath (Split-Path $WorkDir) -Force
143+
Rename-Item -Path (Join-Path (Split-Path $WorkDir) ("NodeProbe-" + $Branch)) -NewName (Split-Path $WorkDir -Leaf)
144+
}
145+
146+
# 5) Generate a generic Dockerfile if missing
147+
$Dockerfile = Join-Path $WorkDir "Dockerfile"
148+
if (-not (Test-Path $Dockerfile)) {
149+
Write-Host "=> Dockerfile not found, generating a generic version..."
150+
@"
151+
FROM python:3.11-slim
152+
WORKDIR /app
153+
ENV PIP_DISABLE_PIP_VERSION_CHECK=1 PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
154+
# Base dependencies (add more system libs as needed)
155+
RUN apt-get update && apt-get install -y --no-install-recommends build-essential && rm -rf /var/lib/apt/lists/*
156+
COPY . .
157+
RUN python -m pip install --upgrade pip && \
158+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
159+
EXPOSE ${AppPort}
160+
# Entry point: adjust if your project uses a different module
161+
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "${AppPort}"]
162+
"@ | Set-Content -Path $Dockerfile -Encoding UTF8
163+
}
164+
165+
# 6) Build image
166+
Write-Host "=> Building image: $Image"
167+
docker build -t $Image $WorkDir
168+
169+
# 7) Replace existing container
170+
if ((docker ps -a --format '{{.Names}}') -contains $Container) {
171+
Write-Host "=> Existing container found, removing: $Container"
172+
docker rm -f $Container | Out-Null
173+
}
174+
175+
# 8) Run container
176+
Write-Host "=> Starting container: $Container mapping port $HostPort -> $AppPort"
177+
docker run -d --name $Container -p $HostPort:$AppPort --restart unless-stopped $Image | Out-Null
178+
179+
# 9) Health check and access
180+
Start-Sleep -Seconds 2
181+
Write-Host "=> Recent logs (Ctrl+C to stop following):"
182+
docker logs --tail 50 $Container
183+
Write-Host "=> Open http://localhost:$HostPort in your browser"
184+
try { Start-Process "http://localhost:$HostPort" } catch {}
185+
Write-Host "=== Deployment complete ==="
186+
```
187+
94188
## Changelog
95189

96190
For a list of notable changes, see [CHANGELOG](CHANGELOG.md) or the [Chinese version](CHANGELOG.zh.md).

‎README.zh.md‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,101 @@ docker run -d --name nodeprobe -p 8380:8380 \
8787
默认数据会保存到 `/opt/NodeProbe/data/`。
8888
同样可通过 `DATA_DIR` 环境变量进行更改。
8989

90+
### Windows 一键部署
91+
92+
Windows 用户可使用以下 PowerShell 脚本一键部署,在管理员权限的 PowerShell 中运行即可:
93+
94+
```powershell
95+
# === NodeProbe 一键部署 (Docker Desktop / Windows) ===
96+
$ErrorActionPreference = 'Stop'
97+
98+
# 1) 可自定义变量
99+
$Repo = "https://github.com/podcctv/NodeProbe"
100+
$Branch = "main"
101+
$WorkDir = "$env:USERPROFILE\NodeProbe"
102+
$ZipTmp = "$env:TEMP\nodeprobe.zip"
103+
$Image = "nodeprobe:latest"
104+
$Container = "nodeprobe"
105+
$HostPort = 8000 # 如端口冲突可改这里
106+
$AppPort = 8000 # 容器内服务端口,若项目不同请改
107+
108+
# 2) 检查 Docker 是否可用
109+
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
110+
throw "未检测到 docker 命令。请先安装并启动 Docker Desktop。"
111+
}
112+
try { docker version | Out-Null } catch { throw "Docker Desktop 未启动或无权限访问 Docker 引擎。" }
113+
114+
# 3) 准备目录
115+
if (Test-Path $WorkDir) {
116+
Write-Host "=> 目录已存在:$WorkDir"
117+
} else {
118+
New-Item -ItemType Directory -Path $WorkDir | Out-Null
119+
Write-Host "=> 已创建目录:$WorkDir"
120+
}
121+
122+
# 4) 获取源码(优先 git,其次 ZIP)
123+
if (Get-Command git -ErrorAction SilentlyContinue) {
124+
if (Test-Path (Join-Path $WorkDir ".git")) {
125+
Write-Host "=> 已存在 Git 仓库,执行拉取..."
126+
git -C $WorkDir fetch --all --prune
127+
git -C $WorkDir checkout $Branch
128+
git -C $WorkDir reset --hard origin/$Branch
129+
} else {
130+
Write-Host "=> 使用 git clone 获取源码..."
131+
git clone --depth 1 --branch $Branch $Repo $WorkDir
132+
}
133+
} else {
134+
Write-Host "=> 未检测到 git,改用 ZIP 下载..."
135+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
136+
Invoke-WebRequest "$Repo/archive/refs/heads/$Branch.zip" -OutFile $ZipTmp
137+
# 清理旧目录再解压
138+
if (Test-Path $WorkDir) { Remove-Item -Recurse -Force $WorkDir }
139+
Expand-Archive -LiteralPath $ZipTmp -DestinationPath (Split-Path $WorkDir) -Force
140+
Rename-Item -Path (Join-Path (Split-Path $WorkDir) ("NodeProbe-" + $Branch)) -NewName (Split-Path $WorkDir -Leaf)
141+
}
142+
143+
# 5) 若缺少 Dockerfile,则按通用 Python 项目生成一个
144+
$Dockerfile = Join-Path $WorkDir "Dockerfile"
145+
if (-not (Test-Path $Dockerfile)) {
146+
Write-Host "=> 未发现 Dockerfile,自动生成通用版本..."
147+
@"
148+
FROM python:3.11-slim
149+
WORKDIR /app
150+
ENV PIP_DISABLE_PIP_VERSION_CHECK=1 PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
151+
# 基础依赖(按需追加系统库)
152+
RUN apt-get update && apt-get install -y --no-install-recommends build-essential && rm -rf /var/lib/apt/lists/*
153+
COPY . .
154+
RUN python -m pip install --upgrade pip && \
155+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
156+
EXPOSE ${AppPort}
157+
# 入口:如你的项目入口不同,请修改该行(例如 backend.main:app / app:app 等)
158+
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "${AppPort}"]
159+
"@ | Set-Content -Path $Dockerfile -Encoding UTF8
160+
}
161+
162+
# 6) 构建镜像
163+
Write-Host "=> 开始构建镜像:$Image"
164+
docker build -t $Image $WorkDir
165+
166+
# 7) 若已有同名容器则替换
167+
if ((docker ps -a --format '{{.Names}}') -contains $Container) {
168+
Write-Host "=> 发现已有容器,先移除:$Container"
169+
docker rm -f $Container | Out-Null
170+
}
171+
172+
# 8) 运行容器
173+
Write-Host "=> 启动容器:$Container 映射端口 $HostPort -> $AppPort"
174+
docker run -d --name $Container -p $HostPort:$AppPort --restart unless-stopped $Image | Out-Null
175+
176+
# 9) 简要健康检查与访问
177+
Start-Sleep -Seconds 2
178+
Write-Host "=> 近期日志(截断显示,Ctrl+C 结束跟随):"
179+
docker logs --tail 50 $Container
180+
Write-Host "=> 打开浏览器访问:http://localhost:$HostPort"
181+
try { Start-Process "http://localhost:$HostPort" } catch {}
182+
Write-Host "=== 部署完成 ==="
183+
```
184+
90185
## 更新日志
91186

92187
查看 [CHANGELOG.zh.md](CHANGELOG.zh.md) 或 [英文版](CHANGELOG.md) 了解最新功能与修复。

0 commit comments

Comments
 (0)