flnxi-Wu/scripts/push-base-images.ps1
WuYongJie d1c6efc79d
Some checks failed
CI Check / check (push) Has been cancelled
feat: NAS 部署与 Harbor 推送流程
2025-12-03 14:39:06 +08:00

71 lines
2.2 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 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
}