|
| 1 | +name: 构建并推送 |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + profile: |
| 10 | + description: "构建配置 (release/debug)" |
| 11 | + type: choice |
| 12 | + options: [ release, debug ] |
| 13 | + required: false |
| 14 | + default: release |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + packages: write |
| 19 | + |
| 20 | +env: |
| 21 | + REGISTRY: ghcr.io |
| 22 | + HTTP_PROXY: http://127.0.0.1:6152 |
| 23 | + HTTPS_PROXY: http://127.0.0.1:6152 |
| 24 | + |
| 25 | +jobs: |
| 26 | + build-and-push: |
| 27 | + name: 构建多平台镜像并推送到 GHCR |
| 28 | + runs-on: [ self-hosted, macOS, ARM64 ] |
| 29 | + |
| 30 | + steps: |
| 31 | + # - name: 登录到 GHCR |
| 32 | + # uses: docker/login-action@v3 |
| 33 | + # with: |
| 34 | + # registry: ${{ env.REGISTRY }} |
| 35 | + # username: ${{ github.repository_owner }} |
| 36 | + # password: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + # - name: 检查 base-debug 可用性 |
| 39 | + # run: | |
| 40 | + # docker pull ghcr.io/${{ github.repository_owner }}/convertor/base-debug:2.6.15 || echo "base-debug 镜像不可用,继续构建" |
| 41 | + # sleep 600 |
| 42 | + |
| 43 | + - name: 检出代码 |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: 确认 Xcode 命令行工具已安装 |
| 47 | + run: xcode-select -p || sudo xcode-select --install |
| 48 | + |
| 49 | + - name: 安装 Rust 工具链 |
| 50 | + uses: dtolnay/rust-toolchain@stable |
| 51 | + |
| 52 | + # 构建 builder 工具用于后续步骤 |
| 53 | + - name: 构建 builder 工具 |
| 54 | + run: cargo install --path crates/builder |
| 55 | + |
| 56 | + - name: 设置构建参数 |
| 57 | + id: vars |
| 58 | + run: | |
| 59 | + PROFILE="${{ github.event.inputs.profile }}" |
| 60 | + if [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref }}" = "refs/heads/dev" ]; then PROFILE="debug"; fi |
| 61 | + if [ -z "$PROFILE" ]; then PROFILE="release"; fi |
| 62 | + echo "profile=$PROFILE" >> "$GITHUB_OUTPUT" |
| 63 | +
|
| 64 | + - name: 安装 Zig 编译器 |
| 65 | + uses: mlugg/setup-zig@v2 |
| 66 | + |
| 67 | + - name: 安装 cargo-zigbuild |
| 68 | + run: command -v cargo-zigbuild || cargo install cargo-zigbuild --locked |
| 69 | + |
| 70 | + - name: 安装 pnpm |
| 71 | + uses: pnpm/action-setup@v4 |
| 72 | + with: |
| 73 | + version: latest |
| 74 | + |
| 75 | + - name: 安装 Node.js |
| 76 | + uses: actions/setup-node@v4 |
| 77 | + with: |
| 78 | + node-version: lts/* |
| 79 | + |
| 80 | + - name: 安装 Dashboard 依赖 |
| 81 | + run: pnpm install |
| 82 | + working-directory: dashboard |
| 83 | + |
| 84 | + - name: 登录到 GHCR |
| 85 | + uses: docker/login-action@v3 |
| 86 | + with: |
| 87 | + registry: ${{ env.REGISTRY }} |
| 88 | + username: ${{ github.repository_owner }} |
| 89 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 90 | + |
| 91 | + - name: Set up Docker Buildx |
| 92 | + uses: docker/setup-buildx-action@v3 |
| 93 | + with: |
| 94 | + driver-opts: network=host |
| 95 | + config-inline: | |
| 96 | + [registry."ghcr.io"] |
| 97 | + [registry."ghcr.io".auth] |
| 98 | + username = "${{ github.repository_owner }}" |
| 99 | + password = "${{ secrets.GITHUB_TOKEN }}" |
| 100 | +
|
| 101 | + - name: 检查基础镜像可访问性,不存在则构建并推送 |
| 102 | + run: | |
| 103 | + set -e |
| 104 | + BASE_IMAGE=$(builder tag base ${{ steps.vars.outputs.profile }} --registry ghcr --user ${{ github.repository_owner }}) |
| 105 | + echo "🔍 检查基础镜像: $BASE_IMAGE" |
| 106 | +
|
| 107 | + if docker buildx imagetools inspect "$BASE_IMAGE" > /dev/null 2>&1; then |
| 108 | + echo "✅ 基础镜像已存在,跳过构建" |
| 109 | + else |
| 110 | + echo "⚠️ 基础镜像不存在,开始构建并推送..." |
| 111 | + builder image base \ |
| 112 | + ${{ steps.vars.outputs.profile }} \ |
| 113 | + --arch amd,arm \ |
| 114 | + --user ${{ github.repository_owner }} \ |
| 115 | + --registry ghcr |
| 116 | + echo "✅ 基础镜像构建并推送完成" |
| 117 | + fi |
| 118 | +
|
| 119 | + - name: 使用 conv 构建并推送镜像(多架构) |
| 120 | + run: | |
| 121 | + # builder image convd 会自动: |
| 122 | + # 1. 构建二进制、Dashboard 和 Docker 镜像(多架构) |
| 123 | + # 2. 推送到指定的 registry |
| 124 | + # 3. 创建多架构 manifest(版本号 + latest 标签) |
| 125 | + builder image convd \ |
| 126 | + ${{ steps.vars.outputs.profile }} \ |
| 127 | + --arch amd,arm \ |
| 128 | + --dashboard \ |
| 129 | + --user ${{ github.repository_owner }} \ |
| 130 | + --registry ghcr |
0 commit comments