Python
Overview
OKD provides S2I enabled Python images for building and running Python applications. The Python S2I builder image assembles your application source with any required dependencies to create a new image containing your Python application. This resulting image can be run either by OKD or by a container runtime.
Versions
Currently, OKD provides versions 2.7, 3.3, 3.4, and 3.5 of Python.
Images
These images come in two flavors, depending on your needs:
RHEL 7
CentOS 7
RHEL 7 Based Images
The RHEL 7 images are available through the Red Hat Registry:
$ docker pull registry.redhat.io/rhscl/python-27-rhel7
$ docker pull registry.redhat.io/openshift3/python-33-rhel7
$ docker pull registry.redhat.io/rhscl/python-34-rhel7
$ docker pull registry.redhat.io/rhscl/python-35-rhel7
CentOS 7 Based Images
These images are available on Docker Hub:
$ docker pull centos/python-27-centos7
$ docker pull openshift/python-33-centos7
$ docker pull centos/python-34-centos7
$ docker pull centos/python-35-centos7
To use these images, you can either access them directly from these image registries or push them into your OKD container image registry. Additionally, you can create an image stream that points to the image, either in your container image registry or at the external location. Your OKD resources can then reference the ImageStream. You can find example image stream definitions for all the provided OKD images.
Build Process
S2I produces ready-to-run images by injecting source code into a container and letting the container prepare that source code for execution. It performs the following steps:
Starts a container from the builder image.
Downloads the application source.
Streams the scripts and application sources into the builder image container.
Runs the assemble script (from the builder image).
Saves the final image.
See S2I Build Process for a detailed overview of the build process.
Configuration
The Python image supports a number of environment variables which can be set to control the configuration and behavior of the Python runtime.
To set these environment variables as part of your image, you can place them into a .s2i/environment file inside your source code repository, or define them in the environment section of the build configuration’s **sourceStrategy**
definition.
You can also set environment variables to be used with an existing image when creating new applications, or by updating environment variables for existing objects such as deployment configurations.
Environment variables that control build behavior must be set as part of the s2i build configuration or in the .s2i/environment file to make them available to the build steps. |
Variable name | Description |
---|---|
| This variable specifies the file name passed to the Python interpreter which is responsible for launching the application. This variable is set to app.py by default. |
| This variable specifies the WSGI callable. It follows the pattern |
| This variable indicates the path to a valid Python file with a gunicorn configuration. |
| Set it to a nonempty value to inhibit the execution of |
| Set it to a nonempty value to inhibit the execution of |
| Set this variable to use a custom index URL or mirror to download required packages during build process. This only affects packages listed in the requirements.txt file. |
| Set this to change the default setting for the number of workers. By default, this is set to the number of available cores times 4. |
Hot Deploying
Hot deployment allows you to quickly make and deploy changes to your application without having to generate a new S2I build. If you are using Django, hot deployment works out of the box.
To enable hot deployment while using Gunicorn, ensure you have a Gunicorn configuration file inside your repository with the **reload**
option set to true. Specify your configuration file using the **APP_CONFIG**
environment variable. For example, see the oc new-app
command. You can use the oc set env
command to update environment variables of existing objects.
You should only use this option while developing or debugging; it is not recommended to turn this on in your production environment. |
To change your source code in a running pod, use the oc rsh
command to enter the container:
$ oc rsh <pod_id>
After you enter into the running container, your current directory is set to /opt/app-root/src, where the source code is located.