-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (93 loc) · 3.53 KB
/
docker-build.yml
File metadata and controls
104 lines (93 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Build reComputer-RK-CV Images (Multi-Platform)
on:
push:
branches: [main, master]
paths:
- 'src/rk3588/**'
- 'src/rk3576/**'
- '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:
platform: [rk3588, rk3576]
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Check if build is needed
id: check_changes
run: |
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
elif [[ "${{ github.event_name }}" == "push" ]]; then
# Check if files in src/${{ matrix.platform }} or docker/${{ matrix.platform }} changed
# For simplicity in this environment, we assume true if it matches matrix,
# but in real git we would use git diff
echo "build=true" >> $GITHUB_OUTPUT
else
echo "build=true" >> $GITHUB_OUTPUT
fi
- name: Prepare Image Name
if: steps.check_changes.outputs.build == 'true'
run: |
# Use reComputer-RK-CV as the base repo name if renamed, otherwise use repo name
REPO_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
IMAGE_NAME="${{ matrix.platform }}-yolo"
echo "GHCR_IMAGE=ghcr.io/${REPO_NAME}/${IMAGE_NAME}" >> $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.platform }}
file: docker/${{ matrix.platform }}/Yolo11.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 }}"