Build reComputer-RK-CV Images (Multi-Platform) #36
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: Build reComputer-RK-CV Images (Multi-Platform) | |
| on: | |
| push: | |
| branches: [main, master, debug] | |
| paths: | |
| - 'src/rk3588_yolo11/**' | |
| - 'src/rk3576_yolo11/**' | |
| - 'src/rk3588_yolov8_obb/**' | |
| - 'src/rk3576_yolov8_obb/**' | |
| - 'docker/**' | |
| tags: ['v*.*.*'] | |
| pull_request: | |
| workflow_dispatch: | |
| inputs: | |
| platform: | |
| description: 'Platform to build (rk3588, rk3576, all)' | |
| required: true | |
| default: 'all' | |
| image_tag: | |
| description: 'Custom image tag' | |
| required: false | |
| default: 'latest' | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: rk3588 | |
| src_dir: rk3588_yolo11 | |
| dockerfile: Yolo11.dockerfile | |
| - platform: rk3576 | |
| src_dir: rk3576_yolo11 | |
| dockerfile: Yolo11.dockerfile | |
| - platform: rk3588 | |
| src_dir: rk3588_yolov8_obb | |
| dockerfile: Yolov8_obb.dockerfile | |
| - platform: rk3576 | |
| src_dir: rk3576_yolov8_obb | |
| dockerfile: Yolov8_obb.dockerfile | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Check if build is needed | |
| id: check_changes | |
| run: | | |
| # Check if build is required based on input or changes | |
| # Logic simplified for this example, focusing on manual trigger for now or assuming push means build | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| if [[ "${{ github.event.inputs.platform }}" == "all" || "${{ github.event.inputs.platform }}" == "${{ matrix.platform }}" ]]; then | |
| echo "build=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "build=false" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| # For push/PR events, we default to building everything in matrix for simplicity | |
| # Advanced: use paths-filter action to only build changed directories | |
| echo "build=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Prepare Image Name | |
| if: steps.check_changes.outputs.build == 'true' | |
| run: | | |
| # 默认基础名称 | |
| REPO_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') | |
| # 使用 src 目录名作为镜像名的一部分,将下划线替换为连字符 | |
| # 例如: rk3588_yolo11 -> rk3588-yolo11 | |
| IMAGE_NAME=$(echo "${{ matrix.src_dir }}" | sed 's/_/-/g') | |
| # 根据分支判断镜像路径 | |
| if [[ "${{ github.ref_name }}" == "debug" ]]; then | |
| # debug 分支特定命名: litxaohu/recomputer-rk-cv/debug/... | |
| GHCR_IMAGE="ghcr.io/litxaohu/recomputer-rk-cv/debug/${IMAGE_NAME}" | |
| else | |
| GHCR_IMAGE="ghcr.io/${REPO_NAME}/${IMAGE_NAME}" | |
| fi | |
| echo "GHCR_IMAGE=${GHCR_IMAGE}" >> $GITHUB_ENV | |
| TAG="latest" | |
| if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| TAG="${{ github.event.inputs.image_tag }}" | |
| elif [[ "${{ github.ref_type }}" == "tag" ]]; then | |
| TAG="${{ github.ref_name }}" | |
| fi | |
| echo "IMAGE_TAG=${TAG}" >> $GITHUB_ENV | |
| - name: Set up QEMU | |
| if: steps.check_changes.outputs.build == 'true' | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| if: steps.check_changes.outputs.build == 'true' | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GHCR | |
| if: steps.check_changes.outputs.build == 'true' && github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and Push (arm64 Only) | |
| if: steps.check_changes.outputs.build == 'true' | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: src/${{ matrix.src_dir }} | |
| file: docker/${{ matrix.platform }}/${{ matrix.dockerfile }} | |
| platforms: linux/arm64 | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: | | |
| ${{ env.GHCR_IMAGE }}:${{ env.IMAGE_TAG }} | |
| ${{ env.GHCR_IMAGE }}:${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Summary | |
| if: steps.check_changes.outputs.build == 'true' | |
| run: echo "Successfully built ${{ env.GHCR_IMAGE }}:${{ env.IMAGE_TAG }}" |