-
Notifications
You must be signed in to change notification settings - Fork 3
150 lines (130 loc) · 5.47 KB
/
build_wheel_dockerfile.yml
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
name: Build via Dockerfile
on:
workflow_dispatch:
inputs:
package:
required: true
type: string
version:
required: true
type: string
python_version:
required: true
type: string
workflow_call:
inputs:
package:
required: true
type: string
version:
required: true
type: string
python_version:
required: true
type: string
jobs:
calculate_matrix:
name: Calculate build matrix
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get build strategy
working-directory: packages/${{ inputs.package }}
run: |
echo STRATEGY=$(cat build.yaml | yq .strategy) >> $GITHUB_ENV
- uses: nick-fields/assert-action@v1
with:
expected: "dockerfile"
actual: ${{ env.STRATEGY }}
comparison: exact
- name: Calculate build matrix
id: gen_matrix
working-directory: packages/${{ inputs.package }}
run: |
set -x
echo "::set-output name=matrix::$(cat build.yaml | yq -o=json -I=0 '[(.source | array_to_map),(select(.source | type == "!!str").source | (. | select(. != null) ) as $i ireduce({}; .[$i | 0] = $i))] | filter(. | length > 0) | map(to_entries) | .[0]')"
echo "::set-output name=matrix_last::$(cat build.yaml | yq -o=json -I=0 '[(.source | array_to_map),(select(.source | type == "!!str").source | (. | select(. != null) ) as $i ireduce({}; .[$i | 0] = $i))] | filter(. | length > 0) | map(to_entries) | .[0] | length - 1')"
outputs:
build_matrix: ${{ steps.gen_matrix.outputs.matrix }}
build_matrix_last: ${{ steps.gen_matrix.outputs.matrix_last }}
build:
name: Python ${{ inputs.python_version }} ${{ inputs.package }} ${{ inputs.version }} ${{ fromJSON(needs.calculate_matrix.outputs.build_matrix_last) == 0 && ' ' || matrix.build_params['key'] }}
runs-on: ubuntu-latest
needs: calculate_matrix
strategy:
matrix:
build_params: ${{ fromJSON(needs.calculate_matrix.outputs.build_matrix) }}
fail-fast: true
max-parallel: 1
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Calculate previous build number
if: ${{ matrix.build_params['key'] != 0 }}
run: |
echo "PREVIOUS=$((${{ matrix.build_params['key'] }} - 1))" >> $GITHUB_ENV
- name: Download artifact
uses: actions/download-artifact@v3
if: ${{ matrix.build_params['key'] != 0 }}
with:
name: ${{ inputs.package }}-${{ inputs.version }}-cpython${{ inputs.python_version }}-dockerstage${{ env.PREVIOUS }}
path: /tmp
- name: Load image
if: ${{ matrix.build_params['key'] != 0 }}
run: |
docker load --input /tmp/stage.tar
docker image ls -a
- name: Push image to local registry
if: ${{ matrix.build_params['key'] != 0 }}
run: |
docker image tag armv7l:latest localhost:5000/base:latest
docker image push localhost:5000/base:latest
- name: Build wheels via Docker
uses: docker/build-push-action@v3
with:
context: packages/${{ inputs.package }}
file: packages/${{ inputs.package }}/${{ matrix.build_params['value'] }}
build-contexts: base=docker-image://${{ matrix.build_params['key'] == 0 && 'ghcr.io/bjia56/armv7l-wheel-builder:main' || 'localhost:5000/base:latest' }}
build-args: |
PYTHON_VERSION=${{ inputs.python_version }}
VERSION=${{ inputs.version }}
OUTPUT_DIR=/export
push: false
platforms: linux/armhf
tags: armv7l:latest
cache-from: type=gha,scope=${{ github.ref }}-${{ inputs.package }}-${{ inputs.version }}-${{ inputs.python_version }}-${{ matrix.build_params['key'] }}
cache-to: type=gha,mode=max,scope=${{ github.ref }}-${{ inputs.package }}-${{ inputs.version }}-${{ inputs.python_version }}
outputs: type=docker,dest=/tmp/stage.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
if: ${{ matrix.build_params['key'] != fromJSON(needs.calculate_matrix.outputs.build_matrix_last) }}
with:
name: ${{ inputs.package }}-${{ inputs.version }}-cpython${{ inputs.python_version }}-dockerstage${{ matrix.build_params['key'] }}
path: /tmp/stage.tar
- name: Load image
if: ${{ matrix.build_params['key'] == fromJSON(needs.calculate_matrix.outputs.build_matrix_last) }}
run: |
docker load --input /tmp/stage.tar
docker image ls -a
- name: Extract output
if: ${{ matrix.build_params['key'] == fromJSON(needs.calculate_matrix.outputs.build_matrix_last) }}
run: |
docker run -v /tmp/output:/host armv7l:latest bash -c "cp /export/* /host/"
- name: Upload Artifacts
uses: actions/upload-artifact@v3
if: ${{ matrix.build_params['key'] == fromJSON(needs.calculate_matrix.outputs.build_matrix_last) }}
with:
name: ${{ inputs.package }}-${{ inputs.version }}-cpython${{ inputs.python_version }}
path: /tmp/output/*.whl