110 lines
3.7 KiB
PowerShell
110 lines
3.7 KiB
PowerShell
# FLNXI 客户首装向导脚本
|
||
# 这是对 smoke-install.ps1 的分步骤包装,不替代 docker-compose.prod.yml。
|
||
|
||
param(
|
||
[string]$ProjectDir = ".",
|
||
[string]$ComposeFile = "docker-compose.prod.yml",
|
||
[string]$EnvFile = ".env",
|
||
[string]$ExpectedVersion = "",
|
||
[switch]$Start,
|
||
[switch]$PrepareDirectories,
|
||
[switch]$PlanOnly,
|
||
[switch]$SkipMigrationStatus,
|
||
[switch]$SkipObjectStorageCheck,
|
||
[int]$HealthTimeoutSeconds = 120
|
||
)
|
||
|
||
Set-StrictMode -Version Latest
|
||
$ErrorActionPreference = "Stop"
|
||
|
||
function Write-Step {
|
||
param([int]$Number, [string]$Message)
|
||
Write-Host ""
|
||
Write-Host "[$Number/4] $Message" -ForegroundColor Cyan
|
||
}
|
||
|
||
function Invoke-SmokeInstall {
|
||
param([string[]]$ExtraArgs)
|
||
|
||
$scriptPath = Join-Path $PSScriptRoot "smoke-install.ps1"
|
||
if (-not (Test-Path -LiteralPath $scriptPath -PathType Leaf)) {
|
||
throw "找不到 smoke-install.ps1:$scriptPath"
|
||
}
|
||
|
||
$smokeArgs = @(
|
||
"-ProjectDir", $ProjectDir,
|
||
"-ComposeFile", $ComposeFile,
|
||
"-EnvFile", $EnvFile,
|
||
"-HealthTimeoutSeconds", "$HealthTimeoutSeconds"
|
||
)
|
||
|
||
if ($SkipMigrationStatus) {
|
||
$smokeArgs += "-SkipMigrationStatus"
|
||
}
|
||
if ($SkipObjectStorageCheck) {
|
||
$smokeArgs += "-SkipObjectStorageCheck"
|
||
}
|
||
if (-not [string]::IsNullOrWhiteSpace($ExpectedVersion)) {
|
||
$smokeArgs += @("-ExpectedVersion", $ExpectedVersion)
|
||
}
|
||
|
||
& powershell -ExecutionPolicy Bypass -File $scriptPath @smokeArgs @ExtraArgs
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "安装验收步骤失败,退出码:$LASTEXITCODE"
|
||
}
|
||
}
|
||
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host " FLNXI 客户首装向导" -ForegroundColor Cyan
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host "部署目录:$ProjectDir"
|
||
Write-Host "Compose:$ComposeFile"
|
||
Write-Host "环境文件:$EnvFile"
|
||
|
||
Write-Step 1 "检查部署文件和客户现场配置"
|
||
Write-Host "会检查 .env、APP_IMAGE、许可证参数、数据目录和常见占位值。"
|
||
if ($PrepareDirectories) {
|
||
Write-Host "缺少 uploads/data 目录时会自动创建并测试写入。"
|
||
}
|
||
|
||
if ($PlanOnly) {
|
||
Write-Step 2 "准备启动方式"
|
||
Write-Host "如果希望脚本启动容器,请重新执行并加 -Start。"
|
||
Write-Host "如果已经通过 NAS 图形界面启动,则不加 -Start,脚本只做验收。"
|
||
Write-Step 3 "运行首装验收"
|
||
Write-Host "验收内容包括 Compose 配置、容器状态、运行镜像、VERSION.txt、/api/health、Prisma 迁移状态和 MinIO bucket。"
|
||
if (-not [string]::IsNullOrWhiteSpace($ExpectedVersion)) {
|
||
Write-Host "会额外确认当前运行版本等于:$ExpectedVersion。"
|
||
}
|
||
Write-Step 4 "查看结果"
|
||
Write-Host "所有步骤通过后,浏览器打开 APP_PUBLIC_URL / NEXTAUTH_URL。"
|
||
Write-Host "如失败,根据脚本输出先修 .env、镜像、目录权限或容器日志。"
|
||
return
|
||
}
|
||
|
||
$preflightArgs = @("-PreflightOnly")
|
||
if ($PrepareDirectories) {
|
||
$preflightArgs += "-PrepareDirectories"
|
||
}
|
||
Invoke-SmokeInstall -ExtraArgs $preflightArgs
|
||
|
||
Write-Step 2 "确认容器启动方式"
|
||
if ($Start) {
|
||
Write-Host "将由脚本执行 docker compose up -d。"
|
||
} else {
|
||
Write-Host "未传 -Start,默认认为容器已由 NAS 图形界面或其它编排入口启动。"
|
||
}
|
||
|
||
Write-Step 3 "执行首装启动和验收"
|
||
$verifyArgs = @()
|
||
if ($Start) {
|
||
$verifyArgs += "-Start"
|
||
}
|
||
if ($PrepareDirectories) {
|
||
$verifyArgs += "-PrepareDirectories"
|
||
}
|
||
Invoke-SmokeInstall -ExtraArgs $verifyArgs
|
||
|
||
Write-Step 4 "完成"
|
||
Write-Host "首装向导完成。下一步请用浏览器打开 APP_PUBLIC_URL / NEXTAUTH_URL,并完成管理员初始化、登录、上传和下载验收。"
|