Weekly wheel build images #203
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Weekly wheel build images | |
on: | |
schedule: | |
- cron: "42 5 * * 1" | |
workflow_dispatch: | |
inputs: | |
use_cache: | |
description: Use GH Actions cache | |
type: boolean | |
required: false | |
default: true | |
env: | |
CONTAINER_REGISTRY: ghcr.io | |
jobs: | |
build_wheel_linux_dockers: | |
name: Build wheel containers | |
runs-on: ubuntu-20.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
# 64-bit manylinux | |
- system: "manylinux" | |
type: "_2_34" | |
arch: "x86_64" | |
py_minors: "8 9 10 11 12 13" | |
#- system: "manylinux" | |
# type: "_2_28" | |
# arch: "x86_64" | |
# py_minors: "8 9 10 11 12" | |
#- system: "manylinux" | |
# type: "2014" | |
# arch: "x86_64" | |
# py_minors: "8 9 10 11 12" | |
#- system: "manylinux" | |
# type: "2010" | |
# arch: "x86_64" | |
# py_minors: "8 9" | |
# 64-bit musllinux | |
- system: "musllinux" | |
type: "_1_2" | |
arch: "x86_64" | |
py_minors: "8 9 10 11 12 13" | |
#- system: "musllinux" | |
# type: "_1_1" | |
# arch: "x86_64" | |
# py_minors: "8 9 10 11" | |
#- system: "musllinux" | |
# type: "_1_2" | |
# arch: "x86_64" | |
# py_minors: "8 9 10 11" | |
# 32-bit manylinux | |
- system: "manylinux" | |
type: "2014" | |
arch: "i686" | |
py_minors: "10 11 12 13" | |
#- system: "manylinux" | |
# type: "2010" | |
# arch: "i686" | |
# py_minors: "8 9" | |
# 32-bit musllinux | |
# Seems that pyyaml depends on distutils, which is only available on Python 3.11 and below | |
- system: "musllinux" | |
type: "_1_2" | |
arch: "i686" | |
py_minors: "9 10 11" | |
#- system: "musllinux" | |
# type: "_1_1" | |
# arch: "i686" | |
# py_minors: "8 9 10 11" | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup Docker buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Setup cache | |
if: github.event_name != 'workflow_dispatch' || fromJSON(github.event.inputs.use_cache) | |
uses: actions/cache@v4 | |
with: | |
path: .buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }} | |
key: buildx-cache-${{ matrix.system }}${{ matrix.type }}-${{ matrix.arch }}-${{ github.sha }} | |
restore-keys: buildx-cache-${{ matrix.system }}${{ matrix.type }}-${{ matrix.arch }}- | |
- name: Define environment variables | |
run: | | |
# Relative path to Dockerfile to build | |
echo "DOCKERFILE=docker_build_wheel/Dockerfile-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}" >> "$GITHUB_ENV" | |
# Filename to store SHA hash of the Dockerfile | |
echo "SHA_FILENAME=${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}:latest.sha.txt" >> "$GITHUB_ENV" | |
# The base image to use when building the docker container | |
echo "IMAGE=quay.io/pypa/${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}:latest" >> "$GITHUB_ENV" | |
# Cache directory for checking whether to (re)build docker container | |
echo "CACHE_DIR=.buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}" >> "$GITHUB_ENV" | |
- name: Create docker file | |
run: | | |
mkdir -p docker_build_wheel | |
bash .github/docker/gen_dockerfile.sh ${{ matrix.system }} ${{ matrix.type }} ${{ matrix.arch }} "${{ matrix.py_minors }}" \ | |
> ${DOCKERFILE} | |
- name: Create file with SHA hashes | |
run: | | |
sha256sum ${DOCKERFILE} > ${SHA_FILENAME} | |
- name: Check whether to build new image | |
run: | | |
docker pull ${IMAGE} | |
docker images --no-trunc --quiet ${IMAGE} >> ${SHA_FILENAME} | |
if [ -f "${CACHE_DIR}/${SHA_FILENAME}" ] && [ "$( cat ${SHA_FILENAME} )" == "$( cat ${CACHE_DIR}/${SHA_FILENAME} )" ]; then | |
echo "BUILD_NEW_IMAGE=false" >> $GITHUB_ENV | |
else | |
echo "BUILD_NEW_IMAGE=true" >> $GITHUB_ENV | |
fi | |
- name: Login to GitHub Container Registry | |
if: env.BUILD_NEW_IMAGE == 'true' | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.CONTAINER_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
if: env.BUILD_NEW_IMAGE == 'true' | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: docker_build_wheel/Dockerfile-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }} | |
tags: ${{ env.CONTAINER_REGISTRY }}/sintef/dlite-python-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}:latest | |
push: true | |
build-args: | | |
PY_MINORS=${{ matrix.py_minors }} | |
cache-from: type=local,src=.buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }} | |
cache-to: type=local,dest=.buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}-new,mode=max | |
# Temporary fix from https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: Move cache | |
if: env.BUILD_NEW_IMAGE == 'true' | |
run: | | |
rm -rf .buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }} | |
mv .buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}-new .buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }} | |
- name: Add sha.txt to cache | |
if: env.BUILD_NEW_IMAGE == 'true' | |
run: mv ${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}:latest.sha.txt .buildx-cache-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }} |