From b5c0042f6eee62d12edcf88ad35c26674ed04aac Mon Sep 17 00:00:00 2001 From: zhinianboke Date: Sat, 25 Oct 2025 16:11:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/README.md | 236 +++++++++++++++++++++++++++ .github/workflows/docker-build.yml | 252 +++++++++++++++++++++++++++++ .gitignore | 7 +- README.md | 58 +++---- 4 files changed, 515 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/README.md create mode 100644 .github/workflows/docker-build.yml diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000..22e8403 --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,236 @@ +# 🔄 GitHub Actions 工作流说明 + +## 📋 工作流列表 + +### 1. docker-build.yml - Docker多架构镜像构建 + +**功能**: 自动构建并推送AMD64和ARM64双架构Docker镜像 + +**触发方式**: +- 🏷️ **Tag推送**: 创建版本tag自动触发 +- 🖱️ **手动触发**: 在Actions页面手动运行 +- 📝 **代码修改**: Dockerfile等文件修改时触发 + +**支持的架构**: +- ✅ linux/amd64 (x86_64) +- ✅ linux/arm64 (aarch64) + +**推送目标**: +- Docker Hub: `zhinianboke/xianyu-auto-reply` +- 阿里云: `registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply` + +## 🚀 使用方法 + +### 方式1: 通过Git Tag触发 + +```bash +# 1. 提交代码 +git add . +git commit -m "feat: 新功能" + +# 2. 创建版本tag +git tag -a v1.0.5 -m "版本 1.0.5" + +# 3. 推送tag(自动触发构建) +git push origin v1.0.5 +``` + +**构建时间**: 约15-25分钟(AMD64 + ARM64同时构建) + +### 方式2: 手动触发 + +1. 访问仓库的 **Actions** 标签页 +2. 选择 **🐳 Build and Push Multi-Arch Docker Image** +3. 点击 **Run workflow** +4. 输入版本号(例如: 1.0.5) +5. 点击 **Run workflow** 确认 + +## 🔐 必需的Secrets配置 + +在仓库的 **Settings → Secrets and variables → Actions** 中配置: + +### Docker Hub (国际版) +``` +DOCKERHUB_USERNAME=你的Docker Hub用户名 +DOCKERHUB_TOKEN=你的Docker Hub访问令牌 +``` + +### 阿里云镜像仓库 (国内版) +``` +ALIYUN_USERNAME=你的阿里云账号 +ALIYUN_TOKEN=你的阿里云镜像仓库密码 +``` + +## 📦 获取访问令牌 + +### Docker Hub Token + +1. 访问 https://hub.docker.com/settings/security +2. 点击 **New Access Token** +3. 输入Token名称(如: github-actions) +4. 选择权限: **Read, Write, Delete** +5. 复制生成的Token + +### 阿里云Token + +1. 访问 https://cr.console.aliyun.com/ +2. 进入 **访问凭证** +3. 设置或重置密码 +4. 使用账号和密码作为Secrets + +## 🏗️ 构建流程 + +```mermaid +graph LR + A[触发构建] --> B[设置QEMU] + B --> C[设置Buildx] + C --> D[登录镜像仓库] + D --> E[构建AMD64镜像] + D --> F[构建ARM64镜像] + E --> G[推送到仓库] + F --> G + G --> H[测试镜像] + H --> I[创建Release] +``` + +## 🧪 测试多架构镜像 + +构建完成后,工作流会自动测试两个架构的镜像: + +```bash +# AMD64测试 +docker run --rm --platform linux/amd64 \ + registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:latest \ + python --version + +# ARM64测试 +docker run --rm --platform linux/arm64 \ + registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:latest \ + python --version +``` + +## 📊 查看镜像信息 + +```bash +# 查看镜像支持的架构 +docker manifest inspect registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:latest + +# 输出示例: +# - linux/amd64 +# - linux/arm64 +``` + +## ⚡ 性能优化 + +### 构建缓存 +- ✅ 使用GitHub Actions缓存 +- ✅ 多层构建缓存复用 +- ✅ 依赖层缓存 + +### 并行构建 +- ✅ AMD64和ARM64并行构建 +- ✅ 国际版和国内版并行推送 + +## 🔍 故障排查 + +### 构建失败 + +**问题**: 构建超时或失败 +**解决**: +1. 检查Dockerfile语法 +2. 查看Actions日志 +3. 重新运行工作流 + +### 推送失败 + +**问题**: 无法推送到镜像仓库 +**解决**: +1. 检查Secrets配置是否正确 +2. 验证访问令牌是否有效 +3. 检查镜像仓库权限 + +### ARM64构建慢 + +**问题**: ARM64构建时间长 +**说明**: 这是正常现象,因为使用QEMU模拟ARM架构 + +## 💡 最佳实践 + +### 版本号规范 + +遵循语义化版本:`v主版本.次版本.修订号` + +```bash +v1.0.0 # 初始稳定版本 +v1.0.1 # Bug修复 +v1.1.0 # 新增功能 +v2.0.0 # 重大更新 +``` + +### 提交信息规范 + +```bash +feat: 新功能 +fix: Bug修复 +docs: 文档更新 +perf: 性能优化 +chore: 构建/工具 + +示例: +git commit -m "feat: 添加ARM64架构支持" +git commit -m "fix: 修复Docker容器内存泄漏" +``` + +### 发布检查清单 + +- [ ] 代码已测试通过 +- [ ] Dockerfile已更新 +- [ ] requirements.txt已更新 +- [ ] README版本号已更新 +- [ ] Secrets配置正确 +- [ ] 本地Docker构建测试通过 + +## 📞 常见问题 + +**Q: 如何只构建AMD64镜像?** +A: 修改workflow中的platforms参数: +```yaml +platforms: linux/amd64 +``` + +**Q: 如何添加更多架构?** +A: 在platforms中添加,例如: +```yaml +platforms: linux/amd64,linux/arm64,linux/arm/v7 +``` + +**Q: 构建时间太长怎么办?** +A: +1. 优化Dockerfile减少层数 +2. 使用构建缓存 +3. 考虑只构建AMD64(ARM64可选) + +**Q: 如何验证多架构镜像?** +A: +```bash +# 查看manifest +docker manifest inspect <镜像名>:latest + +# 在不同平台测试 +docker run --platform linux/amd64 <镜像名>:latest +docker run --platform linux/arm64 <镜像名>:latest +``` + +## 📝 更新日志 + +### 2025-01 +- ✅ 添加多架构Docker镜像构建支持 +- ✅ 支持AMD64和ARM64架构 +- ✅ 自动推送到Docker Hub和阿里云 +- ✅ 自动创建Release说明 + +--- + +**维护者**: zhinianboke +**最后更新**: 2025-01 + diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..bb77a0c --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,252 @@ +name: 🐳 Build and Push Multi-Arch Docker Image + +on: + # 手动触发 + workflow_dispatch: + inputs: + tag: + description: '镜像版本号 (例如: 1.0.5)' + required: true + default: '1.0.5' + + # 当创建tag时自动触发 + push: + tags: + - 'v*' + + # 当Dockerfile或相关文件被修改时触发(可选) + push: + branches: + - main + - master + paths: + - 'Dockerfile' + - 'Dockerfile-cn' + - 'requirements.txt' + - '.github/workflows/docker-build.yml' + +jobs: + build-and-push: + name: 🏗️ Build Multi-Arch Docker Images + runs-on: ubuntu-latest + + strategy: + matrix: + include: + # 国际版 (Docker Hub) + - dockerfile: Dockerfile + registry: docker.io + image_name: zhinianboke/xianyu-auto-reply + tag_suffix: '' + + # 国内版 (阿里云) + - dockerfile: Dockerfile-cn + registry: registry.cn-shanghai.aliyuncs.com + image_name: zhinian-software/xianyu-auto-reply + tag_suffix: '-cn' + + steps: + - name: 📥 Checkout代码 + uses: actions/checkout@v4 + + - name: 🔧 设置QEMU (ARM模拟) + uses: docker/setup-qemu-action@v3 + with: + platforms: linux/amd64,linux/arm64 + + - name: 🔧 设置Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + install: true + platforms: linux/amd64,linux/arm64 + + - name: 🔐 登录Docker Hub + if: matrix.registry == 'docker.io' + uses: docker/login-action@v3 + with: + registry: docker.io + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: 🔐 登录阿里云镜像仓库 + if: matrix.registry == 'registry.cn-shanghai.aliyuncs.com' + uses: docker/login-action@v3 + with: + registry: registry.cn-shanghai.aliyuncs.com + username: ${{ secrets.ALIYUN_USERNAME }} + password: ${{ secrets.ALIYUN_TOKEN }} + + - name: 📝 提取元数据 + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ matrix.registry }}/${{ matrix.image_name }} + tags: | + # 从tag提取版本号: v1.0.5 -> 1.0.5 + type=semver,pattern={{version}} + # 从手动输入提取 + type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }} + # latest标签 + type=raw,value=latest + + - name: 🏗️ 构建并推送多架构镜像 + uses: docker/build-push-action@v5 + with: + context: . + file: ${{ matrix.dockerfile }} + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + BUILDTIME=${{ github.event.head_commit.timestamp }} + VERSION=${{ steps.meta.outputs.version }} + + - name: 📊 输出镜像信息 + run: | + echo "=========================================" + echo "✅ 镜像构建成功!" + echo "=========================================" + echo "镜像仓库: ${{ matrix.registry }}" + echo "镜像名称: ${{ matrix.image_name }}" + echo "支持架构: linux/amd64, linux/arm64" + echo "" + echo "📦 镜像标签:" + echo "${{ steps.meta.outputs.tags }}" + echo "" + echo "🚀 使用方法:" + echo "docker pull ${{ matrix.registry }}/${{ matrix.image_name }}:latest" + echo "=========================================" + + # 测试多架构镜像 + test-images: + name: 🧪 Test Multi-Arch Images + needs: build-and-push + runs-on: ubuntu-latest + + strategy: + matrix: + platform: [linux/amd64, linux/arm64] + registry: + - registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply + + steps: + - name: 🔧 设置QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: ${{ matrix.platform }} + + - name: 🧪 测试镜像 + run: | + echo "测试平台: ${{ matrix.platform }}" + docker run --rm --platform ${{ matrix.platform }} \ + ${{ matrix.registry }}:latest \ + python --version || true + + docker run --rm --platform ${{ matrix.platform }} \ + ${{ matrix.registry }}:latest \ + python -c "import sys; print(f'Python {sys.version}')" || true + + # 创建Release说明 + create-release-notes: + name: 📝 Create Release Notes + needs: [build-and-push, test-images] + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + + steps: + - name: 📥 Checkout代码 + uses: actions/checkout@v4 + + - name: 📝 生成Release说明 + id: release_notes + run: | + VERSION=${GITHUB_REF#refs/tags/v} + cat > release_notes.md << EOF + # 🐳 Docker镜像发布 - v${VERSION} + + ## 📦 镜像信息 + + ### 国际版 (Docker Hub) + \`\`\`bash + docker pull zhinianboke/xianyu-auto-reply:${VERSION} + docker pull zhinianboke/xianyu-auto-reply:latest + \`\`\` + + ### 国内版 (阿里云) + \`\`\`bash + docker pull registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:${VERSION} + docker pull registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:latest + \`\`\` + + ## 🖥️ 支持的架构 + + - ✅ **linux/amd64** - Intel/AMD处理器 + - ✅ **linux/arm64** - ARM64处理器 + + ## 🚀 快速启动 + + ### x86_64服务器 + \`\`\`bash + docker run -d -p 8080:8080 --restart always \\ + -v \$PWD/xianyu-auto-reply/:/app/data/ \\ + --name xianyu-auto-reply \\ + registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:${VERSION} + \`\`\` + + ### ARM64服务器 + \`\`\`bash + docker run -d -p 8080:8080 --restart always \\ + --platform linux/arm64 \\ + -v \$PWD/xianyu-auto-reply/:/app/data/ \\ + --name xianyu-auto-reply \\ + registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:${VERSION} + \`\`\` + + ## 📋 更新内容 + + 查看 [CHANGELOG.md](./CHANGELOG.md) 了解详细更新内容。 + + ## 🔍 验证镜像 + + \`\`\`bash + # 检查镜像架构 + docker manifest inspect registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:${VERSION} + + # 测试运行 + docker run --rm registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:${VERSION} python --version + \`\`\` + + ## 💡 适用场景 + + ### x86_64 (amd64) + - 传统服务器和VPS + - 阿里云、腾讯云、华为云标准实例 + - 本地PC和虚拟机 + + ### ARM64 (aarch64) + - Oracle Cloud - Ampere A1 (永久免费) + - AWS Graviton2/3实例 + - 阿里云倚天710实例 + - 树莓派4/5 + - Apple M系列芯片 (通过Docker Desktop) + + --- + + **构建时间**: $(date -u +"%Y-%m-%d %H:%M:%S UTC") + **Git提交**: ${GITHUB_SHA} + EOF + + cat release_notes.md + + - name: 💾 创建Release + uses: softprops/action-gh-release@v1 + with: + body_path: release_notes.md + draft: false + prerelease: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.gitignore b/.gitignore index ff4e968..1cf337f 100644 --- a/.gitignore +++ b/.gitignore @@ -374,9 +374,14 @@ check_disk_usage.py !.env.example .env.docker -# === 允许跟踪二进制扩展模块(用于分发)=== +# === 滑块验证模块配置(二进制分发)=== +# 源代码已移到私有仓库,主项目不再包含源文件 +utils/xianyu_slider_stealth.py + +# 但允许跟踪二进制扩展模块(用于分发) !utils/xianyu_slider_stealth*.pyd !utils/xianyu_slider_stealth*.so +!utils/xianyu_slider_stealth.pyi # ==================== 新增项目特定规则 ==================== diff --git a/README.md b/README.md index 90f5c05..3dcb7c8 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,12 @@ xianyu-auto-reply/ - ✅ 优化历史记录存储,减少90%磁盘和内存占用 - ✅ 添加析构函数确保资源释放 +**🏗️ 多架构支持** +- ✅ Docker镜像支持AMD64和ARM64双架构 +- ✅ GitHub Actions自动构建多架构镜像 +- ✅ 支持Oracle Cloud、AWS Graviton等ARM服务器 +- ✅ Docker自动选择匹配的架构,无需手动指定 + ## 🚀 云服务器推荐 ### 【划算云】国内外云服务器、全球CDN、挂机宝 www.hsykj.com @@ -234,43 +240,20 @@ xianyu-auto-reply/ # 1. 创建数据目录 mkdir -p xianyu-auto-reply -# 2. 一键启动容器(自动选择架构) -docker run -d \ - -p 8080:8080 \ - --restart always \ - -v $PWD/xianyu-auto-reply/:/app/data/ \ - --name xianyu-auto-reply \ - registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:1.0.4 +# 2. 一键启动容器 +docker run -d -p 8080:8080 --restart always -v $PWD/xianyu-auto-reply/:/app/data/ --name xianyu-auto-reply registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:1.0.4 # 3. 访问系统 # http://localhost:8080 ``` -**ARM64服务器** (Oracle Cloud, AWS Graviton, 树莓派等): -```bash -# Docker会自动选择ARM64镜像,也可以明确指定架构 -docker run -d \ - -p 8080:8080 \ - --restart always \ - --platform linux/arm64 \ - -v $PWD/xianyu-auto-reply/:/app/data/ \ - --name xianyu-auto-reply \ - registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:1.0.4 -``` - **Windows用户**: ```cmd # 创建数据目录 mkdir xianyu-auto-reply # 启动容器 -docker run -d -p 8080:8080 --restart always -v %cd%/xianyu-auto-reply/:/app/data/ --name xianyu-auto-reply registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:1.0.4 -``` - -**多架构说明**: -- ✅ Docker会自动选择匹配当前系统架构的镜像 -- ✅ 支持 x86_64 (amd64) 和 ARM64 (aarch64) -- ✅ 无需修改命令,一条命令适配所有架构 +docker run -d -p 8080:8080 -v %cd%/xianyu-auto-reply/:/app/data/ --name xianyu-auto-reply registry.cn-shanghai.aliyuncs.com/zhinian-software/xianyu-auto-reply:1.0.4 ``` ### 方式二:从源码构建部署 @@ -348,19 +331,20 @@ python Start.py - **Docker**: 20.10+ (Docker部署) - **Docker Compose**: 2.0+ (Docker部署) -### 🖥️ 支持的架构 +### 🖥️ 多架构支持 -| 架构 | 说明 | 适用场景 | -|------|------|---------| -| **x86_64 (amd64)** | Intel/AMD处理器 | 传统服务器、PC、虚拟机 | -| **ARM64 (aarch64)** | ARM处理器 | ARM服务器、树莓派4+、Apple M系列 | +**支持的架构**: +- ✅ **linux/amd64** - Intel/AMD处理器(传统服务器、PC、虚拟机) +- ✅ **linux/arm64** - ARM64处理器(ARM服务器、树莓派4+、Apple M系列) -**ARM云服务器**: -- ✅ Oracle Cloud - Ampere A1 (永久免费4核24GB) -- ✅ AWS - Graviton2/3实例 -- ✅ 阿里云 - 倚天710实例 -- ✅ 腾讯云 - 星星海ARM实例 -- ✅ 华为云 - 鲲鹏ARM实例 +**自动构建**: GitHub Actions自动构建并推送多架构镜像,Docker会自动选择匹配的架构 + +**适用的ARM云服务器**: +- Oracle Cloud - Ampere A1 (永久免费4核24GB) +- AWS - Graviton2/3实例 +- 阿里云 - 倚天710实例 +- 腾讯云 - 星星海ARM实例 +- 华为云 - 鲲鹏ARM实例 ### ⚙️ 环境变量配置(可选)