Docker Build and Release #4
Workflow file for this run
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
| name: Docker Build and Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Tag to build (e.g., v1.0.0)' | |
| required: true | |
| default: 'latest' | |
| env: | |
| REGISTRY: ghcr.io | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Prepare image owner | |
| id: image_owner | |
| run: echo "value=${GITHUB_REPOSITORY_OWNER,,}" >> "$GITHUB_OUTPUT" | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ steps.image_owner.outputs.value }}/yuquesync | |
| tags: | | |
| type=ref,event=tag | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }} | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| 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 | |
| create-release: | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| if: startsWith(github.ref, 'refs/tags/') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Prepare image owner | |
| id: image_owner | |
| run: echo "value=${GITHUB_REPOSITORY_OWNER,,}" >> "$GITHUB_OUTPUT" | |
| - name: Get tag name | |
| id: get_tag | |
| run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Create docker-compose file for release | |
| run: | | |
| cat > docker-compose-release.yml << EOF | |
| version: '3' | |
| services: | |
| yuque-sync: | |
| image: ${{ env.REGISTRY }}/${{ steps.image_owner.outputs.value }}/yuquesync:${{ steps.get_tag.outputs.tag }} | |
| container_name: yuque-sync | |
| restart: always | |
| volumes: | |
| - ./data:/data | |
| environment: | |
| # 必须设置的环境变量(请替换为你的实际值) | |
| - YUQUE_TOKEN=your_yuque_token_here | |
| - YUQUE_SESSION=your_yuque_session_here | |
| # 可选的环境变量(已有默认值) | |
| - YUQUE_BASE_URL=https://www.yuque.com | |
| - SAVE_PATH=/data | |
| - MONITOR_INTERVAL_MINUTES=10 | |
| - EXPORT_FORMAT=pdf | |
| EOF | |
| - name: Create usage instructions | |
| run: | | |
| cat > USAGE.md << 'EOF' | |
| # YuqueSync Docker 使用说明 | |
| ## 快速开始 | |
| ### 1. 获取语雀凭证 | |
| 1. 打开浏览器,登录语雀 | |
| 2. 按 F12 打开开发者工具 | |
| 3. 切换到 Network 标签 | |
| 4. 刷新页面,找到任意一个请求 | |
| 5. 在请求头中找到: | |
| - `yuque_ctoken`: 这是你的 YUQUE_TOKEN | |
| - `_yuque_session`: 这是你的 YUQUE_SESSION | |
| ### 2. 使用 Docker 运行 | |
| ```bash | |
| # 方式一:直接运行 | |
| docker run -d \ | |
| --name yuque-sync \ | |
| --restart always \ | |
| -e YUQUE_TOKEN="你的token" \ | |
| -e YUQUE_SESSION="你的session" \ | |
| -v ./data:/data \ | |
| ${{ env.REGISTRY }}/${{ steps.image_owner.outputs.value }}/yuquesync:latest | |
| # 方式二:使用 docker-compose(推荐) | |
| # 1. 下载 docker-compose-release.yml | |
| # 2. 编辑其中的环境变量 | |
| # 3. 运行: | |
| docker-compose -f docker-compose-release.yml up -d | |
| ``` | |
| ### 3. 环境变量配置 | |
| | 环境变量 | 必需 | 默认值 | 说明 | | |
| |---------|------|--------|------| | |
| | `YUQUE_TOKEN` | ✅ | - | 语雀 Token | | |
| | `YUQUE_SESSION` | ✅ | - | 语雀 Session | | |
| | `YUQUE_BASE_URL` | ❌ | `https://www.yuque.com` | 语雀网站地址 | | |
| | `SAVE_PATH` | ❌ | `/data` | 文档保存路径 | | |
| | `MONITOR_INTERVAL_MINUTES` | ❌ | `10` | 同步间隔(分钟) | | |
| | `EXPORT_FORMAT` | ❌ | `pdf` | 导出格式(pdf 或 markdown) | | |
| ### 4. 查看日志 | |
| ```bash | |
| docker logs -f yuque-sync | |
| ``` | |
| ### 5. 停止服务 | |
| ```bash | |
| docker stop yuque-sync | |
| docker rm yuque-sync | |
| ``` | |
| EOF | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.get_tag.outputs.tag }} | |
| name: Release ${{ steps.get_tag.outputs.tag }} | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true | |
| files: | | |
| docker-compose-release.yml | |
| USAGE.md | |
| body: | | |
| ## 🐳 Docker 镜像发布 | |
| ### 镜像信息 | |
| - **镜像地址**: `${{ env.REGISTRY }}/${{ steps.image_owner.outputs.value }}/yuquesync:${{ steps.get_tag.outputs.tag }}` | |
| - **支持架构**: linux/amd64, linux/arm64 | |
| - **导出格式**: PDF(默认)和 Markdown | |
| ### 快速启动 | |
| ```bash | |
| docker run -d \ | |
| --name yuque-sync \ | |
| --restart always \ | |
| -e YUQUE_TOKEN="你的token" \ | |
| -e YUQUE_SESSION="你的session" \ | |
| -v ./data:/data \ | |
| ${{ env.REGISTRY }}/${{ steps.image_owner.outputs.value }}/yuquesync:latest | |
| ``` | |
| ### 📁 下载文件 | |
| - `docker-compose-release.yml`: Docker Compose 配置文件 | |
| - `USAGE.md`: 详细使用说明 | |
| 更多使用说明请查看 [项目文档](https://github.com/${{ github.repository }}) | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |