317 lines
10 KiB
Groff
317 lines
10 KiB
Groff
.TH Python 3.6 container image
|
|
.PP
|
|
This container image includes Python 3.6 as a S2I
|
|
\[la]https://github.com/openshift/source-to-image\[ra] base image for your Python 3.6 applications.
|
|
Users can choose between RHEL and CentOS based builder images.
|
|
The RHEL image is available in the Red Hat Container Catalog
|
|
\[la]https://access.redhat.com/containers/#/registry.access.redhat.com/rhscl/python-36-rhel7\[ra]
|
|
as registry.access.redhat.com/rhscl/python\-36\-rhel7.
|
|
The CentOS image is then available on Docker Hub
|
|
\[la]https://hub.docker.com/r/centos/python-36-centos7/\[ra]
|
|
as centos/python\-36\-centos7.
|
|
The resulting image can be run using Docker
|
|
\[la]http://docker.io\[ra]\&.
|
|
|
|
.SH Description
|
|
.PP
|
|
Python 3.6 available as container is a base platform for
|
|
building and running various Python 3.6 applications and frameworks.
|
|
Python is an easy to learn, powerful programming language. It has efficient high\-level
|
|
data structures and a simple but effective approach to object\-oriented programming.
|
|
Python's elegant syntax and dynamic typing, together with its interpreted nature,
|
|
make it an ideal language for scripting and rapid application development in many areas
|
|
on most platforms.
|
|
|
|
.PP
|
|
This container image includes an npm utility, so users can use it to install JavaScript
|
|
modules for their web applications. There is no guarantee for any specific npm or nodejs
|
|
version, that is included in the image; those versions can be changed anytime and
|
|
the nodejs itself is included just to make the npm work.
|
|
|
|
.SH Usage
|
|
.PP
|
|
To build a simple python\-sample\-app
|
|
\[la]https://github.com/sclorg/s2i-python-container/tree/master/3.6/test/setup-test-app\[ra] application
|
|
using standalone S2I
|
|
\[la]https://github.com/openshift/source-to-image\[ra] and then run the
|
|
resulting image with Docker
|
|
\[la]http://docker.io\[ra] execute:
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBFor RHEL based image\fP
|
|
.PP
|
|
.RS
|
|
|
|
.nf
|
|
$ s2i build https://github.com/sclorg/s2i\-python\-container.git \-\-context\-dir=3.6/test/setup\-test\-app/ rhscl/python\-36\-rhel7 python\-sample\-app
|
|
$ docker run \-p 8080:8080 python\-sample\-app
|
|
|
|
.fi
|
|
.RE
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBFor CentOS based image\fP
|
|
.PP
|
|
.RS
|
|
|
|
.nf
|
|
$ s2i build https://github.com/sclorg/s2i\-python\-container.git \-\-context\-dir=3.6/test/setup\-test\-app/ centos/python\-36\-centos7 python\-sample\-app
|
|
$ docker run \-p 8080:8080 python\-sample\-app
|
|
|
|
.fi
|
|
.RE
|
|
|
|
.PP
|
|
\fBAccessing the application:\fP
|
|
|
|
.PP
|
|
.RS
|
|
|
|
.nf
|
|
$ curl 127.0.0.1:8080
|
|
|
|
.fi
|
|
.RE
|
|
|
|
.SH Environment variables
|
|
.PP
|
|
To set these environment variables, you can place them as a key value pair into a \fB\fC\&.s2i/environment\fR
|
|
file inside your source code repository.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBAPP\_SCRIPT\fP
|
|
.PP
|
|
Used to run the application from a script file.
|
|
This should be a path to a script file (defaults to \fB\fCapp.sh\fR unless set to null) that will be
|
|
run to start the application.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBAPP\_FILE\fP
|
|
.PP
|
|
Used to run the application from a Python script.
|
|
This should be a path to a Python file (defaults to \fB\fCapp.py\fR unless set to null) that will be
|
|
passed to the Python interpreter to start the application.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBAPP\_MODULE\fP
|
|
.PP
|
|
Used to run the application with Gunicorn, as documented
|
|
here
|
|
\[la]http://docs.gunicorn.org/en/latest/run.html#gunicorn\[ra]\&.
|
|
This variable specifies a WSGI callable with the pattern
|
|
\fB\fCMODULE\_NAME:VARIABLE\_NAME\fR, where \fB\fCMODULE\_NAME\fR is the full dotted path
|
|
of a module, and \fB\fCVARIABLE\_NAME\fR refers to a WSGI callable inside the
|
|
specified module.
|
|
Gunicorn will look for a WSGI callable named \fB\fCapplication\fR if not specified.
|
|
|
|
.PP
|
|
If \fB\fCAPP\_MODULE\fR is not provided, the \fB\fCrun\fR script will look for a \fB\fCwsgi.py\fR
|
|
file in your project and use it if it exists.
|
|
|
|
.PP
|
|
If using \fB\fCsetup.py\fR for installing the application, the \fB\fCMODULE\_NAME\fR part
|
|
can be read from there. For an example, see
|
|
setup\-test\-app
|
|
\[la]https://github.com/sclorg/s2i-python-container/tree/master/3.6/test/setup-test-app\[ra]\&.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBAPP\_HOME\fP
|
|
.PP
|
|
This variable can be used to specify a sub\-directory in which the application to be run is contained.
|
|
The directory pointed to by this variable needs to contain \fB\fCwsgi.py\fR (for Gunicorn) or \fB\fCmanage.py\fR (for Django).
|
|
|
|
.PP
|
|
If \fB\fCAPP\_HOME\fR is not provided, the \fB\fCassemble\fR and \fB\fCrun\fR scripts will use the application's root
|
|
directory.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBAPP\_CONFIG\fP
|
|
.PP
|
|
Path to a valid Python file with a
|
|
Gunicorn configuration
|
|
\[la]http://docs.gunicorn.org/en/latest/configure.html#configuration-file\[ra] file.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBDISABLE\_MIGRATE\fP
|
|
.PP
|
|
Set this variable to a non\-empty value to inhibit the execution of 'manage.py migrate'
|
|
when the produced image is run. This only affects Django projects. See
|
|
"Handling Database Migrations" section of Django blogpost on OpenShift blog
|
|
\[la]https://blog.openshift.com/migrating-django-applications-openshift-3/\[ra] on suggestions
|
|
how/when to run DB migrations in OpenShift environment. Most importantly,
|
|
note that running DB migrations from two or more pods might corrupt your database.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBDISABLE\_COLLECTSTATIC\fP
|
|
.PP
|
|
Set this variable to a non\-empty value to inhibit the execution of
|
|
'manage.py collectstatic' during the build. This only affects Django projects.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBDISABLE\_SETUP\_PY\_PROCESSING\fP
|
|
.PP
|
|
Set this to a non\-empty value to skip processing of setup.py script if you
|
|
use \fB\fC\-e .\fR in requirements.txt to trigger its processing or you don't want
|
|
your application to be installed into site\-packages directory.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBENABLE\_PIPENV\fP
|
|
.PP
|
|
Set this variable to use Pipenv
|
|
\[la]https://github.com/kennethreitz/pipenv\[ra],
|
|
the higher\-level Python packaging tool, to manage dependencies of the application.
|
|
This should be used only if your project contains properly formated Pipfile
|
|
and Pipfile.lock.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBPIP\_INDEX\_URL\fP
|
|
.PP
|
|
Set this variable to use a custom index URL or mirror to download required packages
|
|
during build process. This only affects packages listed in requirements.txt.
|
|
Pipenv ignores this variable.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBUPGRADE\_PIP\_TO\_LATEST\fP
|
|
.PP
|
|
Set this variable to a non\-empty value to have the 'pip' program and related
|
|
python packages (setuptools and wheel) be upgraded to the most recent version
|
|
before any Python packages are installed. If not set it will use whatever
|
|
the default version is included by the platform for the Python version being used.
|
|
.IP \(bu 2
|
|
|
|
.PP
|
|
\fBWEB\_CONCURRENCY\fP
|
|
.PP
|
|
Set this to change the default setting for the number of
|
|
workers
|
|
\[la]http://docs.gunicorn.org/en/stable/settings.html#workers\[ra]\&. By
|
|
default, this is set to the number of available cores times 2, capped
|
|
at 12.
|
|
|
|
.SH Source repository layout
|
|
.PP
|
|
You do not need to change anything in your existing Python project's repository.
|
|
However, if these files exist they will affect the behavior of the build process:
|
|
.IP \(bu 2
|
|
\fBrequirements.txt\fP
|
|
|
|
.PP
|
|
List of dependencies to be installed with \fB\fCpip\fR\&. The format is documented
|
|
here
|
|
\[la]https://pip.pypa.io/en/latest/user_guide.html#requirements-files\[ra]\&.
|
|
.IP \(bu 2
|
|
\fBPipfile\fP
|
|
|
|
.PP
|
|
The replacement for requirements.txt, project is currently under active
|
|
design and development, as documented here
|
|
\[la]https://github.com/pypa/pipfile\[ra]\&.
|
|
Set \fB\fCENABLE\_PIPENV\fR environment variable to true in order to process this file.
|
|
.IP \(bu 2
|
|
\fBsetup.py\fP
|
|
|
|
.PP
|
|
Configures various aspects of the project, including installation of
|
|
dependencies, as documented
|
|
here
|
|
\[la]https://packaging.python.org/en/latest/distributing.html#setup-py\[ra]\&.
|
|
For most projects, it is sufficient to simply use \fB\fCrequirements.txt\fR or
|
|
\fB\fCPipfile\fR\&. Set \fB\fCDISABLE\_SETUP\_PY\_PROCESSING\fR environment variable to true
|
|
in order to skip processing of this file.
|
|
|
|
.SH Run strategies
|
|
.PP
|
|
The container image produced by s2i\-python executes your project in one of the
|
|
following ways, in precedence order:
|
|
.IP \(bu 2
|
|
\fBGunicorn\fP
|
|
|
|
.PP
|
|
The Gunicorn WSGI HTTP server is used to serve your application in the case that it
|
|
is installed. It can be installed by listing it either in the \fB\fCrequirements.txt\fR
|
|
file or in the \fB\fCinstall\_requires\fR section of the \fB\fCsetup.py\fR file.
|
|
|
|
.PP
|
|
If a file named \fB\fCwsgi.py\fR is present in your repository, it will be used as
|
|
the entry point to your application. This can be overridden with the
|
|
environment variable \fB\fCAPP\_MODULE\fR\&.
|
|
This file is present in Django projects by default.
|
|
|
|
.PP
|
|
If you have both Django and Gunicorn in your requirements, your Django project
|
|
will automatically be served using Gunicorn.
|
|
.IP \(bu 2
|
|
\fBDjango development server\fP
|
|
|
|
.PP
|
|
If you have Django in your requirements but don't have Gunicorn, then your
|
|
application will be served using Django's development web server. However, this is not
|
|
recommended for production environments.
|
|
.IP \(bu 2
|
|
\fBPython script\fP
|
|
|
|
.PP
|
|
This would be used where you provide a Python code file for running you
|
|
application. It will be used in the case where you specify a path to a
|
|
Python script via the \fB\fCAPP\_FILE\fR environment variable, defaulting to a
|
|
file named \fB\fCapp.py\fR if it exists. The script is passed to a regular
|
|
Python interpreter to launch your application.
|
|
.IP \(bu 2
|
|
\fBApplication script file\fP
|
|
|
|
.PP
|
|
This is the most general way of executing your application. It will be
|
|
used in the case where you specify a path to an executable script file
|
|
via the \fB\fCAPP\_SCRIPT\fR environment variable, defaulting to a file named
|
|
\fB\fCapp.sh\fR if it exists. The script is executed directly to launch your
|
|
application.
|
|
|
|
.SH Hot deploy
|
|
.PP
|
|
If you are using Django, hot deploy will work out of the box.
|
|
|
|
.PP
|
|
To enable hot deploy while using Gunicorn, make sure you have a Gunicorn
|
|
configuration file inside your repository with the
|
|
\fB\fCreload\fR
|
|
\[la]https://gunicorn-docs.readthedocs.org/en/latest/settings.html#reload\[ra]
|
|
option set to \fB\fCtrue\fR\&. Make sure to specify your config via the \fB\fCAPP\_CONFIG\fR
|
|
environment variable.
|
|
|
|
.PP
|
|
To change your source code in running container, use Docker's
|
|
exec
|
|
\[la]https://docs.docker.com/reference/commandline/exec/\[ra] command:
|
|
|
|
.PP
|
|
.RS
|
|
|
|
.nf
|
|
docker exec \-it <CONTAINER\_ID> /bin/bash
|
|
|
|
.fi
|
|
.RE
|
|
|
|
.PP
|
|
After you enter into the running container, your current directory is set
|
|
to \fB\fC/opt/app\-root/src\fR, where the source code is located.
|
|
|
|
.SH See also
|
|
.PP
|
|
Dockerfile and other sources are available on
|
|
\[la]https://github.com/sclorg/s2i-python-container\[ra]\&.
|
|
In that repository you also can find another versions of Python environment Dockerfiles.
|
|
Dockerfile for CentOS is called Dockerfile, Dockerfile for RHEL is called Dockerfile.rhel7.
|