Repository: SINTEF/dlite (language: python)

Issue:
Fix build wheel image for manylinux2014_i686
As seen for example in [this run](https://github.com/SINTEF/dlite/runs/5549961574?check_suite_focus=true) the manylinux2014_i686 image has trouble building, making it impossible to build the wheel for the series of 32-bit Linux distros this image represents.


Discussion / hints:

Fix patch:
diff --git a/.github/docker/Dockerfile-manylinux.template b/.github/docker/Dockerfile-manylinux.template
index 5cb4e260e..0e68ed675 100644
--- a/.github/docker/Dockerfile-manylinux.template
+++ b/.github/docker/Dockerfile-manylinux.template
@@ -26,26 +26,36 @@ FROM quay.io/pypa/manylinux{{ TYPE }}_{{ ARCH }}:latest
 
 ARG PY_MINORS="7 8 9 10"
 
+COPY requirements.txt /tmp/requirements.txt
+
+{{ EXTRA_PRE }}
+
 # Enable rpmfusion for additional packages
 RUN yum update -y && \
-  yum localinstall -y \
+  yum localinstall -y --skip-broken \
     https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm --eval %{centos_ver}).noarch.rpm \
     https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm --eval %{centos_ver}).noarch.rpm && \
   yum install -y \
     redland-devel \
     rasqal-devel \
-    hdf5-devel \
     swig \
     libcurl-devel \
     libxslt-devel \
     libxml2-devel && \
+  if [ "{{ TYPE }}{{ ARCH }}" != "2014i686" ]; then yum install -y hdf5-devel; fi && \
+  if [ -f "/etc/yum.repos.d/pgdg-91.repo" ]; then yum install -y postgresql91-devel; fi && \
 # Unpack static libraries
 # It's necessary to be in /opt/_internal because the internal libraries
 # exist here.
   cd /opt/_internal && \
   tar -Jxvf static-libs-for-embedding-only.tar.xz && \
+  mkdir -p /ci/pip_cache && \
+  if [ -f "/etc/yum.repos.d/pgdg-91.repo" ]; then export PATH="$PATH:/usr/pgsql-9.1/bin"; fi && \
   for minor in ${PY_MINORS}; do \
     python3.${minor} -m pip install -U pip && \
     python3.${minor} -m pip install -U setuptools wheel && \
-    python3.${minor} -m pip install -U cmake oldest-supported-numpy; \
+    python3.${minor} -m pip install -U --cache-dir /ci/pip_cache cmake oldest-supported-numpy && \
+    python3.${minor} -m pip install --cache-dir /ci/pip_cache --prefer-binary -r /tmp/requirements.txt; \
   done
+
+{{ EXTRA_POST }}
diff --git a/.github/docker/Dockerfile-musllinux.template b/.github/docker/Dockerfile-musllinux.template
index 97b574100..7a449bc22 100644
--- a/.github/docker/Dockerfile-musllinux.template
+++ b/.github/docker/Dockerfile-musllinux.template
@@ -23,6 +23,8 @@
 #
 FROM quay.io/pypa/musllinux{{ TYPE }}_{{ ARCH }}:latest
 
+COPY requirements.txt /tmp/requirements.txt
+
 RUN apk add -u \
   redland \
   rasqal \
@@ -32,9 +34,11 @@ RUN apk add -u \
 # It's necessary to be in /opt/_internal because the internal libraries
 # exist here.
   cd /opt/_internal && \
-  tar -Jxvf static-libs-for-embedding-only.tar.xz  && \
+  tar -Jxvf static-libs-for-embedding-only.tar.xz && \
+  mkdir -p /ci/pip_cache && \
   for minor in 7 8 9 10; do \
     python3.${minor} -m pip install -U pip && \
     python3.${minor} -m pip install -U setuptools wheel && \
-    python3.${minor} -m pip install -U cmake oldest-supported-numpy; \
+    python3.${minor} -m pip install -U --cache-dir /ci/pip_cache cmake oldest-supported-numpy && \
+    python3.${minor} -m pip install --cache-dir /ci/pip_cache --prefer-binary -r /tmp/requirements.txt; \
   done
