|
| 1 | +# This image provides a Python 3.11 environment you can use to run your Python |
| 2 | +# applications. |
| 3 | +FROM quay.io/fedora/s2i-base:37 |
| 4 | + |
| 5 | +EXPOSE 8080 |
| 6 | + |
| 7 | +ENV PYTHON_VERSION=3.11 \ |
| 8 | + PATH=$HOME/.local/bin/:$PATH \ |
| 9 | + PYTHONUNBUFFERED=1 \ |
| 10 | + PYTHONIOENCODING=UTF-8 \ |
| 11 | + LC_ALL=en_US.UTF-8 \ |
| 12 | + LANG=en_US.UTF-8 \ |
| 13 | + PIP_NO_CACHE_DIR=off |
| 14 | + |
| 15 | +ENV NAME=python3 \ |
| 16 | + VERSION=0 \ |
| 17 | + ARCH=x86_64 |
| 18 | + |
| 19 | +ENV SUMMARY="Platform for building and running Python $PYTHON_VERSION applications" \ |
| 20 | + DESCRIPTION="Python $PYTHON_VERSION available as container is a base platform for \ |
| 21 | +building and running various Python $PYTHON_VERSION applications and frameworks. \ |
| 22 | +Python is an easy to learn, powerful programming language. It has efficient high-level \ |
| 23 | +data structures and a simple but effective approach to object-oriented programming. \ |
| 24 | +Python's elegant syntax and dynamic typing, together with its interpreted nature, \ |
| 25 | +make it an ideal language for scripting and rapid application development in many areas \ |
| 26 | +on most platforms." |
| 27 | + |
| 28 | +LABEL summary="$SUMMARY" \ |
| 29 | + description="$DESCRIPTION" \ |
| 30 | + io.k8s.description="$DESCRIPTION" \ |
| 31 | + io.k8s.display-name="Python 3.11" \ |
| 32 | + io.openshift.expose-services="8080:http" \ |
| 33 | + io.openshift.tags="builder,python,python311,python-311,rh-python311" \ |
| 34 | + com.redhat.component="$NAME" \ |
| 35 | + name="fedora/$NAME-311" \ |
| 36 | + version="$VERSION" \ |
| 37 | + usage="s2i build https://github.com/sclorg/s2i-python-container.git --context-dir=3.11/test/setup-test-app/ quay.io/fedora/$NAME-311 python-sample-app" \ |
| 38 | + maintainer="SoftwareCollections.org < [email protected]>" |
| 39 | + |
| 40 | +RUN INSTALL_PKGS="python3 python3-devel python3-setuptools python3-pip nss_wrapper \ |
| 41 | + httpd httpd-devel atlas-devel gcc-gfortran libffi-devel \ |
| 42 | + libtool-ltdl enchant redhat-rpm-config krb5-devel" && \ |
| 43 | + dnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ |
| 44 | + rpm -V $INSTALL_PKGS && \ |
| 45 | + dnf -y clean all --enablerepo='*' |
| 46 | + |
| 47 | +# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH. |
| 48 | +COPY 3.11/s2i/bin/ $STI_SCRIPTS_PATH |
| 49 | + |
| 50 | +# Copy extra files to the image. |
| 51 | +COPY 3.11/root/ / |
| 52 | + |
| 53 | +# Python 3.7+ only |
| 54 | +# Yes, the directory below is already copied by the previous command. |
| 55 | +# The problem here is that the wheels directory is copied as a symlink. |
| 56 | +# Only if you specify symlink directly as a source, COPY copies all the |
| 57 | +# files from the symlink destination. |
| 58 | +COPY 3.11/root/opt/wheels /opt/wheels |
| 59 | +# - Create a Python virtual environment for use by any application to avoid |
| 60 | +# potential conflicts with Python packages preinstalled in the main Python |
| 61 | +# installation. |
| 62 | +# - In order to drop the root user, we have to make some directories world |
| 63 | +# writable as OpenShift default security model is to run the container |
| 64 | +# under random UID. |
| 65 | +RUN python3.11 -m venv ${APP_ROOT} && \ |
| 66 | +# Python 3.7+ only code, Python <3.7 installs pip from PyPI in the assemble script. \ |
| 67 | +# We have to upgrade pip to a newer verison because: \ |
| 68 | +# * pip < 9 does not support different packages' versions for Python 2/3 \ |
| 69 | +# * pip < 19.3 does not support manylinux2014 wheels. Only manylinux2014 (and later) wheels \ |
| 70 | +# support platforms like ppc64le, aarch64 or armv7 \ |
| 71 | +# We are newly using wheel from one of the latest stable Fedora releases (from RPM python-pip-wheel) \ |
| 72 | +# because it's tested better then whatever version from PyPI and contains useful patches. \ |
| 73 | +# We have to do it here (in the macro) so the permissions are correctly fixed and pip is able \ |
| 74 | +# to reinstall itself in the next build phases in the assemble script if user wants the latest version \ |
| 75 | +${APP_ROOT}/bin/pip install /opt/wheels/pip-* && \ |
| 76 | +rm -r /opt/wheels && \ |
| 77 | +chown -R 1001:0 ${APP_ROOT} && \ |
| 78 | +fix-permissions ${APP_ROOT} -P |
| 79 | + |
| 80 | +# For Fedora scl_enable isn't sourced automatically in s2i-core |
| 81 | +# so virtualenv needs to be activated this way |
| 82 | +ENV BASH_ENV="${APP_ROOT}/bin/activate" \ |
| 83 | + ENV="${APP_ROOT}/bin/activate" \ |
| 84 | + PROMPT_COMMAND=". ${APP_ROOT}/bin/activate" |
| 85 | + |
| 86 | +USER 1001 |
| 87 | + |
| 88 | +# Set the default CMD to print the usage of the language image. |
| 89 | +CMD $STI_SCRIPTS_PATH/usage |
0 commit comments