feat(deploy): automate Windows setup and startup

Prepare a local Python environment, install dependencies and run first-time setup before starting OSE.
This commit is contained in:
rekushi committed 2026-10-29 04:40:10 +00:00
1 parent 5076f77b55
commit 5295c86d30
1 file changed
+36
+36
View File
@@ -0,0 +1,36 @@
param([Parameter(ValueFromRemainingArguments = $true)][string[]]$ServerArguments)
$ErrorActionPreference = 'Stop'
Set-Location -LiteralPath $PSScriptRoot
$environmentDirectory = Join-Path $PSScriptRoot '.venv'
$pythonExecutable = Join-Path $environmentDirectory 'Scripts\python.exe'
if (-not (Test-Path -LiteralPath $pythonExecutable)) {
Write-Host 'Preparing the Python environment...'
if (Get-Command py -ErrorAction SilentlyContinue) {
& py -3 -m venv $environmentDirectory
} elseif (Get-Command python -ErrorAction SilentlyContinue) {
& python -m venv $environmentDirectory
} else {
throw 'Install Python 3.10 or newer from python.org, then run this script again.'
}
if ($LASTEXITCODE -ne 0) { throw 'Could not create the Python environment.' }
}
& $pythonExecutable -c 'import sys; raise SystemExit(0 if sys.version_info >= (3,10) else 1)'
if ($LASTEXITCODE -ne 0) { throw 'Python 3.10 or newer is required. Recreate .venv with a supported Python installation.' }
$requirements = Join-Path $PSScriptRoot 'requirements.txt'
$fingerprint = (Get-FileHash -LiteralPath $requirements -Algorithm SHA256).Hash
$marker = Join-Path $environmentDirectory 'ose-requirements.sha256'
$previous = if (Test-Path -LiteralPath $marker) { (Get-Content -LiteralPath $marker -Raw).Trim() } else { '' }
if ($previous -ne $fingerprint) {
Write-Host 'Installing the server dependencies. This may take a few minutes the first time...'
& $pythonExecutable -m pip install -r $requirements
if ($LASTEXITCODE -ne 0) { throw 'Dependency installation failed. Check the error above, then run this script again.' }
Set-Content -LiteralPath $marker -Value $fingerprint -Encoding Ascii
}
& $pythonExecutable -c 'from server_config import load_config; raise SystemExit(0 if load_config()["setup_complete"] else 1)'
if ($LASTEXITCODE -ne 0) {
& $pythonExecutable (Join-Path $PSScriptRoot 'manage.py') setup
if ($LASTEXITCODE -ne 0) { throw 'Setup was not completed. Run this script again when ready.' }
}
Write-Host 'Starting OSE. Press Ctrl+C in this window to stop it.'
& $pythonExecutable -u (Join-Path $PSScriptRoot 'server.py') @ServerArguments
exit $LASTEXITCODE