buildDockerImage_latest.ps1 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Cognio 创建多架构 latest 标签脚本(海外服务器版本)
  2. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  3. # ============================================================
  4. # 配置区
  5. # ============================================================
  6. # 远程服务器配置
  7. $remoteUser = "root"
  8. $remoteHost = "vps-apq2.zalhb.com"
  9. $remotePort = "22"
  10. # Docker 镜像配置
  11. $imageName = "amwpfiqvy/cognio"
  12. # tmux 会话名
  13. $tmuxSession = "dbx"
  14. # ============================================================
  15. # 主程序
  16. # ============================================================
  17. Write-Host ""
  18. Write-Host "========================================" -ForegroundColor Cyan
  19. Write-Host " Cognio 创建多架构 latest 标签" -ForegroundColor Cyan
  20. Write-Host "========================================" -ForegroundColor Cyan
  21. Write-Host ""
  22. Write-Host "将合并 amd64 和 arm64 镜像为 latest 标签" -ForegroundColor Yellow
  23. Write-Host ""
  24. # 支持命令行参数覆盖默认配置
  25. if ($args.Count -ge 1) { $remoteUser = $args[0] }
  26. if ($args.Count -ge 2) { $remoteHost = $args[1] }
  27. if ($args.Count -ge 3) { $remotePort = $args[2] }
  28. Write-Host "连接到: $remoteUser@$remoteHost`:$remotePort" -ForegroundColor Yellow
  29. Write-Host ""
  30. # ============================================================
  31. # 构建远程执行的 Shell 脚本
  32. # ============================================================
  33. # 生成远程脚本内容
  34. $scriptContent = @"
  35. #!/bin/bash
  36. echo "创建多架构 manifest 并推送 latest 标签..."
  37. echo "源镜像: ${imageName}:amd64, ${imageName}:arm64"
  38. echo ""
  39. # 删除旧的 manifest(如果存在)
  40. docker manifest rm ${imageName}:latest 2>/dev/null || true
  41. # 创建新的多架构 manifest
  42. docker manifest create ${imageName}:latest \
  43. ${imageName}:amd64 \
  44. ${imageName}:arm64
  45. # 推送 manifest
  46. docker manifest push ${imageName}:latest
  47. echo ""
  48. echo "完成!已推送 ${imageName}:latest"
  49. "@
  50. # 将脚本内容转为 base64,避免特殊字符问题
  51. $scriptBase64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($scriptContent))
  52. # tmux 命令:解码并执行脚本
  53. $remoteCmd = "tmux has-session -t $tmuxSession 2>/dev/null || tmux new-session -d -s $tmuxSession; " +
  54. "tmux send-keys -t $tmuxSession 'echo $scriptBase64 | base64 -d > /tmp/create_latest.sh && bash /tmp/create_latest.sh' Enter"
  55. # ============================================================
  56. # 执行远程命令
  57. # ============================================================
  58. Write-Host "正在发送命令到 tmux 会话: $tmuxSession" -ForegroundColor Yellow
  59. Write-Host ""
  60. & ssh -p $remotePort "$remoteUser@$remoteHost" $remoteCmd
  61. if ($LASTEXITCODE -eq 0) {
  62. Write-Host ""
  63. Write-Host "========================================" -ForegroundColor Green
  64. Write-Host " 命令已发送到 tmux 会话: $tmuxSession" -ForegroundColor Green
  65. Write-Host "========================================" -ForegroundColor Green
  66. Write-Host ""
  67. Write-Host "推送目标:" -ForegroundColor Yellow
  68. Write-Host " - ${imageName}:latest (多架构: amd64 + arm64)" -ForegroundColor Cyan
  69. Write-Host ""
  70. Write-Host "查看进度:" -ForegroundColor Yellow
  71. Write-Host " ssh -t -p $remotePort $remoteUser@$remoteHost `"tmux attach -t $tmuxSession`"" -ForegroundColor Cyan
  72. } else {
  73. Write-Host ""
  74. Write-Host "部署失败,请检查错误信息" -ForegroundColor Red
  75. }
  76. Write-Host ""
  77. pause