Skip to content

Commit 4737104

Browse files
feat: 添加自定义构建模板
1 parent dea58ae commit 4737104

File tree

6 files changed

+518
-3
lines changed

6 files changed

+518
-3
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: Build manywheel docker images (custom)
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.sha }}
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: 'Build with specific tag'
11+
required: false
12+
default: ''
13+
14+
jobs:
15+
check_version:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
version: ${{ steps.check_version.outputs.version }}
19+
steps:
20+
- name: Check version
21+
id: check_version
22+
run: |
23+
if [ -z "${{ github.event.inputs.tag }}" ]; then
24+
echo "No tag provided, using latest release"
25+
version=$(curl -s "https://api.github.com/repos/opencv/opencv-python/releases/latest" | jq -r .tag_name)
26+
else
27+
version=${{ github.event.inputs.tag }}
28+
fi
29+
30+
if [ -z "${version}" ] || [ "${version}" == "null" ]; then
31+
echo "Failed to get version"
32+
exit 1
33+
fi
34+
35+
echo "version=${version}" >> $GITHUB_ENV
36+
echo "version=${version}" >> $GITHUB_OUTPUT
37+
echo ""
38+
echo "========== Build Args =========="
39+
echo "opencv-python version: ${version}"
40+
41+
build_loongarch64_manylinux:
42+
name: Build image for loongarch64
43+
runs-on: ubuntu-latest
44+
needs: check_version
45+
env:
46+
version: ${{ needs.check_version.outputs.version }}
47+
steps:
48+
- uses: actions/checkout@v4
49+
- uses: docker/setup-qemu-action@v3
50+
- uses: docker/setup-buildx-action@v3
51+
52+
- name: Generate files
53+
run: |
54+
mkdir -p docker/manylinux_2_38
55+
wget -qO docker/manylinux_2_38/Dockerfile_loongarch64 https://github.com/opencv/opencv-python/raw/refs/tags/${version}/docker/manylinux2014/Dockerfile_x86_64
56+
patch -p1 < loong64.patch
57+
cd docker/manylinux_2_38
58+
sed -i "s@FROM quay.io/pypa/manylinux2014_x86_64@FROM ghcr.io/loong64/manylinux_2_38_loongarch64@g" Dockerfile_loongarch64
59+
image_tag=$(cat Dockerfile_loongarch64 | grep "Version:" | sed 's/# Version: //')
60+
echo "image_tag=${image_tag}" >> $GITHUB_ENV
61+
62+
- name: Login to GitHub Container Registry
63+
uses: docker/login-action@v3
64+
with:
65+
registry: ghcr.io
66+
username: ${{ github.repository_owner }}
67+
password: ${{ secrets.GITHUB_TOKEN }}
68+
69+
- name: Build and push image
70+
uses: docker/build-push-action@v6
71+
with:
72+
context: .
73+
file: docker/manylinux_2_38/Dockerfile_loongarch64
74+
platforms: linux/loong64
75+
push: true
76+
tags: |
77+
ghcr.io/${{ github.repository_owner }}/opencv-python-manylinux_2_38-loongarch64:${{ env.image_tag }}
78+
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/opencv-python-manylinux_2_38-loongarch64:buildcache
79+
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/opencv-python-manylinux_2_38-loongarch64:buildcache,mode=max
80+
81+
build_ppc64le_manylinux:
82+
name: Build image for ppc64le
83+
runs-on: ubuntu-latest
84+
needs: check_version
85+
env:
86+
version: ${{ needs.check_version.outputs.version }}
87+
steps:
88+
- uses: actions/checkout@v4
89+
- uses: docker/setup-qemu-action@v3
90+
- uses: docker/setup-buildx-action@v3
91+
92+
- name: Generate files
93+
run: |
94+
mkdir -p docker/manylinux2014
95+
wget -qO docker/manylinux2014/Dockerfile_ppc64le https://github.com/opencv/opencv-python/raw/refs/tags/${version}/docker/manylinux2014/Dockerfile_x86_64
96+
patch -p1 < ppc64le.patch
97+
cd docker/manylinux2014
98+
sed -i "s@FROM quay.io/pypa/manylinux2014_x86_64@FROM quay.io/pypa/manylinux2014_ppc64le@g" Dockerfile_ppc64le
99+
image_tag=$(cat Dockerfile_ppc64le | grep "Version:" | sed 's/# Version: //')
100+
echo "image_tag=${image_tag}" >> $GITHUB_ENV
101+
102+
- name: Login to GitHub Container Registry
103+
uses: docker/login-action@v3
104+
with:
105+
registry: ghcr.io
106+
username: ${{ github.repository_owner }}
107+
password: ${{ secrets.GITHUB_TOKEN }}
108+
109+
- name: Build and push image
110+
uses: docker/build-push-action@v6
111+
with:
112+
context: .
113+
file: docker/manylinux2014/Dockerfile_ppc64le
114+
platforms: linux/ppc64le
115+
push: true
116+
tags: |
117+
ghcr.io/${{ github.repository_owner }}/opencv-python-manylinux2014-ppc64le:${{ env.image_tag }}
118+
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/opencv-python-manylinux2014-ppc64le:buildcache
119+
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/opencv-python-manylinux2014-ppc64le:buildcache,mode=max
120+
121+
build_s390x_manylinux:
122+
name: Build image for s390x
123+
runs-on: ubuntu-latest
124+
needs: check_version
125+
env:
126+
version: ${{ needs.check_version.outputs.version }}
127+
steps:
128+
- uses: actions/checkout@v4
129+
- uses: docker/setup-qemu-action@v3
130+
- uses: docker/setup-buildx-action@v3
131+
132+
- name: Generate files
133+
run: |
134+
mkdir -p docker/manylinux2014
135+
wget -qO docker/manylinux2014/Dockerfile_s390x https://github.com/opencv/opencv-python/raw/refs/tags/${version}/docker/manylinux2014/Dockerfile_x86_64
136+
patch -p1 < s390x.patch
137+
cd docker/manylinux2014
138+
sed -i "s@FROM quay.io/pypa/manylinux2014_x86_64@FROM quay.io/pypa/manylinux2014_s390x@g" Dockerfile_s390x
139+
image_tag=$(cat Dockerfile_s390x | grep "Version:" | sed 's/# Version: //')
140+
echo "image_tag=${image_tag}" >> $GITHUB_ENV
141+
142+
- name: Login to GitHub Container Registry
143+
uses: docker/login-action@v3
144+
with:
145+
registry: ghcr.io
146+
username: ${{ github.repository_owner }}
147+
password: ${{ secrets.GITHUB_TOKEN }}
148+
149+
- name: Build and push image
150+
uses: docker/build-push-action@v6
151+
with:
152+
context: .
153+
file: docker/manylinux2014/Dockerfile_s390x
154+
platforms: linux/s390x
155+
push: true
156+
tags: |
157+
ghcr.io/${{ github.repository_owner }}/opencv-python-manylinux2014-s390x:${{ env.image_tag }}
158+
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/opencv-python-manylinux2014-s390x:buildcache
159+
cache-to: type=registry,ref=ghcr.io/${{ github.repository_owner }}/opencv-python-manylinux2014-s390x:buildcache,mode=max

