Skip to content

Build via Dockerfile #41

Build via Dockerfile

Build via Dockerfile #41

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