|
|
@@ -0,0 +1,100 @@
|
|
|
+# Cognio 创建多架构 latest 标签脚本(海外服务器版本)
|
|
|
+
|
|
|
+[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
+
|
|
|
+# ============================================================
|
|
|
+# 配置区
|
|
|
+# ============================================================
|
|
|
+
|
|
|
+# 远程服务器配置
|
|
|
+$remoteUser = "root"
|
|
|
+$remoteHost = "vps-apq3.zalhb.com"
|
|
|
+$remotePort = "22"
|
|
|
+
|
|
|
+# Docker 镜像配置
|
|
|
+$imageName = "amwpfiqvy/cognio"
|
|
|
+
|
|
|
+# tmux 会话名
|
|
|
+$tmuxSession = "dbx"
|
|
|
+
|
|
|
+# ============================================================
|
|
|
+# 主程序
|
|
|
+# ============================================================
|
|
|
+
|
|
|
+Write-Host ""
|
|
|
+Write-Host "========================================" -ForegroundColor Cyan
|
|
|
+Write-Host " Cognio 创建多架构 latest 标签" -ForegroundColor Cyan
|
|
|
+Write-Host "========================================" -ForegroundColor Cyan
|
|
|
+Write-Host ""
|
|
|
+
|
|
|
+Write-Host "将合并 amd64 和 arm64 镜像为 latest 标签" -ForegroundColor Yellow
|
|
|
+Write-Host ""
|
|
|
+
|
|
|
+# 支持命令行参数覆盖默认配置
|
|
|
+if ($args.Count -ge 1) { $remoteUser = $args[0] }
|
|
|
+if ($args.Count -ge 2) { $remoteHost = $args[1] }
|
|
|
+if ($args.Count -ge 3) { $remotePort = $args[2] }
|
|
|
+
|
|
|
+Write-Host "连接到: $remoteUser@$remoteHost`:$remotePort" -ForegroundColor Yellow
|
|
|
+Write-Host ""
|
|
|
+
|
|
|
+# ============================================================
|
|
|
+# 构建远程执行的 Shell 脚本
|
|
|
+# ============================================================
|
|
|
+
|
|
|
+# 生成远程脚本内容
|
|
|
+$scriptContent = @"
|
|
|
+#!/bin/bash
|
|
|
+echo "创建多架构 manifest 并推送 latest 标签..."
|
|
|
+echo "源镜像: ${imageName}:amd64, ${imageName}:arm64"
|
|
|
+echo ""
|
|
|
+
|
|
|
+# 删除旧的 manifest(如果存在)
|
|
|
+docker manifest rm ${imageName}:latest 2>/dev/null || true
|
|
|
+
|
|
|
+# 创建新的多架构 manifest
|
|
|
+docker manifest create ${imageName}:latest \
|
|
|
+ ${imageName}:amd64 \
|
|
|
+ ${imageName}:arm64
|
|
|
+
|
|
|
+# 推送 manifest
|
|
|
+docker manifest push ${imageName}:latest
|
|
|
+
|
|
|
+echo ""
|
|
|
+echo "完成!已推送 ${imageName}:latest"
|
|
|
+"@
|
|
|
+
|
|
|
+# 将脚本内容转为 base64,避免特殊字符问题
|
|
|
+$scriptBase64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($scriptContent))
|
|
|
+
|
|
|
+# tmux 命令:解码并执行脚本
|
|
|
+$remoteCmd = "tmux has-session -t $tmuxSession 2>/dev/null || tmux new-session -d -s $tmuxSession; " +
|
|
|
+ "tmux send-keys -t $tmuxSession 'echo $scriptBase64 | base64 -d > /tmp/create_latest.sh && bash /tmp/create_latest.sh' Enter"
|
|
|
+
|
|
|
+# ============================================================
|
|
|
+# 执行远程命令
|
|
|
+# ============================================================
|
|
|
+
|
|
|
+Write-Host "正在发送命令到 tmux 会话: $tmuxSession" -ForegroundColor Yellow
|
|
|
+Write-Host ""
|
|
|
+
|
|
|
+& ssh -p $remotePort "$remoteUser@$remoteHost" $remoteCmd
|
|
|
+
|
|
|
+if ($LASTEXITCODE -eq 0) {
|
|
|
+ Write-Host ""
|
|
|
+ Write-Host "========================================" -ForegroundColor Green
|
|
|
+ Write-Host " 命令已发送到 tmux 会话: $tmuxSession" -ForegroundColor Green
|
|
|
+ Write-Host "========================================" -ForegroundColor Green
|
|
|
+ Write-Host ""
|
|
|
+ Write-Host "推送目标:" -ForegroundColor Yellow
|
|
|
+ Write-Host " - ${imageName}:latest (多架构: amd64 + arm64)" -ForegroundColor Cyan
|
|
|
+ Write-Host ""
|
|
|
+ Write-Host "查看进度:" -ForegroundColor Yellow
|
|
|
+ Write-Host " ssh -t -p $remotePort $remoteUser@$remoteHost `"tmux attach -t $tmuxSession`"" -ForegroundColor Cyan
|
|
|
+} else {
|
|
|
+ Write-Host ""
|
|
|
+ Write-Host "部署失败,请检查错误信息" -ForegroundColor Red
|
|
|
+}
|
|
|
+
|
|
|
+Write-Host ""
|
|
|
+pause
|