gongxiangp2/scripts/load-base-images.ps1

59 lines
1.9 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 从本地加载基础镜像
# 在构建前调用,确保基础镜像已加载到 Docker
$ErrorActionPreference = "Stop"
# 优先从 flnxi_sucai/docker-images 加载(steering 里指定的缓存位置)
$projectRoot = Split-Path $PSScriptRoot -Parent
$baseImagesDir = Join-Path $projectRoot "flnxi_sucai\docker-images\node"
$baseImagesDir = [System.IO.Path]::GetFullPath($baseImagesDir)
Write-Host "检查本地基础镜像..." -ForegroundColor Cyan
if (-not (Test-Path $baseImagesDir)) {
Write-Host "基础镜像目录不存在: $baseImagesDir" -ForegroundColor Yellow
Write-Host "提示: 运行 scripts/save-base-images.ps1 来下载基础镜像" -ForegroundColor Gray
return
}
$tarFiles = Get-ChildItem -Path $baseImagesDir -Filter "*.tar" -ErrorAction SilentlyContinue
if ($tarFiles.Count -eq 0) {
Write-Host "未找到基础镜像文件" -ForegroundColor Yellow
Write-Host "提示: 运行 scripts/save-base-images.ps1 来下载基础镜像" -ForegroundColor Gray
return
}
$loadedCount = 0
$skippedCount = 0
foreach ($tarFile in $tarFiles) {
$imageName = $tarFile.BaseName -replace '-', ':'
# 检查镜像是否已存在
docker image inspect $imageName 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓ 镜像已存在: $imageName" -ForegroundColor Gray
$skippedCount++
continue
}
# 加载镜像
Write-Host " 正在加载: $($tarFile.Name) -> $imageName" -ForegroundColor Yellow
docker load -i $tarFile.FullName
if ($LASTEXITCODE -ne 0) {
Write-Host " ✗ 加载失败: $($tarFile.Name)" -ForegroundColor Red
continue
}
Write-Host " ✓ 加载成功: $imageName" -ForegroundColor Green
$loadedCount++
}
if ($loadedCount -gt 0) {
Write-Host "已加载 $loadedCount 个基础镜像" -ForegroundColor Green
} else {
Write-Host "所有基础镜像已就绪" -ForegroundColor Green
}