-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Python virtual environment and optional pip upgrade. #159
Conversation
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
May want to tweak the messages output when running pip due to: and that can now indicate you want newer pip installed. To be consistent all images should likely use:
There will be duplicate information in logging when new enough |
[test] |
…n-container into virtual-environment # Conflicts: # 3.3/README.md
Note that of all the PRs, this one should be regarded as highest priority. |
[test] |
There should also be some test for this change present. Something along the lines of setting the env var to upgrade pip to latest and then trying to install a package that is available only as a wheel, but that can be added later. I have verified the new functionality manually for the time being. |
This set of changes addresses #90 by adding in use of a Python virtual environment. It means #58, #117 and #158 can be closed out as well since change provides way for user to indicate they want the latest
pip
version installed, overriding whatever version comes with SCL or which the image was explicitly installing to match RHEL.I have checked this for CentOS images for each Python version by using OpenShift to do a Docker build of the respective directives and then deploying a test application etc. I have not checked this for RHEL variants of the images or used the top level makefile build system.
A number of points to look at when evaluating this change.
at end of s2i/bin/assemble generates lot of warnings.
This is because the Python virtual environment creates symbolic links back to the main Python installation.
The fault here is not the use of a Python virtual environment or where it is placed. The problem here is the
fix-permissions
script. That script has:If any file created under the directory for which permissions are being changed is actually a symbolic link, then it will attempt to change the target of the symbolic link. If the symbolic link points to a file elsewhere in the file system which the user has no privileges to modify, you will get these warnings. As
chmod
on Linux has no way to say change the permissions on the link rather than the target, the way to get rid of all the warnings would be to use the-f
option tochgrp
andchmod
. This at least suppresses the warnings. The other alternative is to use a fancy condition withfind
so that it doesn't exec the command when a file is a symbolic link.Either way, this is an issue for the command base image that
fix-permissions
is added in.pip
cache directory must be disabled.There is no real reason to have the cache anyway as it just takes up extra space in the image and is not needed by the running application.
Leaving the
pip
cache directory in place causes other problems because the directory permissions get changed. As a consequence,pip
will try and set them back to what it wants ifpip
were run in a subsequent layer. Changing permissions of a directory in a higher layer can cause the AUFS permissions bug and the directory then becomes inaccessible and could then causepip
to fail later.To ensure the
pip
cache is always disabled, including for whenpip
is run explicitly in a derived imageDockerfile
, theDockerfile
for these images should set:It has to have a value of
off
because of the strange parsing thatpip
does on argument values.pip
which is a part of SCL is too old to be able to install Linux wheels, plus other reported issues. Some packages are now only supplying binary wheels for Linux and no source packages. Upgrading enabled by settingUPGRADE_PIP_TO_LATEST
to non empty value:as build time environment variable. Could also be supplied in the
.s2i/environment
file.Making this change in same PR as adding Python virtual environment as it requires use of Python virtual environment. It is not possible to install a newer
pip
version into a per usersite-packages
directory as it can't first uninstall thepip
version installed in system wide Python installation.$HOME/.local/bin
in$PATH
so is removed. This should not cause any problems as was only used by Python when per usersite-packages
was being used. The--user
option topip
has also been removed though as that is incompatible with Python virtual environments. That is, cannot usepip install --user
when using a Python virtual environment.There is a very low risk that someone had created a derived Docker image, or a custom
assemble
script which ranpip install --user
for some reason, but that is not likely. So not expecting this change would really cause any real world impacts on existing users. If a user was affected, they would need to remove the--user
option, and if running it from aDockerfile
and also activate the Python virtual environment first, in addition to enabling SCL packages as they would already have had to be doing.As the Python virtual environment needs to be manually activated, if someone uses
oc exec pod command
oroc rsh pod command
, then the Python virtual environment will not be activated. This is not seen as a problem because they also would have needed to enable the SCL Python package themselves as well. The latter would have meant they had to wrap the command in a shell script for it to work and rely on theBASH_ENV
hack. So long as that is done then the Python virtual environment should be activated fine, as activation was added to thecontrib/etc/scl_enable
script invoked as a side effect ofBASH_ENV
.In CentOS image for Python 3.3, still install
pip
1.5.6 to match what was provided in RHEL image, but now only installed within the Python virtual environment and not in the base SCL Python installation. Also install it withpip
rather thaneasy_install
to ensure that it replaces thepip
version in the Python virtual environment correctly.