-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/refactor-go 使用 Go 重新实现项目功能 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
cfc5467
feat: 添加 Go 版本重写的基础框架
YewFence a47d10d
feat(go): 添加日志文件输出、Gist上传和并行服务管理
YewFence d3f4f16
chore: 删除 kopia 维护相关命令
YewFence 33f3879
test: 添加单测
YewFence b267075
feat(go): 添加交叉编译 Makefile 和 CI/CD 工作流
YewFence c376a78
docs: 更新 README 添加 Go 版本说明
YewFence a83d73b
refactor: 优化配置加载和日志捕获,增强并发安全性
YewFence 45bdc34
chore: 删除 latest 版本发布 Action
YewFence 7ee4b01
refactor: 改进 LoadConfig 函数的错误处理逻辑,增强配置文件加载的健壮性
YewFence c58324e
fix: 修复异步执行通知发送时程序退出过快导致通知无法发送的问题
YewFence f869827
chore: 增加二进制文件名的gitignore
YewFence 3a59a83
chore: 增加代码块说明
YewFence 44b649e
test: 增加不合法配置默认值回退测试
YewFence c4a5e88
ci: 增加静态链接编译选项
YewFence 0aadfee
feat: 增加 Docker 命令超时时间配置,优化服务管理
YewFence b3e3937
feat: 增强远程路径校验,只需要确保引号包裹期望远程路径即可
YewFence 276722c
fix: 修复当 .env 不存在时,go test失败的问题
YewFence 727dd2e
fix: 增加 docker compose ps 命令失败时报错的功能
YewFence 9e12cf0
feat: 检测不到配置文件时显式输出日志
YewFence b1b6baf
feat: 补充 Windows 环境中 sh 执行权限检测逻辑
YewFence 37334a3
fix: 修复和文档不一致的错误配置
YewFence 1e649b0
refactor: 简化 yes 判断逻辑
YewFence a68f299
chore: 删除多余的引号
YewFence 032ab5f
docs: 更新环境变量表格,增加 Shell 和 Go 版本支持说明
YewFence 35d92a2
refactor: 引入 ServiceError 结构体以显式提取错误服务名
YewFence 6ef1527
ci: 去除了推送即构建的功能
YewFence 615db93
ci: 增加手动选择分支构建功能
YewFence 211a03b
ci: 增加 go 版本的应用选择单个平台构建的功能
YewFence 1f00b1f
feat: 将依赖检查提前至交互式确认之前
YewFence 79f6c2f
ci: 把输出目录改浅一点
YewFence 6aa05b5
test: 增加 docker main 模块的测试
YewFence bc2cf5c
test: 增加 orchestrator 测试
YewFence 054e85e
feat: 统一使用 UTC 时间
YewFence 5552b0b
feat: 增加 kopia 仓库状态检测,使用--json参数直接解析 json, 增加健壮性
YewFence File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: Go Build Artifact | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'go/**' | ||
| workflow_dispatch: | ||
| inputs: | ||
| ref: | ||
| description: '要构建的分支或标签' | ||
| required: true | ||
| default: 'main' | ||
| platform: | ||
| description: '选择构建平台' | ||
| required: true | ||
| default: 'all' | ||
| type: choice | ||
| options: | ||
| - all | ||
| - linux | ||
| - darwin | ||
| - windows | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ inputs.ref || github.ref }} | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.23' | ||
|
|
||
| - name: Run tests | ||
| working-directory: go | ||
| run: go test -v ./... | ||
|
|
||
| - name: Build selected platform | ||
| working-directory: go | ||
| run: make ${{ inputs.platform || 'all' }} | ||
|
|
||
| - name: Prepare artifact root | ||
| run: | | ||
| mkdir -p artifacts | ||
| cp go/dist/* artifacts/ | ||
|
|
||
| - name: Upload artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: yewresin-go-${{ github.sha }} | ||
| path: | | ||
| artifacts/* | ||
| retention-days: 7 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Go Production Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "v2*" | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| build-and-release: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '1.23' | ||
|
|
||
| - name: Run tests | ||
| working-directory: go | ||
| run: go test -v ./... | ||
|
|
||
| - name: Build all platforms | ||
| working-directory: go | ||
| run: VERSION=${{ github.ref_name }} make all | ||
|
|
||
| - name: Create Tagged Release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| files: | | ||
| go/dist/* | ||
| .env.example | ||
| generate_release_notes: true | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## 项目概述 | ||
|
|
||
| YewResin 是一个 Docker Compose 服务的自动化备份脚本,使用 Kopia + rclone 实现本地快照与云端同步。脚本会依次停止所有 Docker 服务,创建一致性快照,然后按优先级恢复服务。 | ||
|
|
||
| ## 构建命令 | ||
|
|
||
| ```bash | ||
| # 合并 src/ 模块生成 yewresin.sh(必须在修改代码后执行) | ||
| make build | ||
|
|
||
| # 清理生成的脚本 | ||
| make clean | ||
| ``` | ||
|
|
||
| ## 架构 | ||
|
|
||
| 脚本采用模块化设计,源代码在 `src/` 目录下,按数字前缀顺序拼接: | ||
|
|
||
| | 模块 | 职责 | | ||
| |------|------| | ||
| | `00-header.sh` | shebang、set -eo pipefail、记录开始时间 | | ||
| | `01-logging.sh` | 日志输出(tee 到文件和终端)、`log()` 函数 | | ||
| | `02-args.sh` | 命令行参数解析(`--dry-run`、`-y`、`--help`) | | ||
| | `03-config.sh` | 配置加载(从 `.env` 读取)、默认值、`print_config()` | | ||
| | `04-utils.sh` | 通用工具函数 | | ||
| | `05-notification.sh` | Apprise 通知发送 | | ||
| | `06-gist.sh` | GitHub Gist 日志上传和清理 | | ||
| | `07-dependencies.sh` | 依赖检查(rclone、kopia) | | ||
| | `08-services.sh` | Docker 服务管理:停止、启动、状态检查、cleanup | | ||
| | `09-main.sh` | 主流程:停止服务 → Kopia 快照 → 启动服务 | | ||
|
|
||
| **核心函数在 `08-services.sh`:** | ||
| - `stop_all_services()` / `start_all_services()` - 批量服务管理 | ||
| - `is_service_running()` - 检测服务运行状态 | ||
| - `cleanup()` - 异常退出时自动恢复服务(trap EXIT) | ||
|
|
||
| **服务启停优先级逻辑:** | ||
| - 优先服务(`PRIORITY_SERVICES`):最后停止,最先启动(如网关 caddy/nginx) | ||
| - 普通服务:先停止,后启动 | ||
| - 只恢复原本在运行的服务(通过 `RUNNING_SERVICES` 关联数组追踪) | ||
|
|
||
| ## 开发流程 | ||
|
|
||
| 1. 修改 `src/` 下的模块文件 | ||
| 2. 执行 `make build` 重新生成 `yewresin.sh` | ||
| 3. 提交 `src/`、`Makefile` 和 `yewresin.sh` | ||
|
|
||
| ## 运行与测试 | ||
|
|
||
| ```bash | ||
| # 本地模拟运行(不执行实际操作) | ||
| ./yewresin.sh --dry-run | ||
|
|
||
| # 执行备份(需确认) | ||
| ./yewresin.sh | ||
|
|
||
| # 跳过确认(用于 cron) | ||
| ./yewresin.sh -y | ||
| ``` | ||
|
|
||
| ## 配置 | ||
|
|
||
| 必须在 `.env` 中设置: | ||
| - `BASE_DIR` - Docker Compose 项目总目录 | ||
| - `EXPECTED_REMOTE` - Kopia 远程路径(如 `gdrive:backup`) | ||
|
|
||
| 可参考 `.env.example` 查看完整配置项。 | ||
|
|
||
| ## CI/CD | ||
|
|
||
| - `dev-release.yml` - main 分支推送后自动构建并发布到 `latest` tag | ||
| - `prod-release.yml` - 手动触发正式版本发布 | ||
YewFence marked this conversation as resolved.
Show resolved
Hide resolved
YewFence marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.