Add docker files and scripts for creating cross-distro PyPI packages

This commit is contained in:
Gaute Lindkvist
2020-06-16 13:06:52 +02:00
parent cbd23e71ef
commit 5515422d02
6 changed files with 113 additions and 5 deletions

12
python/Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
# Dockerfile to generate PyPI packages. Needs to be run from the opm-common root folder
# Example use:
# sudo docker build -t manylinux2014_opm:built . -f python/Dockerfile
FROM quay.io/pypa/manylinux2014_x86_64
ARG version_tag=""
WORKDIR /tmp/opm-common
RUN echo "Using package version tag: $version_tag"
ADD . .
RUN /bin/bash /tmp/opm-common/python/generate-pypi-package.sh $version_tag
# docker run -e PLAT=manylinux2014_x86_64 -it lindkvis/manylinux2014_opm:latest

8
python/Dockerfile.create Normal file
View File

@@ -0,0 +1,8 @@
# Docker file to generate a Docker image capable of building PyPI packages
# Example use:
# Use sudo docker build -t lindkvis/manylinux2014_opm:latest -f Dockerfile.create .
FROM quay.io/pypa/manylinux2014_x86_64
WORKDIR /tmp
COPY setup-docker-image.sh .
RUN /bin/bash /tmp/setup-docker-image.sh

61
python/generate-pypi-package.sh Executable file
View File

@@ -0,0 +1,61 @@
#!/bin/bash
# Run in docker container
# docker run -e PLAT=manylinux2014_x86_64 -it quay.io/pypa/manylinux2014_x86_64
VERSION_TAG=${1:-""}
#export PYTHON27=/usr/bin/python2.7
export PYTHON35=/opt/python/cp35-cp35m/bin/python
export PYTHON36=/opt/python/cp36-cp36m/bin/python
export PYTHON37=/opt/python/cp37-cp37m/bin/python
export PYTHON38=/opt/python/cp38-cp38/bin/python
/bin/bash /tmp/opm-common/python/setup-docker-image.sh
cd /tmp/opm-common
# Delete the folder if it already exists
if [ -d build ]; then
rm -rf build
fi
mkdir build && cd build
cmake3 -DPYTHON_EXECUTABLE=${PYTHON35} -DBOOST_INCLUDEDIR=/usr/include/boost169 -DBOOST_LIBRARYDIR=/usr/lib64/boost169 \
-DOPM_ENABLE_PYTHON=ON -DOPM_ENABLE_DYNAMIC_BOOST=OFF -DOPM_ENABLE_DYNAMIC_PYTHON_LINKING=OFF \
-DOPM_PYTHON_PACKAGE_VERSION_TAG=${VERSION_TAG} ..
# make step is necessary until the generated ParserKeywords/*.hpp are generated in the Python step
make -j2
./setup-package.sh
${PYTHON35} -m auditwheel repair python/dist/*cp35*.whl
# Run setup-package.sh four times (Python 3.5, 3.6, 3.7 and 3.8)
cmake3 -DPYTHON_EXECUTABLE=${PYTHON36} -DBOOST_INCLUDEDIR=/usr/include/boost169 -DBOOST_LIBRARYDIR=/usr/lib64/boost169 \
-DOPM_ENABLE_PYTHON=ON -DOPM_ENABLE_DYNAMIC_BOOST=OFF -DOPM_ENABLE_DYNAMIC_PYTHON_LINKING=OFF \
-DOPM_PYTHON_PACKAGE_VERSION_TAG=${VERSION_TAG} ..
./setup-package.sh
${PYTHON36} -m auditwheel repair python/dist/*cp36*.whl
cmake3 -DPYTHON_EXECUTABLE=${PYTHON37} -DBOOST_INCLUDEDIR=/usr/include/boost169 -DBOOST_LIBRARYDIR=/usr/lib64/boost169 \
-DOPM_ENABLE_PYTHON=ON -DOPM_ENABLE_DYNAMIC_BOOST=OFF -DOPM_ENABLE_DYNAMIC_PYTHON_LINKING=OFF \
-DOPM_PYTHON_PACKAGE_VERSION_TAG=${VERSION_TAG} ..
./setup-package.sh
${PYTHON37} -m auditwheel repair python/dist/*cp37*.whl
cmake3 -DPYTHON_EXECUTABLE=${PYTHON38} -DBOOST_INCLUDEDIR=/usr/include/boost169 -DBOOST_LIBRARYDIR=/usr/lib64/boost169 \
-DOPM_ENABLE_PYTHON=ON -DOPM_ENABLE_DYNAMIC_BOOST=OFF -DOPM_ENABLE_DYNAMIC_PYTHON_LINKING=OFF \
-DOPM_PYTHON_PACKAGE_VERSION_TAG=${VERSION_TAG} ..
./setup-package.sh
${PYTHON38} -m auditwheel repair python/dist/*cp38*.whl
#cmake3 -DPYTHON_EXECUTABLE=${PYTHON27} -DBOOST_INCLUDEDIR=/usr/include/boost169 -DBOOST_LIBRARYDIR=/usr/lib64/boost169 \
#-DOPM_ENABLE_PYTHON=ON -DOPM_ENABLE_DYNAMIC_BOOST=OFF -DOPM_ENABLE_DYNAMIC_PYTHON_LINKING=OFF ..
#./setup-package.sh
#${PYTHON27} -m auditwheel repair python/dist/*cp27*.whl
# Example of upload
# /usr/bin/python3 -m twine upload --repository testpypi wheelhouse/*

View File

@@ -0,0 +1,24 @@
#!/bin/bash
# Script to be run on a manylinux2014 docker image to complete it for OPM usage.
# i.e. docker run -i -t quay.io/pypa/manylinux2014_x86_64 < setup-docker-image.sh
# A ready made Docker image is available at Dockerhub:
# docker run -i -t lindkvis/manylinux2014_opm:latest
yum-config-manager --add-repo \
https://www.opm-project.org/package/opm.repo
yum install -y cmake3 ccache boost169-devel boost169-static
yum install -y blas-devel suitesparse-devel trilinos-openmpi-devel
#${PYTHON27} -m pip install pip --upgrade
#${PYTHON27} -m pip install wheel setuptools twine pytest-runner auditwheel
${PYTHON35} -m pip install pip --upgrade
${PYTHON35} -m pip install wheel setuptools twine pytest-runner auditwheel
${PYTHON36} -m pip install pip --upgrade
${PYTHON36} -m pip install wheel setuptools twine pytest-runner auditwheel
${PYTHON37} -m pip install pip --upgrade
${PYTHON37} -m pip install wheel setuptools twine pytest-runner auditwheel
${PYTHON38} -m pip install pip --upgrade
${PYTHON38} -m pip install wheel setuptools twine pytest-runner auditwheel

View File

@@ -40,7 +40,7 @@ if 'build' in sys.argv:
ext_modules = [
Extension(
'libopmcommon_python',
'opm.libopmcommon_python',
[
'cxx/unit_system.cpp',
'cxx/connection.cpp',
@@ -73,7 +73,7 @@ ext_modules = [
setup(
name='Opm',
version = '@opm-common_VERSION@',
version = '@opm-common_VERSION@' + '@opm-common_PYTHON_PACKAGE_VERSION@',
url='http://www.opm-project.org',
author='The Open Porous Media Project',
author_email='opmuser@gmail.com',
@@ -89,7 +89,6 @@ setup(
'opm.tools'
],
ext_modules=ext_modules,
package_data={'opm': ['libopmcommon_python{}'.format(suffix)]},
include_package_data=True,
license='Open Source',
zip_safe=False,