- 新增许可证服务器 (license-server/) - 新增 Agent 部署模块 (flnxi-agent/) - 添加许可证验证和激活页面 - 添加 Harbor 镜像同步脚本 - 更新素材系统支持许可证验证
159 lines
6.1 KiB
PowerShell
159 lines
6.1 KiB
PowerShell
# 素材系统镜像构建脚本
|
|
# 支持测试版和正式版分离
|
|
|
|
param(
|
|
[Parameter(Mandatory=$true)]
|
|
[ValidateSet("dev", "test", "release")]
|
|
[string]$Environment,
|
|
|
|
[string]$Version = "",
|
|
[string]$HarborHost = "harbor.flnxi.com",
|
|
[string]$HarborProject = "flnxi",
|
|
[switch]$Push = $false,
|
|
[switch]$NoBuild = $false
|
|
)
|
|
|
|
# Harbor 镜像路径规划:
|
|
# ┌─────────────────────────────────────────────────────────────────┐
|
|
# │ harbor.flnxi.com/flnxi/ │
|
|
# ├─────────────────────────────────────────────────────────────────┤
|
|
# │ material/ <- 正式版(客户拉取) │
|
|
# │ ├── flnxi-material:latest <- 最新正式版 │
|
|
# │ ├── flnxi-material:1.0.0 <- 版本标签 │
|
|
# │ └── flnxi-material:1.0.1 │
|
|
# ├─────────────────────────────────────────────────────────────────┤
|
|
# │ material-dev/ <- 测试版(开发测试用) │
|
|
# │ ├── flnxi-material:latest <- 最新测试版 │
|
|
# │ ├── flnxi-material:dev-xxx <- 开发分支 │
|
|
# │ └── flnxi-material:test-xxx<- 测试版本 │
|
|
# └─────────────────────────────────────────────────────────────────┘
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
# 根据环境确定镜像路径
|
|
$ImageName = "flnxi-material"
|
|
switch ($Environment) {
|
|
"dev" {
|
|
$HarborPath = "material-dev"
|
|
$DefaultTag = "dev-$(Get-Date -Format 'yyyyMMdd-HHmm')"
|
|
}
|
|
"test" {
|
|
$HarborPath = "material-dev"
|
|
$DefaultTag = "test-$(Get-Date -Format 'yyyyMMdd')"
|
|
}
|
|
"release" {
|
|
$HarborPath = "material"
|
|
if (-not $Version) {
|
|
# 从 VERSION.txt 读取版本号
|
|
if (Test-Path "VERSION.txt") {
|
|
$Version = (Get-Content "VERSION.txt" -Raw).Trim()
|
|
} else {
|
|
Write-Host "错误: 正式版必须指定版本号,或在 VERSION.txt 中定义" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
}
|
|
$DefaultTag = $Version
|
|
}
|
|
}
|
|
|
|
$Tag = if ($Version) { $Version } else { $DefaultTag }
|
|
$FullImageName = "$HarborHost/$HarborProject/$HarborPath/${ImageName}:${Tag}"
|
|
$LatestImageName = "$HarborHost/$HarborProject/$HarborPath/${ImageName}:latest"
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "素材系统镜像构建工具" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "环境: $Environment" -ForegroundColor Yellow
|
|
Write-Host "版本: $Tag" -ForegroundColor Yellow
|
|
Write-Host "镜像: $FullImageName" -ForegroundColor Yellow
|
|
Write-Host "推送: $(if ($Push) { '是' } else { '否' })" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
# 检查 Docker 是否可用
|
|
try {
|
|
docker version | Out-Null
|
|
} catch {
|
|
Write-Host "错误: Docker 未安装或未运行" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 构建镜像
|
|
if (-not $NoBuild) {
|
|
Write-Host "开始构建镜像..." -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# 构建参数
|
|
$buildArgs = @(
|
|
"build",
|
|
"-t", $FullImageName,
|
|
"-t", $LatestImageName,
|
|
"--build-arg", "APP_VERSION=$Tag",
|
|
"."
|
|
)
|
|
|
|
# 执行构建
|
|
$process = Start-Process -FilePath "docker" -ArgumentList $buildArgs -NoNewWindow -Wait -PassThru
|
|
|
|
if ($process.ExitCode -ne 0) {
|
|
Write-Host "构建失败!" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "构建完成 ✓" -ForegroundColor Green
|
|
Write-Host ""
|
|
}
|
|
|
|
# 推送镜像
|
|
if ($Push) {
|
|
Write-Host "检查 Harbor 登录状态..." -ForegroundColor Gray
|
|
$loginCheck = docker login $HarborHost 2>&1
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "请先登录 Harbor:" -ForegroundColor Yellow
|
|
Write-Host " docker login $HarborHost" -ForegroundColor White
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "推送镜像到 Harbor..." -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# 推送版本标签
|
|
Write-Host "推送 $FullImageName ..." -ForegroundColor Gray
|
|
docker push $FullImageName
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "推送失败!" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 推送 latest 标签
|
|
Write-Host "推送 $LatestImageName ..." -ForegroundColor Gray
|
|
docker push $LatestImageName
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "推送失败!" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "推送完成 ✓" -ForegroundColor Green
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "操作完成" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "镜像信息:" -ForegroundColor White
|
|
Write-Host " 版本标签: $FullImageName" -ForegroundColor Gray
|
|
Write-Host " 最新标签: $LatestImageName" -ForegroundColor Gray
|
|
Write-Host ""
|
|
|
|
if ($Environment -eq "release") {
|
|
Write-Host "提示: 正式版镜像已发布,客户可通过以下地址拉取:" -ForegroundColor Yellow
|
|
Write-Host " $HarborHost/$HarborProject/material/flnxi-material:latest" -ForegroundColor White
|
|
} else {
|
|
Write-Host "提示: 测试版镜像已发布到 material-dev 目录" -ForegroundColor Yellow
|
|
Write-Host " 测试完成后,使用以下命令发布正式版:" -ForegroundColor Gray
|
|
Write-Host " .\scripts\build-material-image.ps1 -Environment release -Version $Tag -Push" -ForegroundColor White
|
|
}
|