Add build verification scripts and documentation
Some checks are pending
Build and Deploy / test-backend (push) Waiting to run
Build and Deploy / build-backend (push) Blocked by required conditions
Build and Deploy / build-admin (push) Waiting to run
Deploy to Production / build-backend (push) Waiting to run
Deploy to Production / deploy (push) Blocked by required conditions
Some checks are pending
Build and Deploy / test-backend (push) Waiting to run
Build and Deploy / build-backend (push) Blocked by required conditions
Build and Deploy / build-admin (push) Waiting to run
Deploy to Production / build-backend (push) Waiting to run
Deploy to Production / deploy (push) Blocked by required conditions
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
164
VERIFY_BUILD.md
Normal file
164
VERIFY_BUILD.md
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
# 验证构建和推送是否成功
|
||||||
|
|
||||||
|
## 快速验证步骤
|
||||||
|
|
||||||
|
### 1. 检查本地镜像
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 查看所有 registry.667788.cool 的镜像
|
||||||
|
docker images registry.667788.cool/wecom-backend
|
||||||
|
docker images registry.667788.cool/wecom-admin
|
||||||
|
docker images registry.667788.cool/wecom-nginx
|
||||||
|
|
||||||
|
# 或查看所有镜像
|
||||||
|
docker images | Select-String "registry.667788.cool"
|
||||||
|
```
|
||||||
|
|
||||||
|
**预期结果**:应该看到三个镜像:
|
||||||
|
- `registry.667788.cool/wecom-backend:latest`
|
||||||
|
- `registry.667788.cool/wecom-admin:latest`
|
||||||
|
- `registry.667788.cool/wecom-nginx:latest`
|
||||||
|
|
||||||
|
### 2. 检查镜像详细信息
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 查看镜像详细信息
|
||||||
|
docker images registry.667788.cool/wecom-backend:latest --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}\t{{.CreatedAt}}"
|
||||||
|
docker images registry.667788.cool/wecom-admin:latest --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}\t{{.CreatedAt}}"
|
||||||
|
docker images registry.667788.cool/wecom-nginx:latest --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}\t{{.CreatedAt}}"
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. 测试镜像是否可以运行
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 测试 Backend 镜像(检查 Python 版本)
|
||||||
|
docker run --rm registry.667788.cool/wecom-backend:latest python --version
|
||||||
|
|
||||||
|
# 测试 Admin 镜像(检查 Node 版本)
|
||||||
|
docker run --rm registry.667788.cool/wecom-admin:latest node --version
|
||||||
|
|
||||||
|
# 测试 Nginx 镜像(检查 Nginx 版本)
|
||||||
|
docker run --rm registry.667788.cool/wecom-nginx:latest nginx -v
|
||||||
|
```
|
||||||
|
|
||||||
|
**预期结果**:每个命令都应该成功执行并显示版本信息。
|
||||||
|
|
||||||
|
### 4. 验证镜像是否已推送到 Registry
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 登录 Registry(如果需要)
|
||||||
|
docker login registry.667788.cool
|
||||||
|
|
||||||
|
# 尝试拉取镜像(如果已推送,应该能拉取)
|
||||||
|
docker pull registry.667788.cool/wecom-backend:latest
|
||||||
|
docker pull registry.667788.cool/wecom-admin:latest
|
||||||
|
docker pull registry.667788.cool/wecom-nginx:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
**预期结果**:
|
||||||
|
- 如果镜像已推送:会显示 "Image is up to date" 或重新下载
|
||||||
|
- 如果镜像未推送:会显示 "not found" 或 "unauthorized"
|
||||||
|
|
||||||
|
### 5. 检查构建日志
|
||||||
|
|
||||||
|
如果构建失败,查看构建日志:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# 查看最近的构建输出
|
||||||
|
# 或重新运行构建脚本查看详细输出
|
||||||
|
.\scripts\build_and_push.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
## 完整验证清单
|
||||||
|
|
||||||
|
- [ ] 本地镜像已构建
|
||||||
|
- [ ] `registry.667788.cool/wecom-backend:latest` 存在
|
||||||
|
- [ ] `registry.667788.cool/wecom-admin:latest` 存在
|
||||||
|
- [ ] `registry.667788.cool/wecom-nginx:latest` 存在
|
||||||
|
|
||||||
|
- [ ] 镜像可以正常运行
|
||||||
|
- [ ] Backend 镜像可以运行 Python
|
||||||
|
- [ ] Admin 镜像可以运行 Node
|
||||||
|
- [ ] Nginx 镜像可以运行 Nginx
|
||||||
|
|
||||||
|
- [ ] 镜像已推送到 Registry
|
||||||
|
- [ ] 可以成功拉取 Backend 镜像
|
||||||
|
- [ ] 可以成功拉取 Admin 镜像
|
||||||
|
- [ ] 可以成功拉取 Nginx 镜像
|
||||||
|
|
||||||
|
## 常见问题
|
||||||
|
|
||||||
|
### 问题:镜像未找到
|
||||||
|
|
||||||
|
**原因**:构建可能失败或未完成
|
||||||
|
|
||||||
|
**解决方案**:
|
||||||
|
```powershell
|
||||||
|
# 重新运行构建脚本
|
||||||
|
.\scripts\build_and_push.ps1
|
||||||
|
|
||||||
|
# 查看详细输出,检查错误信息
|
||||||
|
```
|
||||||
|
|
||||||
|
### 问题:推送失败
|
||||||
|
|
||||||
|
**原因**:Registry 需要认证或网络问题
|
||||||
|
|
||||||
|
**解决方案**:
|
||||||
|
```powershell
|
||||||
|
# 登录 Registry
|
||||||
|
docker login registry.667788.cool
|
||||||
|
|
||||||
|
# 重新推送
|
||||||
|
docker push registry.667788.cool/wecom-backend:latest
|
||||||
|
docker push registry.667788.cool/wecom-admin:latest
|
||||||
|
docker push registry.667788.cool/wecom-nginx:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
### 问题:镜像可以构建但无法推送
|
||||||
|
|
||||||
|
**检查项**:
|
||||||
|
1. Registry 是否需要认证
|
||||||
|
2. 网络连接是否正常
|
||||||
|
3. 镜像名称格式是否正确
|
||||||
|
|
||||||
|
## 一键验证脚本
|
||||||
|
|
||||||
|
运行验证脚本:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
.\scripts\verify-build.ps1
|
||||||
|
```
|
||||||
|
|
||||||
|
脚本会自动检查:
|
||||||
|
- 本地镜像是否存在
|
||||||
|
- Registry 连接是否正常
|
||||||
|
- 镜像是否可以拉取
|
||||||
|
|
||||||
|
## 成功标志
|
||||||
|
|
||||||
|
如果看到以下输出,说明构建和推送成功:
|
||||||
|
|
||||||
|
```
|
||||||
|
✓ Backend 镜像已构建
|
||||||
|
✓ Admin 镜像已构建
|
||||||
|
✓ Nginx 镜像已构建
|
||||||
|
✓ 所有镜像已推送到 Registry
|
||||||
|
```
|
||||||
|
|
||||||
|
## 下一步
|
||||||
|
|
||||||
|
验证成功后:
|
||||||
|
|
||||||
|
1. **在服务器上部署**:
|
||||||
|
```bash
|
||||||
|
cd deploy
|
||||||
|
docker login registry.667788.cool
|
||||||
|
docker compose -f docker-compose.prod.yml --env-file .env.prod pull
|
||||||
|
docker compose -f docker-compose.prod.yml --env-file .env.prod up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **验证部署**:
|
||||||
|
```bash
|
||||||
|
curl http://your-server/api/health
|
||||||
|
```
|
||||||
42
scripts/quick-verify.ps1
Normal file
42
scripts/quick-verify.ps1
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# 快速验证构建结果
|
||||||
|
|
||||||
|
$Registry = "registry.667788.cool"
|
||||||
|
$Tag = "latest"
|
||||||
|
|
||||||
|
Write-Host "=== 快速验证构建结果 ===" -ForegroundColor Cyan
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
$images = @(
|
||||||
|
"$Registry/wecom-backend:$Tag",
|
||||||
|
"$Registry/wecom-admin:$Tag",
|
||||||
|
"$Registry/wecom-nginx:$Tag"
|
||||||
|
)
|
||||||
|
|
||||||
|
$successCount = 0
|
||||||
|
|
||||||
|
foreach ($image in $images) {
|
||||||
|
$result = docker images $image --format "{{.Repository}}:{{.Tag}}" 2>$null
|
||||||
|
if ($result -and $result -eq $image) {
|
||||||
|
Write-Host "✓ $image" -ForegroundColor Green
|
||||||
|
$successCount++
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ $image (未找到)" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "结果: $successCount/3 个镜像已构建" -ForegroundColor $(if ($successCount -eq 3) { "Green" } else { "Yellow" })
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
if ($successCount -eq 3) {
|
||||||
|
Write-Host "✓ 所有镜像构建成功!" -ForegroundColor Green
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "验证推送:" -ForegroundColor Yellow
|
||||||
|
Write-Host " docker login $Registry" -ForegroundColor Gray
|
||||||
|
Write-Host " docker pull $Registry/wecom-backend:$Tag" -ForegroundColor Gray
|
||||||
|
} else {
|
||||||
|
Write-Host "⚠ 部分镜像未构建,请检查构建日志" -ForegroundColor Yellow
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "重新构建:" -ForegroundColor Yellow
|
||||||
|
Write-Host " .\scripts\build_and_push.ps1" -ForegroundColor Gray
|
||||||
|
}
|
||||||
46
scripts/test-images.ps1
Normal file
46
scripts/test-images.ps1
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# 测试 Docker 镜像
|
||||||
|
# 用途:快速测试镜像是否可以正常运行
|
||||||
|
|
||||||
|
param(
|
||||||
|
[string]$Tag = "latest",
|
||||||
|
[string]$Registry = "registry.667788.cool"
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "=== 测试 Docker 镜像 ===" -ForegroundColor Cyan
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 测试 Backend 镜像
|
||||||
|
Write-Host "1. 测试 Backend 镜像..." -ForegroundColor Yellow
|
||||||
|
$backendImage = "$Registry/wecom-backend:$Tag"
|
||||||
|
docker run --rm $backendImage python --version
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "✓ Backend 镜像正常" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ Backend 镜像测试失败" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 测试 Admin 镜像
|
||||||
|
Write-Host "2. 测试 Admin 镜像..." -ForegroundColor Yellow
|
||||||
|
$adminImage = "$Registry/wecom-admin:$Tag"
|
||||||
|
docker run --rm $adminImage node --version
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "✓ Admin 镜像正常" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ Admin 镜像测试失败" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 测试 Nginx 镜像
|
||||||
|
Write-Host "3. 测试 Nginx 镜像..." -ForegroundColor Yellow
|
||||||
|
$nginxImage = "$Registry/wecom-nginx:$Tag"
|
||||||
|
docker run --rm $nginxImage nginx -v
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host "✓ Nginx 镜像正常" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host "✗ Nginx 镜像测试失败" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
Write-Host "=== 测试完成 ===" -ForegroundColor Cyan
|
||||||
|
Write-Host ""
|
||||||
118
scripts/verify-build.ps1
Normal file
118
scripts/verify-build.ps1
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
# 验证构建和推送是否成功
|
||||||
|
# 用途:检查镜像是否已构建并推送到 Registry
|
||||||
|
|
||||||
|
param(
|
||||||
|
[string]$Tag = "latest",
|
||||||
|
[string]$Registry = "registry.667788.cool"
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "=== 验证构建和推送结果 ===" -ForegroundColor Cyan
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Registry: $Registry" -ForegroundColor Gray
|
||||||
|
Write-Host "Tag: $Tag" -ForegroundColor Gray
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
$images = @(
|
||||||
|
"$Registry/wecom-backend:$Tag",
|
||||||
|
"$Registry/wecom-admin:$Tag",
|
||||||
|
"$Registry/wecom-nginx:$Tag"
|
||||||
|
)
|
||||||
|
|
||||||
|
$allSuccess = $true
|
||||||
|
|
||||||
|
# 1. 检查本地镜像
|
||||||
|
Write-Host "1. 检查本地镜像..." -ForegroundColor Yellow
|
||||||
|
foreach ($image in $images) {
|
||||||
|
$result = docker images $image --format "{{.Repository}}:{{.Tag}}" 2>$null
|
||||||
|
if ($result -and $result -eq $image) {
|
||||||
|
$size = docker images $image --format "{{.Size}}" 2>$null
|
||||||
|
Write-Host " ✓ $image ($size)" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host " ✗ $image (未找到)" -ForegroundColor Red
|
||||||
|
$allSuccess = $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 2. 测试 Registry 连接
|
||||||
|
Write-Host "2. 测试 Registry 连接..." -ForegroundColor Yellow
|
||||||
|
try {
|
||||||
|
$testResult = Test-NetConnection -ComputerName $Registry -Port 443 -InformationLevel Quiet -WarningAction SilentlyContinue 2>$null
|
||||||
|
if ($testResult) {
|
||||||
|
Write-Host " ✓ Registry 网络连接正常" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
Write-Host " ⚠ Registry 网络连接可能有问题" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Host " ⚠ 无法测试网络连接" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 3. 测试拉取镜像(验证推送是否成功)
|
||||||
|
Write-Host "3. 测试拉取镜像(验证推送是否成功)..." -ForegroundColor Yellow
|
||||||
|
Write-Host " 提示: 如果镜像已推送,可以尝试拉取验证" -ForegroundColor Gray
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
foreach ($image in $images) {
|
||||||
|
Write-Host " 测试: $image" -ForegroundColor Gray
|
||||||
|
$pullResult = docker pull $image 2>&1
|
||||||
|
if ($LASTEXITCODE -eq 0) {
|
||||||
|
Write-Host " ✓ 拉取成功(镜像已推送到 Registry)" -ForegroundColor Green
|
||||||
|
} else {
|
||||||
|
$errorMsg = $pullResult | Select-String -Pattern "error|not found|unauthorized" -CaseSensitive:$false
|
||||||
|
if ($errorMsg) {
|
||||||
|
Write-Host " ✗ 拉取失败: $errorMsg" -ForegroundColor Red
|
||||||
|
Write-Host " 可能原因:" -ForegroundColor Yellow
|
||||||
|
Write-Host " - 镜像尚未推送" -ForegroundColor Gray
|
||||||
|
Write-Host " - Registry 需要认证" -ForegroundColor Gray
|
||||||
|
Write-Host " - 网络连接问题" -ForegroundColor Gray
|
||||||
|
} else {
|
||||||
|
Write-Host " ⚠ 无法验证(可能需要先登录 Registry)" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 4. 检查镜像详细信息
|
||||||
|
Write-Host "4. 镜像详细信息..." -ForegroundColor Yellow
|
||||||
|
foreach ($image in $images) {
|
||||||
|
$localImage = docker images $image --format "{{.Repository}}:{{.Tag}} {{.Size}} {{.CreatedAt}}" 2>$null
|
||||||
|
if ($localImage) {
|
||||||
|
Write-Host " $image" -ForegroundColor Cyan
|
||||||
|
Write-Host " $localImage" -ForegroundColor Gray
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 5. 验证镜像内容(可选)
|
||||||
|
Write-Host "5. 验证镜像内容(可选)..." -ForegroundColor Yellow
|
||||||
|
Write-Host " 可以运行以下命令测试镜像:" -ForegroundColor Gray
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host " # 测试 Backend 镜像" -ForegroundColor Gray
|
||||||
|
Write-Host " docker run --rm $Registry/wecom-backend:$Tag python --version" -ForegroundColor Gray
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host " # 测试 Admin 镜像" -ForegroundColor Gray
|
||||||
|
Write-Host " docker run --rm $Registry/wecom-admin:$Tag node --version" -ForegroundColor Gray
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host " # 测试 Nginx 镜像" -ForegroundColor Gray
|
||||||
|
Write-Host " docker run --rm $Registry/wecom-nginx:$Tag nginx -v" -ForegroundColor Gray
|
||||||
|
Write-Host ""
|
||||||
|
|
||||||
|
# 总结
|
||||||
|
Write-Host "=== 验证完成 ===" -ForegroundColor Cyan
|
||||||
|
Write-Host ""
|
||||||
|
if ($allSuccess) {
|
||||||
|
Write-Host "✓ 所有镜像已成功构建" -ForegroundColor Green
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "下一步:" -ForegroundColor Yellow
|
||||||
|
Write-Host " 1. 如果尚未推送,运行: .\scripts\build_and_push.ps1 -Tag $Tag" -ForegroundColor Gray
|
||||||
|
Write-Host " 2. 在服务器上拉取镜像并部署" -ForegroundColor Gray
|
||||||
|
Write-Host " 3. 参考 README_DEPLOY.md 进行部署" -ForegroundColor Gray
|
||||||
|
} else {
|
||||||
|
Write-Host "⚠ 部分镜像未找到,请检查构建日志" -ForegroundColor Yellow
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "重新构建:" -ForegroundColor Yellow
|
||||||
|
Write-Host " .\scripts\build_and_push.ps1 -Tag $Tag" -ForegroundColor Gray
|
||||||
|
}
|
||||||
|
Write-Host ""
|
||||||
Reference in New Issue
Block a user