diff --git a/.github/docker/pgdg-91_i686.repo b/.github/docker/pgdg-91_i686.repo
new file mode 100644
index 000000000..9f161282e
--- /dev/null
+++ b/.github/docker/pgdg-91_i686.repo
@@ -0,0 +1,6 @@
+[pgdg91]
+name=PostgreSQL 9.1 RPMs for RHEL/CentOS 6
+baseurl=https://yum-archive.postgresql.org/9.1/redhat/rhel-6-i386
+enabled=1
+gpgcheck=0
+gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
diff --git a/.github/docker/pgdg-91_x86_64.repo b/.github/docker/pgdg-91_x86_64.repo
new file mode 100644
index 000000000..3a6095561
--- /dev/null
+++ b/.github/docker/pgdg-91_x86_64.repo
@@ -0,0 +1,6 @@
+[pgdg91]
+name=PostgreSQL 9.1 RPMs for RHEL/CentOS 6
+baseurl=https://yum-archive.postgresql.org/9.1/redhat/rhel-6-x86_64
+enabled=1
+gpgcheck=0
+gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
diff --git a/.github/workflows/cd_release.yml b/.github/workflows/cd_release.yml
index 2abb92524..229c4e282 100644
--- a/.github/workflows/cd_release.yml
+++ b/.github/workflows/cd_release.yml
@@ -79,15 +79,14 @@ jobs:
             system_type: ["manylinux", "2010"]
             arch: i686
             py_minors: 7,8,9
-          ## Doesn't seem to be working - cannot build container image for this
-          # - os: ubuntu-20.04
-          #   system_type: ["manylinux", "2014"]
-          #   arch: i686
-          #   py_minors: 7,8,9
+          - os: ubuntu-20.04
+            system_type: ["manylinux", "2014"]
+            arch: i686
+            py_minors: 7,8,9
           - os: ubuntu-20.04
             system_type: ["musllinux", "_1_1"]
             arch: i686
-            py_minors: 7,8,9,10
+            py_minors: 7,8,9
 
           # 64-bit linux
           - os: ubuntu-20.04
diff --git a/.github/workflows/ci_build_wheels.yml b/.github/workflows/ci_build_wheels.yml
index 820d7fa6b..a25500faf 100644
--- a/.github/workflows/ci_build_wheels.yml
+++ b/.github/workflows/ci_build_wheels.yml
@@ -5,12 +5,6 @@ on:
     branches:
       - master
   workflow_dispatch:
-    inputs:
-      use_cache:
-        description: Use GH Actions cache (for `pip` when testing)
-        type: boolean
-        required: false
-        default: true
 
 env:
   container_registry: ghcr.io
@@ -28,15 +22,14 @@ jobs:
             system_type: ["manylinux", "2010"]
             arch: i686
             py_minors: 7,9
-          ## Doesn't seem to be working - cannot build image for this
-          # - os: ubuntu-20.04
-          #   system_type: ["manylinux", "2014"]
-          #   arch: i686
-          #   py_minors: 7,9
+          - os: ubuntu-20.04
+            system_type: ["manylinux", "2014"]
+            arch: i686
+            py_minors: 7,9
           - os: ubuntu-20.04
             system_type: ["musllinux", "_1_1"]
             arch: i686
-            py_minors: 7,10
+            py_minors: 7,9
 
           # 64-bit linux
           - os: ubuntu-20.04
@@ -73,9 +66,6 @@ jobs:
           #   arch: x86_64
           #   py_minors: 7,10
 
-    env:
-      CI_PIP_CACHE_DIR: /tmp/pip-cache-${{ matrix.system_type[0] }}${{ matrix.system_type[1] }}_${{ matrix.arch }}
-
     steps:
       - uses: actions/checkout@v2
 
@@ -83,14 +73,6 @@ jobs:
         with:
           python-version: '3.x'
 
-      - name: Setup cache (for linux builds)
-        if: (github.event_name != 'workflow_dispatch' || fromJSON(github.event.inputs.use_cache)) && contains(matrix.system_type[0], 'linux')
-        uses: actions/cache@v2
-        with:
-          path: ${{ env.CI_PIP_CACHE_DIR }}
-          key: pip-cache-${{ matrix.system_type[0] }}${{ matrix.system_type[1] }}-${{ matrix.arch }}-${{ hashFiles('**/requirements.txt') }}
-          restore-keys: pip-cache-${{ matrix.system_type[0] }}${{ matrix.system_type[1] }}-${{ matrix.arch }}-
-
       - name: Login to GitHub Container Registry
         if: startsWith(matrix.os, 'ubuntu')
         uses: docker/login-action@v1
