After some reading up, I have found the manylinux project. From what I can tell, manylinux builds python in their docker images with an older toolchain, and older version of glibc
.
This leads me to believe that it might be possible to generate and package the venv and python3.8 binary in the charm by using the python3.8 in the manylinux docker image (which is built with the older glibc).
The version of glibc used in the manylinux image is 2.17.
$ docker run -it --rm quay.io/pypa/manylinux2014_x86_64 bash
[root@0b68add7d530 /]# /opt/python/cp38-cp38/bin/python
Python 3.8.5 (default, Jul 27 2020, 16:20:29)
[GCC 9.3.1 20200408 (Red Hat 9.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.confstr('CS_GNU_LIBC_VERSION')
'glibc 2.17'
By mounting the requirements.txt and the build dir, we are able to generate the venv and python3.8 to be packaged into the charm with the manylinux python built with glibc 2.17.
#!/bin/bash
set -eux
docker run -it --rm \
-v `pwd`/requirements.txt:/srv/requirements.txt \
-v `pwd`/build:/srv/build \
-v `pwd`/out:/srv/out \
quay.io/pypa/manylinux2014_x86_64 \
/bin/sh -c \
'/opt/python/cp38-cp38/bin/python -m venv --copies --clear /srv/build/venv && \
/opt/python/cp38-cp38/bin/pip install -r /srv/requirements.txt -t /srv/build/venv/lib/python3.8/site-packages && \
cp -r /usr/local/lib/libcrypt.* /srv/build/venv/lib/ && \
cp -r /opt/_internal/cpython-3.8.5/lib/python3.8 /srv/build/venv/lib/ && \
cp -r /opt/_internal/cpython-3.8.5/include/* /srv/build/venv/include/ && \
chown -R 1000:1000 /srv/build && \
/opt/python/cp38-cp38/bin/python /srv/build/scripts/create_zip.py && \
chown -R 1000:1000 /srv/out'
By doing this we were able to build a .charm that we can deploy on centos and ubuntu.
This leaves me wondering if a) is charmcraft
the right place to look at doing this sort of thing?, b) if yes, can we make charmcraft
support a docker based build component like this?