From eec9163e0e51db48424bc6397b44b70bcb55d331 Mon Sep 17 00:00:00 2001 From: Davlet Panech Date: Fri, 11 Feb 2022 16:34:37 -0500 Subject: [PATCH] Dockerfile: install tox in its own virtualenv Fix multiple problems with python modules that cause build errors. * Avoid replacing RPM-owned python modules with pip: - Remove python-tox: installed via pip later in Dockerfile - Remove python-testrepository: installed via pip later in Dockerfile (required by pbr) - Add python-virtualenv: was pulled in by one of the removed packages above * builder-constraints.txt: used only for global packages: - Move all version constraints of Dockerfile into constraints file - Remove filelock and platformdirs packages (required by tox -- see below). - git-review: downgrade to 1.28.0, latest official version compatible with python 2.7 * Install a sane python 2.7 virtual environment that doesn't conflict with RPM modules, that includes tox. Create a symlink to tox in /usr/bin/. Uses a separate contraints file. * builder-opt-py27-constraints.txt: new file for the virtualenv in /opt: - tox==3.23.0 - Remove "filelock" and "platformdirs" packages formerly in the original constraints file. They resolve correctly by the tox requirement. Note that this downgrades the packages slightly compared to the explicit requirements, back to the latest official versions compatible with python 2.7. See revisions starlingx/tools revisions: 0d67f81bdff338c2f965a50aa3fccac08579ec60 7bde482bcbee0d740446d7484a59d312e73e769b Closes-Bug: 1960675 Signed-off-by: Davlet Panech Change-Id: I7e3e7e4f4afa52a614cb9f58b2d6172441ea7bc1 --- Dockerfile | 32 ++++++++++++++++++++----- toCOPY/builder-constraints.txt | 9 +++++-- toCOPY/builder-opt-py27-constraints.txt | 1 + 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 toCOPY/builder-opt-py27-constraints.txt diff --git a/Dockerfile b/Dockerfile index 98dce557..354137d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -108,8 +108,7 @@ RUN yum install -y \ python3-devel \ python-sphinx \ python-subunit \ - python-testrepository \ - python-tox \ + python-virtualenv \ python-yaml \ python2-ruamel-yaml \ postgresql \ @@ -190,10 +189,31 @@ RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == system # pip installs COPY toCOPY/builder-constraints.txt /home/$MYUNAME/ -RUN pip install -c /home/$MYUNAME/builder-constraints.txt pbr==5.6.0 --upgrade && \ - pip install -c /home/$MYUNAME/builder-constraints.txt git-review==2.1.0 --upgrade && \ - pip install -c /home/$MYUNAME/builder-constraints.txt python-subunit==1.4.0 junitxml==0.7 testtools==2.4.0 --upgrade && \ - pip install -c /home/$MYUNAME/builder-constraints.txt tox==3.23.0 --upgrade +# Install required python modules globally; versions are in the constraints file. +# Be careful not to replace modules provided by RPMs as it may break +# other system packages. Look for warnings similar to "Uninstalling a +# distutils installed project has been deprecated" from pip. +RUN pip install -c /home/$MYUNAME/builder-constraints.txt \ + testrepository \ + fixtures \ + pbr \ + git-review \ + python-subunit \ + junitxml \ + testtools + + +# Create a sane py27 virtualenv +COPY toCOPY/builder-opt-py27-constraints.txt /home/$MYUNAME +RUN virtualenv /opt/py27 && \ + source /opt/py27/bin/activate && \ + pip install -c /home/$MYUNAME/builder-opt-py27-constraints.txt \ + tox \ + && \ + for prog in tox ; do \ + ln -s /opt/py27/bin/$prog /usr/bin ; \ + done + # Inherited tools for mock stuff # we at least need the mock_cache_unlock tool diff --git a/toCOPY/builder-constraints.txt b/toCOPY/builder-constraints.txt index 15d78701..bde18a98 100644 --- a/toCOPY/builder-constraints.txt +++ b/toCOPY/builder-constraints.txt @@ -1,5 +1,10 @@ more-itertools===5.0.0;python_version=='2.7' # Last version with official 2.7 support pyparsing===2.4.7 -filelock===3.4.0 # Last version with official py2.7 support was 3.2.1, but 3.4.0 is known to work -platformdirs===2.4.0 # Last version with official py2.7 support was 2.0.2, but 2.4.0 is known to work +git-review==1.28.0 # Last version with official 2.7 support +pbr==5.6.0 # Last version with official 2.7 support +python-subunit==1.4.0 +junitxml==0.7 +testtools==2.4.0 +testrepository==0.0.20 # Replacement for python-testrepository-0.18 rpm +fixtures==3.0.0 # Required by testrepository diff --git a/toCOPY/builder-opt-py27-constraints.txt b/toCOPY/builder-opt-py27-constraints.txt new file mode 100644 index 00000000..77d991c2 --- /dev/null +++ b/toCOPY/builder-opt-py27-constraints.txt @@ -0,0 +1 @@ +tox===3.23.0