71 lines
2.2 KiB
PowerShell
71 lines
2.2 KiB
PowerShell
# 推送基础镜像到 Docker Registry
|
||
# 用于将基础镜像(如 node:18-alpine)推送到私有 Registry,避免网络问题
|
||
|
||
param(
|
||
[string]$Server = "45.249.208.118",
|
||
[string]$RegistryUrl = "${Server}:5000"
|
||
)
|
||
|
||
$ErrorActionPreference = "Stop"
|
||
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host " 推送基础镜像到 Docker Registry" -ForegroundColor Cyan
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
Write-Host ""
|
||
|
||
# 基础镜像列表
|
||
$baseImages = @(
|
||
"node:18-alpine"
|
||
)
|
||
|
||
$pushedCount = 0
|
||
|
||
foreach ($baseImage in $baseImages) {
|
||
Write-Host "处理基础镜像: $baseImage" -ForegroundColor Yellow
|
||
|
||
# 检查本地是否存在
|
||
$localCheck = docker images --format "{{.Repository}}:{{.Tag}}" | Select-String -Pattern "^${baseImage}$"
|
||
if (-not $localCheck) {
|
||
Write-Host " 本地不存在,尝试拉取..." -ForegroundColor Gray
|
||
docker pull $baseImage
|
||
if ($LASTEXITCODE -ne 0) {
|
||
Write-Host " ✗ 拉取失败,跳过" -ForegroundColor Red
|
||
continue
|
||
}
|
||
}
|
||
|
||
# 生成Registry镜像名称
|
||
$imageName = $baseImage -replace ":", "-"
|
||
$registryImage = "${RegistryUrl}/youyidian/base-${imageName}:latest"
|
||
|
||
# 标记镜像
|
||
Write-Host " 标记镜像: $registryImage" -ForegroundColor Gray
|
||
docker tag $baseImage $registryImage
|
||
if ($LASTEXITCODE -ne 0) {
|
||
Write-Host " ✗ 标记失败" -ForegroundColor Red
|
||
continue
|
||
}
|
||
|
||
# 推送镜像
|
||
Write-Host " 推送镜像到Registry..." -ForegroundColor Gray
|
||
docker push $registryImage
|
||
if ($LASTEXITCODE -eq 0) {
|
||
Write-Host " ✓ 推送成功: $registryImage" -ForegroundColor Green
|
||
$pushedCount++
|
||
} else {
|
||
Write-Host " ✗ 推送失败" -ForegroundColor Red
|
||
}
|
||
|
||
Write-Host ""
|
||
}
|
||
|
||
Write-Host "========================================" -ForegroundColor Cyan
|
||
if ($pushedCount -gt 0) {
|
||
Write-Host "完成!已推送 $pushedCount 个基础镜像" -ForegroundColor Green
|
||
Write-Host ""
|
||
Write-Host "现在可以在构建时从Registry拉取基础镜像,避免网络问题" -ForegroundColor Cyan
|
||
} else {
|
||
Write-Host "未成功推送任何镜像" -ForegroundColor Yellow
|
||
}
|
||
|