Some checks failed
Build and Deploy / test-backend (push) Has been cancelled
Build and Deploy / build-backend (push) Has been cancelled
Build and Deploy / build-admin (push) Has been cancelled
Deploy to Production / build-backend (push) Has been cancelled
Deploy to Production / deploy (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
100 lines
3.5 KiB
PowerShell
100 lines
3.5 KiB
PowerShell
# 使用镜像源构建并推送镜像
|
|
# 用途:解决无法连接 Docker Hub 的问题
|
|
|
|
param(
|
|
[string]$RegistryUrl = "registry.667788.cool",
|
|
[string]$Namespace = "wecom-ai",
|
|
[string]$Tag = "latest"
|
|
)
|
|
|
|
Write-Host "=== 使用镜像源构建并推送镜像 ===" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# 镜像源配置(按优先级)
|
|
$mirrors = @(
|
|
"docker.mirrors.ustc.edu.cn/library",
|
|
"hub-mirror.c.163.com",
|
|
"mirror.baidubce.com"
|
|
)
|
|
|
|
$pythonImage = "python:3.12-slim"
|
|
$nodeImage = "node:20-alpine"
|
|
|
|
Write-Host "尝试使用镜像源构建..." -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
# 尝试使用第一个镜像源
|
|
$mirrorBase = $mirrors[0]
|
|
$pythonMirror = "${mirrorBase}/${pythonImage}"
|
|
$nodeMirror = "${mirrorBase}/${nodeImage}"
|
|
|
|
Write-Host "使用镜像源: $mirrorBase" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# 构建 Backend 镜像
|
|
Write-Host "=== 构建 Backend 镜像 ===" -ForegroundColor Cyan
|
|
$backendImage = "${RegistryUrl}/${Namespace}/wecom-ai-backend:${Tag}"
|
|
Write-Host "镜像: $backendImage" -ForegroundColor Gray
|
|
Write-Host "基础镜像: $pythonMirror" -ForegroundColor Gray
|
|
Write-Host ""
|
|
|
|
Write-Host "构建中..." -ForegroundColor Yellow
|
|
docker build --build-arg PYTHON_IMAGE=$pythonMirror -f deploy/docker/backend.Dockerfile -t $backendImage .
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "✗ Backend 构建失败" -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host "请尝试以下解决方案:" -ForegroundColor Yellow
|
|
Write-Host "1. 配置 Docker Desktop 镜像加速(推荐)" -ForegroundColor Gray
|
|
Write-Host " Docker Desktop → Settings → Docker Engine" -ForegroundColor Gray
|
|
Write-Host " 添加: `"registry-mirrors\": [\"https://docker.mirrors.ustc.edu.cn\"]`" -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host "2. 使用代理" -ForegroundColor Gray
|
|
Write-Host ""
|
|
Write-Host "3. 手动拉取基础镜像后再构建" -ForegroundColor Gray
|
|
Write-Host " docker pull $pythonMirror" -ForegroundColor Gray
|
|
exit 1
|
|
}
|
|
Write-Host "✓ Backend 构建成功" -ForegroundColor Green
|
|
|
|
Write-Host "推送中..." -ForegroundColor Yellow
|
|
docker push $backendImage
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "✗ Backend 推送失败" -ForegroundColor Red
|
|
Write-Host "提示: 请检查 Registry 是否需要登录" -ForegroundColor Yellow
|
|
Write-Host " docker login $RegistryUrl" -ForegroundColor Gray
|
|
exit 1
|
|
}
|
|
Write-Host "✓ Backend 推送成功" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# 构建 Admin 镜像
|
|
Write-Host "=== 构建 Admin 镜像 ===" -ForegroundColor Cyan
|
|
$adminImage = "${RegistryUrl}/${Namespace}/wecom-ai-admin:${Tag}"
|
|
Write-Host "镜像: $adminImage" -ForegroundColor Gray
|
|
Write-Host "基础镜像: $nodeMirror" -ForegroundColor Gray
|
|
Write-Host ""
|
|
|
|
Write-Host "构建中..." -ForegroundColor Yellow
|
|
docker build --build-arg NODE_IMAGE=$nodeMirror -f deploy/docker/admin.Dockerfile -t $adminImage .
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "✗ Admin 构建失败" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
Write-Host "✓ Admin 构建成功" -ForegroundColor Green
|
|
|
|
Write-Host "推送中..." -ForegroundColor Yellow
|
|
docker push $adminImage
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "✗ Admin 推送失败" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
Write-Host "✓ Admin 推送成功" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
Write-Host "=== 完成 ===" -ForegroundColor Green
|
|
Write-Host ""
|
|
Write-Host "镜像已推送到:" -ForegroundColor Cyan
|
|
Write-Host " - $backendImage" -ForegroundColor Gray
|
|
Write-Host " - $adminImage" -ForegroundColor Gray
|
|
Write-Host ""
|