.github/workflows/build-manywheel-images.yml renamed to .github/workflows/build-manylinux-images.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- cron: 0 0 * * *
77

88
jobs:
9-
build_loongarch64_wheels:
9+
build_loongarch64_manylinux:
1010
name: Build image for loongarch64
1111
runs-on: ubuntu-latest
1212
steps:
@@ -80,6 +80,7 @@ jobs:
8080
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8181

8282
- name: Release
83+
if: env.build == '1'
8384
uses: softprops/action-gh-release@v2
8485
with:
8586
repository: ${{ github.repository }}

.github/workflows/build_wheels_linux.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
echo "========== Build Args =========="
2929
echo "opencv-python version: ${version}"
3030
31-
gh release view ${version} -R ${{ github.repository }} | grep opencv.*.whl >/dev/null 2>&1 || echo "build=1" >> $GITHUB_ENV
31+
gh release view ${version} -R ${{ github.repository }} | grep opencv.*.whl >/dev/null 2>&1 || echo "build=1" >> $GITHUB_OUTPUT
3232
env:
3333
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3434

@@ -80,6 +80,8 @@ jobs:
8080
uses: docker/setup-qemu-action@v3
8181
- name: Build a package
8282
run: source scripts/build.sh
83+
env:
84+
DOCKER_DEFAULT_PLATFORM: linux/loong64
8385
- name: Saving a wheel accordingly to matrix
8486
uses: actions/upload-artifact@v4
8587
with:
@@ -98,10 +100,12 @@ jobs:
98100
steps:
99101
- uses: actions/download-artifact@v4
100102
with:
101-
name: wheels
103+
pattern: wheel-*
102104
path: wheelhouse/
105+
merge-multiple: true
103106
- name: Upload wheels
104107
run: |
108+
ls -al wheelhouse/
105109
pip install twine==6.0.1
106110
for file in wheelhouse/*.whl; do
107111
twine upload --repository-url https://gitlab.com/api/v4/projects/65746188/packages/pypi $file || true

0 commit comments

Comments
 (0)