Manual Docker Build #13
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: Manual Docker Build | |
| # 核心配置:仅允许手动触发 | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| reason: | |
| description: '构建原因' | |
| required: false | |
| default: 'Manual build update' | |
| env: | |
| IMAGE_NAME: foxhui/webai-2api | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| # 1. 拉取代码 | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # 2. 设置 QEMU (支持多架构构建,如 ARM64) | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| # 3. 设置 Docker Buildx | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # 4. 登录 Docker Hub | |
| - name: Log into Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| # 5. 生成 Docker 标签 | |
| # 逻辑: | |
| # - 总是打上 'latest' 标签 | |
| # - 额外打上 'sha-xxxxxxx' (基于当前 commit 的哈希) | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=raw,value=latest | |
| type=sha,format=short | |
| # 6. 构建并推送 | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| # 开启推送 | |
| push: true | |
| # 使用上面生成的标签 | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| # 缓存加速 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| # 同时构建 PC (amd64) 和 Mac/树莓派 (arm64) 版本 | |
| platforms: linux/amd64,linux/arm64 |