Răsfoiți Sursa

海外构建说明

黄中银 3 luni în urmă
părinte
comite
4540eb8193

+ 0 - 2
.gitignore

@@ -6,9 +6,7 @@
 *.sh
 *.bak
 *.log
-*.md
 !samba.sh
 !builder.sh
 !entrypoint.sh
-!README*.md
 unbound

+ 2 - 0
cognio/buildDockerImage_apq2.bat

@@ -0,0 +1,2 @@
+@echo off
+powershell -ExecutionPolicy Bypass -File "%~dp0buildDockerImage_apq2.ps1" %*

+ 132 - 0
cognio/buildDockerImage_apq2.ps1

@@ -0,0 +1,132 @@
+# Cognio 远程构建 Docker 镜像脚本(海外服务器版本,无国内加速)
+
+[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
+
+# ============================================================
+# 配置区
+# ============================================================
+
+# 远程服务器配置
+$remoteUser = "root"
+$remoteHost = "vps-apq2.zalhb.com"
+$remotePort = "22"
+
+# Git 仓库配置
+$repoUrl = "https://github.com/0xReLogic/Cognio.git"
+$repoDir = "Cognio"
+
+# Docker 镜像配置
+$imageName = "amwpfiqvy/cognio"
+
+# tmux 会话名
+$tmuxSession = "dbx"
+
+# ============================================================
+# 主程序
+# ============================================================
+
+Write-Host ""
+Write-Host "========================================" -ForegroundColor Cyan
+Write-Host "  Cognio 远程构建 Docker 镜像" -ForegroundColor Cyan
+Write-Host "========================================" -ForegroundColor Cyan
+Write-Host ""
+
+# Docker 镜像标签:提示用户输入(默认包含 latest,-l 排除 latest)
+$imageTagInput = Read-Host "请输入额外的 Docker 镜像标签 (多个用空格分隔,-l=排除latest,留空则仅推送 latest)"
+
+$inputTags = @()
+$excludeLatest = $false
+
+if ($imageTagInput -ne "") {
+    $inputTags = $imageTagInput -split '\s+' | Where-Object { $_ -ne "" }
+    if ($inputTags -contains "-l") {
+        $excludeLatest = $true
+        $inputTags = $inputTags | Where-Object { $_ -ne "-l" }
+    }
+}
+
+# 构建最终标签列表
+if ($excludeLatest) {
+    $imageTags = $inputTags
+} else {
+    $imageTags = @("latest") + $inputTags | Select-Object -Unique
+}
+
+# 构建 -t 参数列表
+$tagParams = ($imageTags | ForEach-Object { "-t ${imageName}:$_" }) -join " "
+
+Write-Host "镜像标签: $($imageTags -join ', ')" -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
+cd ~
+if [ -d "$repoDir" ]; then
+    echo "目录已存在,还原本地修改并拉取最新代码..."
+    cd $repoDir
+    git checkout .
+    git pull
+else
+    echo "目录不存在,正在克隆仓库..."
+    git clone $repoUrl
+    cd $repoDir
+fi
+echo "正在构建并推送 Docker 镜像..."
+docker buildx build \
+    --platform linux/amd64,linux/arm64 \
+    $tagParams \
+    --cache-from type=local,src=`$HOME/.buildx-cache \
+    --cache-to type=local,dest=`$HOME/.buildx-cache,mode=max \
+    --push \
+    .
+"@
+
+# 将脚本内容转为 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/build_cognio.sh && bash /tmp/build_cognio.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
+    foreach ($tag in $imageTags) {
+        Write-Host "  - ${imageName}:${tag}" -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

+ 0 - 0
cognio/国内构建详解.md → cognio/国内构建说明.md


+ 105 - 0
cognio/海外构建说明.md

@@ -0,0 +1,105 @@
+# Cognio Docker 镜像构建脚本 - 海外服务器版本
+
+本脚本用于在海外 Linux 服务器上构建并推送 Cognio 的多架构 Docker 镜像,无国内加速优化。
+
+## 文件说明
+
+| 文件 | 说明 |
+|------|------|
+| `buildDockerImage_apq2.bat` | Windows 批处理入口,调用 PowerShell 脚本 |
+| `buildDockerImage_apq2.ps1` | 主脚本,包含所有构建逻辑 |
+
+## 使用方法
+
+### 基本用法
+
+双击 `buildDockerImage_apq2.bat` 或在命令行执行:
+
+```cmd
+buildDockerImage_apq2.bat
+```
+
+### 命令行参数
+
+```cmd
+buildDockerImage_apq2.bat [用户名] [主机地址] [SSH端口]
+```
+
+### 镜像标签输入
+
+运行后会提示输入镜像标签:
+
+- **留空**: 仅推送 `latest` 标签
+- **输入标签**: 如 `v1.0 beta`,将推送 `latest`、`v1.0`、`beta`
+- **-l 参数**: 排除 `latest`,如 `-l v1.0` 仅推送 `v1.0`
+
+## 处理流程
+
+```
+┌─────────────────────────────────────────────────────────────┐
+│                      本地 Windows                           │
+├─────────────────────────────────────────────────────────────┤
+│  1. 读取配置(远程服务器、Git仓库、Docker镜像名)            │
+│  2. 提示用户输入镜像标签                                     │
+│  3. 生成远程执行的 Shell 脚本                                │
+│  4. 将脚本转为 Base64 编码                                   │
+│  5. 通过 SSH 发送到远程服务器的 tmux 会话                    │
+└─────────────────────────────────────────────────────────────┘
+                              │
+                              ▼ SSH
+┌─────────────────────────────────────────────────────────────┐
+│                    远程 Linux 服务器                         │
+├─────────────────────────────────────────────────────────────┤
+│  6. 在 tmux 会话中解码 Base64 并写入 /tmp/build_cognio.sh   │
+│  7. 执行构建脚本:                                           │
+│     a. 克隆/更新 Git 仓库                                    │
+│     b. 使用 docker buildx 构建多架构镜像                     │
+│     c. 推送到 Docker Hub                                     │
+└─────────────────────────────────────────────────────────────┘
+```
+
+## 配置项
+
+脚本顶部的配置区可修改:
+
+```powershell
+# 远程服务器配置
+$remoteUser = "root"
+$remoteHost = "192.168.1.99"
+$remotePort = "22"
+
+# Git 仓库配置
+$repoUrl = "http://ds:39418/AI/Cognio"
+$repoDir = "Cognio"
+
+# Docker 镜像配置
+$imageName = "amwpfiqvy/cognio"
+
+# tmux 会话名
+$tmuxSession = "dbx"
+```
+
+## 查看构建进度
+
+命令发送后,使用以下命令连接到远程 tmux 会话查看进度:
+
+```bash
+ssh -t -p 22 [email protected] "tmux attach -t dbx"
+```
+
+## 构建产物
+
+- **目标架构**: `linux/amd64`, `linux/arm64`
+- **推送目标**: Docker Hub (`amwpfiqvy/cognio`)
+- **缓存位置**: 远程服务器 `$HOME/.buildx-cache`
+
+## 与国内版本的区别
+
+此版本适用于海外服务器,不包含以下国内加速优化:
+
+- Docker 镜像加速源
+- APT 源加速(阿里云)
+- PyPI 源加速(阿里云)
+- Poetry 源加速
+
+如需在国内服务器构建,请使用 `buildDockerImage_u24_docker.bat`。