- 新增许可证服务器 (license-server/) - 新增 Agent 部署模块 (flnxi-agent/) - 添加许可证验证和激活页面 - 添加 Harbor 镜像同步脚本 - 更新素材系统支持许可证验证
189 lines
6.3 KiB
PowerShell
189 lines
6.3 KiB
PowerShell
# Harbor 镜像同步脚本
|
|
# 用于同步 Runtime 依赖镜像到 Harbor
|
|
|
|
param(
|
|
[string]$HarborHost = "harbor.flnxi.com",
|
|
[string]$HarborProject = "flnxi",
|
|
[switch]$DryRun = $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 # 测试版本
|
|
# └── runtime/ # 依赖镜像
|
|
# ├── postgres:16-alpine
|
|
# ├── minio:latest
|
|
# ├── redis:7-alpine
|
|
# └── nginx:alpine
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
# 国内镜像源(按优先级排序)
|
|
$MirrorRegistries = @(
|
|
"registry.cn-hangzhou.aliyuncs.com", # 阿里云
|
|
"mirror.ccs.tencentyun.com", # 腾讯云
|
|
"hub-mirror.c.163.com" # 网易
|
|
)
|
|
|
|
# 需要同步的依赖镜像
|
|
# 注意:部分镜像在国内源的路径可能不同
|
|
$RuntimeImages = @(
|
|
# PostgreSQL - 阿里云镜像
|
|
@{
|
|
Source = "postgres:16-alpine"
|
|
Mirror = "registry.cn-hangzhou.aliyuncs.com/library/postgres:16-alpine"
|
|
Target = "runtime/postgres:16-alpine"
|
|
},
|
|
# MinIO - 官方镜像(国内源可能没有)
|
|
@{
|
|
Source = "minio/minio:latest"
|
|
Mirror = "quay.io/minio/minio:latest" # Quay.io 备用
|
|
Target = "runtime/minio:latest"
|
|
},
|
|
# MinIO Client
|
|
@{
|
|
Source = "minio/mc:latest"
|
|
Mirror = "quay.io/minio/mc:latest"
|
|
Target = "runtime/mc:latest"
|
|
},
|
|
# Redis - 阿里云镜像
|
|
@{
|
|
Source = "redis:7-alpine"
|
|
Mirror = "registry.cn-hangzhou.aliyuncs.com/library/redis:7-alpine"
|
|
Target = "runtime/redis:7-alpine"
|
|
},
|
|
# Nginx - 阿里云镜像
|
|
@{
|
|
Source = "nginx:alpine"
|
|
Mirror = "registry.cn-hangzhou.aliyuncs.com/library/nginx:alpine"
|
|
Target = "runtime/nginx:alpine"
|
|
},
|
|
# Node.js - 阿里云镜像
|
|
@{
|
|
Source = "node:20-alpine"
|
|
Mirror = "registry.cn-hangzhou.aliyuncs.com/library/node:20-alpine"
|
|
Target = "runtime/node:20-alpine"
|
|
}
|
|
)
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "Harbor 镜像同步工具" -ForegroundColor Cyan
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
Write-Host "Harbor 地址: $HarborHost" -ForegroundColor Yellow
|
|
Write-Host "项目名称: $HarborProject" -ForegroundColor Yellow
|
|
Write-Host "模式: $(if ($DryRun) { '预览模式' } else { '执行模式' })" -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
# 检查 Docker 是否可用
|
|
try {
|
|
docker version | Out-Null
|
|
} catch {
|
|
Write-Host "错误: Docker 未安装或未运行" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
# 检查是否已登录 Harbor
|
|
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 登录状态: OK" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# 拉取镜像函数(优先使用国内镜像源)
|
|
function Pull-ImageWithMirror {
|
|
param(
|
|
[string]$Source,
|
|
[string]$Mirror
|
|
)
|
|
|
|
# 优先尝试国内镜像源
|
|
if ($Mirror) {
|
|
Write-Host " 尝试从国内镜像源拉取: $Mirror" -ForegroundColor Gray
|
|
$pullOutput = docker pull $Mirror 2>&1
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " 国内镜像源拉取成功 ✓" -ForegroundColor Green
|
|
# 重新打标签为原始名称,方便后续处理
|
|
docker tag $Mirror $Source 2>&1 | Out-Null
|
|
return $true
|
|
}
|
|
Write-Host " 国内镜像源拉取失败,尝试官方源..." -ForegroundColor Yellow
|
|
}
|
|
|
|
# 回退到官方源
|
|
Write-Host " 从官方源拉取: $Source" -ForegroundColor Gray
|
|
$pullOutput = docker pull $Source 2>&1
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " 官方源拉取成功 ✓" -ForegroundColor Green
|
|
return $true
|
|
}
|
|
|
|
Write-Host " 所有源拉取失败" -ForegroundColor Red
|
|
return $false
|
|
}
|
|
|
|
# 同步镜像
|
|
Write-Host "开始同步 Runtime 镜像..." -ForegroundColor Cyan
|
|
Write-Host "提示: 优先使用国内镜像源加速下载" -ForegroundColor Gray
|
|
Write-Host ""
|
|
|
|
$successCount = 0
|
|
$failCount = 0
|
|
|
|
foreach ($image in $RuntimeImages) {
|
|
$source = $image.Source
|
|
$mirror = $image.Mirror
|
|
$target = "$HarborHost/$HarborProject/$($image.Target)"
|
|
|
|
Write-Host "[$($RuntimeImages.IndexOf($image) + 1)/$($RuntimeImages.Count)] $source -> $target" -ForegroundColor White
|
|
|
|
if ($DryRun) {
|
|
Write-Host " [预览] 跳过实际操作" -ForegroundColor Gray
|
|
if ($mirror) {
|
|
Write-Host " 国内镜像源: $mirror" -ForegroundColor Gray
|
|
}
|
|
$successCount++
|
|
continue
|
|
}
|
|
|
|
try {
|
|
# 使用国内镜像源拉取
|
|
$pullSuccess = Pull-ImageWithMirror -Source $source -Mirror $mirror
|
|
if (-not $pullSuccess) { throw "拉取失败" }
|
|
|
|
# 打标签
|
|
Write-Host " 打标签为 Harbor 地址..." -ForegroundColor Gray
|
|
docker tag $source $target 2>&1 | Out-Null
|
|
if ($LASTEXITCODE -ne 0) { throw "打标签失败" }
|
|
|
|
# 推送到 Harbor
|
|
Write-Host " 推送到 Harbor..." -ForegroundColor Gray
|
|
docker push $target 2>&1 | Out-Null
|
|
if ($LASTEXITCODE -ne 0) { throw "推送失败" }
|
|
|
|
Write-Host " 完成 ✓" -ForegroundColor Green
|
|
$successCount++
|
|
} catch {
|
|
Write-Host " 失败 ✗: $_" -ForegroundColor Red
|
|
$failCount++
|
|
}
|
|
|
|
Write-Host ""
|
|
}
|
|
|
|
Write-Host "========================================" -ForegroundColor Cyan
|
|
Write-Host "同步完成" -ForegroundColor Cyan
|
|
Write-Host "成功: $successCount, 失败: $failCount" -ForegroundColor $(if ($failCount -eq 0) { "Green" } else { "Yellow" })
|
|
Write-Host "========================================" -ForegroundColor Cyan
|