@@ -116,7 +98,3 @@ jobs:
           CIBW_MANYLINUX_I686_IMAGE: ${{ env.container_registry }}/sintef/dlite-python-manylinux${{ matrix.system_type[1] }}_i686:latest
           CIBW_MUSLLINUX_X86_64_IMAGE: ${{ env.container_registry }}/sintef/dlite-python-musllinux_1_1_x86_64:latest
           CIBW_MUSLLINUX_I686_IMAGE: ${{ env.container_registry }}/sintef/dlite-python-musllinux_1_1_i686:latest
-
-      - name: Fix cache dir owner
-        if: (github.event_name != 'workflow_dispatch' || fromJSON(github.event.inputs.use_cache)) && contains(matrix.system_type[0], 'linux')
-        run: sudo chown -R $USER ${{ env.CI_PIP_CACHE_DIR }}
diff --git a/.github/workflows/container_builds_weekly.yml b/.github/workflows/container_builds_weekly.yml
index 973f9b0d4..c81747b93 100644
--- a/.github/workflows/container_builds_weekly.yml
+++ b/.github/workflows/container_builds_weekly.yml
@@ -41,8 +41,6 @@ jobs:
           type: "2010"
           arch: "i686"
           py_minors: "7 8 9"
-        # Doesn't seem to be working.
-        # Will keep in here though, to check if it should start working.
         - system: "manylinux"
           type: "2014"
           arch: "i686"
@@ -50,7 +48,7 @@ jobs:
         - system: "musllinux"
           type: "_1_1"
           arch: "i686"
-          py_minors: "7 8 9 10"
+          py_minors: "7 8 9"
 
     steps:
       - name: Checkout repository
@@ -86,9 +84,18 @@ jobs:
         run: |
           mkdir -p docker_build_wheel
 
+          EXTRA_PRE=""
+          EXTRA_POST=""
+          if [ "${{ matrix.type }}" == "2010" ]; then
+            EXTRA_PRE="COPY .github/docker/pgdg-91_${{ matrix.arch }}.repo /etc/yum.repos.d/pgdg-91.repo"
+            EXTRA_POST="ENV PATH=\$PATH:/usr/pgsql-9.1/bin"
+          fi
+
           sed \
             -e "s|{{ ARCH }}|${{ matrix.arch }}|" \
             -e "s|{{ TYPE }}|${{ matrix.type }}|" \
+            -e "s|{{ EXTRA_PRE }}|${EXTRA_PRE}|" \
+            -e "s|{{ EXTRA_POST }}|${EXTRA_POST}|" \
             .github/docker/Dockerfile-${{ matrix.system }}.template \
             > docker_build_wheel/Dockerfile-${{ matrix.system }}${{ matrix.type }}_${{ matrix.arch }}
 
diff --git a/python/pyproject.toml b/python/pyproject.toml
index f7014eeb1..95395bbd8 100644
--- a/python/pyproject.toml
+++ b/python/pyproject.toml
@@ -21,7 +21,7 @@ before-build = [
   "export PYVER=$(python -c \"import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')\")",
   "export ABITAG=$(python -c \"import sys; cp=f'cp{sys.version_info.major}{sys.version_info.minor}'; print(f'{cp}-{cp}{sys.abiflags}')\")",
 ]
-before-test = "if [ -n \"${CI_PIP_CACHE_DIR}\" ]; then mkdir -p /host${CI_PIP_CACHE_DIR} && chown -R root /host${CI_PIP_CACHE_DIR} && python -m pip install --cache-dir /host${CI_PIP_CACHE_DIR} -U --upgrade-strategy=eager -r {project}/requirements.txt; fi"
+before-test = "python -m pip install --cache-dir /ci/pip_cache --prefer-binary -r {project}/requirements.txt"
 test-command = "python {package}/../bindings/python/tests/test_python_bindings.py"
 
 [tool.cibuildwheel.linux.environment]


Test patch:
diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml
index 9eb72253d..66f72a87a 100644
--- a/.github/workflows/ci_tests.yml
+++ b/.github/workflows/ci_tests.yml
@@ -71,7 +71,7 @@ jobs:
         cd -
     - name: Install python package via setup.py and test the installation
       run: |
-         cd python
-         python3 setup.py install --user
-         cd ../bindings/python/tests
-         python3 __main__.py
+        cd python
+        python3 setup.py install --user
+        cd ../bindings/python/tests
+        python3 __main__.py