Repository navigation
216 lines (195 loc) · 7.34 KB
/
Copy pathdocker-build.yml
File metadata and controls
216 lines (195 loc) · 7.34 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
name: Build reComputer-RK-CV Images (Multi-Platform)
on:
push:
branches: [main, master]
paths:
- 'src/rk3588_yolov10/**'
- 'src/rk3576_yolov10/**'
- 'src/rk3588_yolox/**'
- 'src/rk3576_yolox/**'
- 'src/rk3588_ppyoloe/**'
- 'src/rk3576_ppyoloe/**'
- 'src/rk3588_yolo_world/**'
- 'src/rk3576_yolo_world/**'
- 'src/rk3588_deeplabv3/**'
- 'src/rk3576_deeplabv3/**'
- 'src/rk3588_ppseg/**'
- 'src/rk3576_ppseg/**'
- 'src/rk3588_mobilesam/**'
- 'src/rk3576_mobilesam/**'
- 'src/rk3588_retinaface/**'
- 'src/rk3576_retinaface/**'
- 'src/rk3588_ppocr/**'
- 'src/rk3576_ppocr/**'
- 'src/rk3588_yolo11/**'
- 'src/rk3576_yolo11/**'
- 'src/rk3588_yolov8_obb/**'
- 'src/rk3576_yolov8_obb/**'
- 'src/rk3588_yolov5/**'
- 'src/rk3576_yolov5/**'
- 'src/rk3588_yolov6/**'
- 'src/rk3576_yolov6/**'
- 'src/rk3588_yolov7/**'
- 'src/rk3576_yolov7/**'
- 'src/rk3588_yolov5_seg/**'
- 'src/rk3576_yolov5_seg/**'
- 'src/rk3588_yolov8/**'
- 'src/rk3576_yolov8/**'
- 'src/rk3588_yolov8_pose/**'
- 'src/rk3576_yolov8_pose/**'
- 'src/rk3588_yolov8_seg/**'
- 'src/rk3576_yolov8_seg/**'
- 'src/rk3576_yolov8_airborne/**'
- 'src/rk3588_whisper/**'
- 'src/rk3576_whisper/**'
- 'src/rk3588_mobilenet/**'
- 'src/rk3588_resnet50v2/**'
- 'src/rk3576_mobilenet/**'
- 'src/rk3576_resnet50v2/**'
- 'docker/**'
tags: ['v*.*.*']
pull_request:
workflow_dispatch:
inputs:
platform:
description: 'Platform to build (e.g. rk3588_yolo11, rk3588_yolov5, 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
# Avoid starting every BuildKit container at once and overwhelming Docker Hub.
max-parallel: 3
matrix:
platform:
- rk3588_ppseg
- rk3576_ppseg
- rk3588_mobilesam
- rk3576_mobilesam
- rk3588_retinaface
- rk3576_retinaface
- rk3588_ppocr
- rk3576_ppocr
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
lfs: true
- 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:]')
# We only want to replace the FIRST underscore with a hyphen.
# For example, rk3588_yolov5_seg -> rk3588-yolov5_seg
IMAGE_NAME=$(echo "${{ matrix.platform }}" | sed 's/_/-/')
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: Pull Docker builder dependencies with retry
if: steps.check_changes.outputs.build == 'true'
shell: bash
run: |
pull_with_retry() {
local image="$1"
local max_attempts=5
local attempt
for attempt in $(seq 1 "$max_attempts"); do
if docker pull "$image"; then
return 0
fi
if [[ "$attempt" -eq "$max_attempts" ]]; then
echo "::error::Failed to pull ${image} after ${max_attempts} attempts"
return 1
fi
local delay=$((attempt * 15))
echo "::warning::Pull ${image} failed (attempt ${attempt}/${max_attempts}); retrying in ${delay}s"
sleep "$delay"
done
}
pull_with_retry "tonistiigi/binfmt:latest"
pull_with_retry "moby/buildkit:buildx-stable-1"
- name: Set up QEMU
if: steps.check_changes.outputs.build == 'true'
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
if: steps.check_changes.outputs.build == 'true'
uses: docker/setup-buildx-action@v4
with:
driver-opts: |
image=moby/buildkit:buildx-stable-1
network=host
buildkitd-config-inline: |
[registry."docker.io"]
mirrors = ["mirror.gcr.io"]
- name: Login to GHCR
if: steps.check_changes.outputs.build == 'true' && github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare Dockerfile Path
if: steps.check_changes.outputs.build == 'true'
run: |
# Convert platform like rk3588_yolov5_seg to rk3588/yolov5_seg.dockerfile
# We extract the prefix (rk3588 or rk3576) and the model part.
PLATFORM="${{ matrix.platform }}"
HW_PREFIX="${PLATFORM%%_*}"
MODEL_SUFFIX="${PLATFORM#*_}"
# Special cases for older names or capitalizations if needed
if [[ "$MODEL_SUFFIX" == "yolo11" ]]; then
DOCKERFILE_NAME="Yolo11.dockerfile"
elif [[ "$MODEL_SUFFIX" == "yolov8_obb" ]]; then
DOCKERFILE_NAME="Yolov8-obb.dockerfile"
else
DOCKERFILE_NAME="${MODEL_SUFFIX}.dockerfile"
fi
echo "DOCKERFILE_PATH=docker/${HW_PREFIX}/${DOCKERFILE_NAME}" >> $GITHUB_ENV
- name: Build and Push (arm64 Only)
if: steps.check_changes.outputs.build == 'true'
uses: docker/build-push-action@v7
with:
context: src/${{ matrix.platform }}
file: ${{ env.DOCKERFILE_PATH }}
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 }}"