-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
1,313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# This image provides a Python 3.5 environment you can use to run your Python | ||
# applications. | ||
FROM centos/s2i-base-centos7 | ||
|
||
EXPOSE 8080 | ||
|
||
ENV PYTHON_VERSION=3.5 \ | ||
PATH=$HOME/.local/bin/:$PATH \ | ||
PYTHONUNBUFFERED=1 \ | ||
PYTHONIOENCODING=UTF-8 \ | ||
LC_ALL=en_US.UTF-8 \ | ||
LANG=en_US.UTF-8 \ | ||
PIP_NO_CACHE_DIR=off | ||
|
||
ENV SUMMARY="Platform for building and running Python $PYTHON_VERSION applications" \ | ||
DESCRIPTION="Python $PYTHON_VERSION available as docker container is a base platform for \ | ||
building and running various Python $PYTHON_VERSION 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." | ||
|
||
LABEL summary="$SUMMARY" \ | ||
description="$DESCRIPTION" \ | ||
io.k8s.description="$DESCRIPTION" \ | ||
io.k8s.display-name="Python 3.5" \ | ||
io.openshift.expose-services="8080:http" \ | ||
io.openshift.tags="builder,python,python35,rh-python35" \ | ||
com.redhat.component="python35-docker" \ | ||
name="centos/python-35-centos7" \ | ||
version="3.5" \ | ||
release="1" \ | ||
maintainer="SoftwareCollections.org <sclorg@redhat.com>" | ||
|
||
RUN yum install -y centos-release-scl-rh && \ | ||
yum-config-manager --enable centos-sclo-rh-testing && \ | ||
INSTALL_PKGS="rh-python35 rh-python35-python-devel rh-python35-python-setuptools rh-python35-python-pip \ | ||
nss_wrapper httpd24 httpd24-httpd-devel httpd24-mod_ssl httpd24-mod_auth_kerb httpd24-mod_ldap \ | ||
httpd24-mod_session atlas-devel gcc-gfortran libffi-devel libtool-ltdl" && \ | ||
yum install -y --setopt=tsflags=nodocs --enablerepo=centosplus $INSTALL_PKGS && \ | ||
rpm -V $INSTALL_PKGS && \ | ||
# Remove centos-logos (httpd dependency, ~20MB of graphics) to keep image | ||
# size smaller. | ||
rpm -e --nodeps centos-logos && \ | ||
yum clean all -y | ||
|
||
# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH. | ||
COPY ./s2i/bin/ $STI_SCRIPTS_PATH | ||
|
||
# Copy extra files to the image. | ||
COPY ./root/ / | ||
|
||
# Create a Python virtual environment for use by any application to avoid | ||
# potential conflicts with Python packages preinstalled in the main Python | ||
# installation. | ||
RUN source scl_source enable rh-python35 && \ | ||
virtualenv /opt/app-root | ||
|
||
# In order to drop the root user, we have to make some directories world | ||
# writable as OpenShift default security model is to run the container under | ||
# random UID. | ||
RUN chown -R 1001:0 /opt/app-root && chmod -R og+rwx /opt/app-root | ||
|
||
USER 1001 | ||
|
||
# Set the default CMD to print the usage of the language image. | ||
CMD $STI_SCRIPTS_PATH/usage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# This image provides a Python 3.5 environment you can use to run your Python | ||
# applications. | ||
FROM rhscl/s2i-base-rhel7 | ||
|
||
EXPOSE 8080 | ||
|
||
ENV PYTHON_VERSION=3.5 \ | ||
PATH=$HOME/.local/bin/:$PATH \ | ||
PYTHONUNBUFFERED=1 \ | ||
PYTHONIOENCODING=UTF-8 \ | ||
LC_ALL=en_US.UTF-8 \ | ||
LANG=en_US.UTF-8 \ | ||
PIP_NO_CACHE_DIR=off | ||
|
||
ENV SUMMARY="Platform for building and running Python $PYTHON_VERSION applications" \ | ||
DESCRIPTION="Python $PYTHON_VERSION available as docker container is a base platform for \ | ||
building and running various Python $PYTHON_VERSION 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." | ||
|
||
LABEL summary="$SUMMARY" \ | ||
description="$DESCRIPTION" \ | ||
io.k8s.description="$DESCRIPTION" \ | ||
io.k8s.display-name="Python 3.5" \ | ||
io.openshift.expose-services="8080:http" \ | ||
io.openshift.tags="builder,python,python35,rh-python35" \ | ||
com.redhat.component="rh-python35-docker" \ | ||
name="rhscl/python-35-rhel7" \ | ||
version="3.5" \ | ||
release="1" | ||
|
||
# We need to call 2 (!) yum commands before being able to enable repositories properly | ||
# This is a workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1479388 | ||
RUN yum repolist > /dev/null && \ | ||
yum install -y yum-utils && \ | ||
yum-config-manager --disable \* &> /dev/null && \ | ||
yum-config-manager --enable rhel-server-rhscl-7-rpms && \ | ||
yum-config-manager --enable rhel-7-server-rpms && \ | ||
yum-config-manager --enable rhel-7-server-optional-rpms && \ | ||
INSTALL_PKGS="rh-python35 rh-python35-python-devel rh-python35-python-setuptools rh-python35-python-pip \ | ||
nss_wrapper httpd24 httpd24-httpd-devel httpd24-mod_ssl httpd24-mod_auth_kerb httpd24-mod_ldap httpd24-mod_session \ | ||
atlas-devel gcc-gfortran libffi-devel libtool-ltdl" && \ | ||
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ | ||
rpm -V $INSTALL_PKGS && \ | ||
# Remove redhat-logos (httpd dependency) to keep image size smaller. | ||
rpm -e --nodeps redhat-logos && \ | ||
yum clean all -y | ||
|
||
# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH. | ||
COPY ./s2i/bin/ $STI_SCRIPTS_PATH | ||
|
||
# Copy extra files to the image. | ||
COPY ./root/ / | ||
|
||
# Create a Python virtual environment for use by any application to avoid | ||
# potential conflicts with Python packages preinstalled in the main Python | ||
# installation. | ||
RUN source scl_source enable rh-python35 && \ | ||
virtualenv /opt/app-root | ||
|
||
# In order to drop the root user, we have to make some directories world | ||
# writable as OpenShift default security model is to run the container under | ||
# random UID. | ||
RUN chown -R 1001:0 /opt/app-root && chmod -R og+rwx /opt/app-root | ||
|
||
USER 1001 | ||
|
||
# Set the default CMD to print the usage of the language image. | ||
CMD $STI_SCRIPTS_PATH/usage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
Python 3.5 Docker image | ||
=================== | ||
|
||
This container image includes Python 3.5 as a [S2I](https://github.com/openshift/source-to-image) base image for your Python 3.5 applications. | ||
Users can choose between RHEL and CentOS based builder images. | ||
The RHEL image is available in the [Red Hat Container Catalog](https://access.redhat.com/containers/#/registry.access.redhat.com/rhscl/python-35-rhel7) | ||
as registry.access.redhat.com/rhscl/python-35-rhel7. | ||
The CentOS image is then available on [Docker Hub](https://hub.docker.com/r/centos/python-35-centos7/) | ||
as centos/python-35-centos7. | ||
The resulting image can be run using [Docker](http://docker.io). | ||
|
||
Description | ||
----------- | ||
|
||
Python 3.5 available as docker container is a base platform for | ||
building and running various Python 3.5 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. | ||
|
||
Usage | ||
--------------------- | ||
To build a simple [python-sample-app](https://github.com/sclorg/s2i-python-container/tree/master/3.5/test/setup-test-app) application | ||
using standalone [S2I](https://github.com/openshift/source-to-image) and then run the | ||
resulting image with [Docker](http://docker.io) execute: | ||
|
||
* **For RHEL based image** | ||
``` | ||
$ s2i build https://github.com/sclorg/s2i-python-container.git --context-dir=3.5/test/setup-test-app/ rhscl/python-35-rhel7 python-sample-app | ||
$ docker run -p 8080:8080 python-sample-app | ||
``` | ||
|
||
* **For CentOS based image** | ||
``` | ||
$ s2i build https://github.com/sclorg/s2i-python-container.git --context-dir=3.5/test/setup-test-app/ centos/python-35-centos7 python-sample-app | ||
$ docker run -p 8080:8080 python-sample-app | ||
``` | ||
|
||
**Accessing the application:** | ||
``` | ||
$ curl 127.0.0.1:8080 | ||
``` | ||
|
||
Environment variables | ||
--------------------- | ||
|
||
To set these environment variables, you can place them as a key value pair into a `.s2i/environment` | ||
file inside your source code repository. | ||
|
||
* **APP_SCRIPT** | ||
|
||
Used to run the application from a script file. | ||
This should be a path to a script file (defaults to `app.sh` unless set to null) that will be | ||
run to start the application. | ||
|
||
* **APP_FILE** | ||
|
||
Used to run the application from a Python script. | ||
This should be a path to a Python file (defaults to `app.py` unless set to null) that will be | ||
passed to the Python interpreter to start the application. | ||
|
||
* **APP_MODULE** | ||
|
||
Used to run the application with Gunicorn, as documented | ||
[here](http://docs.gunicorn.org/en/latest/run.html#gunicorn). | ||
This variable specifies a WSGI callable with the pattern | ||
`MODULE_NAME:VARIABLE_NAME`, where `MODULE_NAME` is the full dotted path | ||
of a module, and `VARIABLE_NAME` refers to a WSGI callable inside the | ||
specified module. | ||
Gunicorn will look for a WSGI callable named `application` if not specified. | ||
|
||
If `APP_MODULE` is not provided, the `run` script will look for a `wsgi.py` | ||
file in your project and use it if it exists. | ||
|
||
If using `setup.py` for installing the application, the `MODULE_NAME` part | ||
can be read from there. For an example, see | ||
[setup-test-app](https://github.com/sclorg/s2i-python-container/tree/master/3.5/test/setup-test-app). | ||
|
||
* **APP_HOME** | ||
|
||
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 `wsgi.py` (for Gunicorn) or `manage.py` (for Django). | ||
|
||
If `APP_HOME` is not provided, the `assemble` and `run` scripts will use the application's root | ||
directory. | ||
|
||
* **APP_CONFIG** | ||
|
||
Path to a valid Python file with a | ||
[Gunicorn configuration](http://docs.gunicorn.org/en/latest/configure.html#configuration-file) file. | ||
|
||
* **DISABLE_COLLECTSTATIC** | ||
|
||
Set this variable to a non-empty value to inhibit the execution of | ||
'manage.py collectstatic' during the build. This only affects Django projects. | ||
|
||
* **DISABLE_MIGRATE** | ||
|
||
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. | ||
|
||
* **PIP_INDEX_URL** | ||
|
||
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. | ||
|
||
* **UPGRADE_PIP_TO_LATEST** | ||
|
||
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. | ||
|
||
* **WEB_CONCURRENCY** | ||
|
||
Set this to change the default setting for the number of | ||
[workers](http://docs.gunicorn.org/en/stable/settings.html#workers). By | ||
default, this is set to the number of available cores times 2. | ||
|
||
Source repository layout | ||
------------------------ | ||
|
||
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: | ||
|
||
* **requirements.txt** | ||
|
||
List of dependencies to be installed with `pip`. The format is documented | ||
[here](https://pip.pypa.io/en/latest/user_guide.html#requirements-files). | ||
|
||
|
||
* **setup.py** | ||
|
||
Configures various aspects of the project, including installation of | ||
dependencies, as documented | ||
[here](https://packaging.python.org/en/latest/distributing.html#setup-py). | ||
For most projects, it is sufficient to simply use `requirements.txt`, if this | ||
file is present `setup.py` is not processed by default, please use `-e .` to | ||
trigger its processing from the requirements.txt file. | ||
|
||
|
||
Run strategies | ||
-------------- | ||
|
||
The Docker image produced by s2i-python executes your project in one of the | ||
following ways, in precedence order: | ||
|
||
* **Gunicorn** | ||
|
||
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 `requirements.txt` | ||
file or in the `install_requires` section of the `setup.py` file. | ||
|
||
If a file named `wsgi.py` is present in your repository, it will be used as | ||
the entry point to your application. This can be overridden with the | ||
environment variable `APP_MODULE`. | ||
This file is present in Django projects by default. | ||
|
||
If you have both Django and Gunicorn in your requirements, your Django project | ||
will automatically be served using Gunicorn. | ||
|
||
* **Django development server** | ||
|
||
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. | ||
|
||
* **Python script** | ||
|
||
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 `APP_FILE` environment variable, defaulting to a | ||
file named `app.py` if it exists. The script is passed to a regular | ||
Python interpreter to launch your application. | ||
|
||
* **Application script file** | ||
|
||
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 `APP_SCRIPT` environment variable, defaulting to a file named | ||
`app.sh` if it exists. The script is executed directly to launch your | ||
application. | ||
|
||
Hot deploy | ||
--------------------- | ||
|
||
If you are using Django, hot deploy will work out of the box. | ||
|
||
To enable hot deploy while using Gunicorn, make sure you have a Gunicorn | ||
configuration file inside your repository with the | ||
[`reload`](https://gunicorn-docs.readthedocs.org/en/latest/settings.html#reload) | ||
option set to `true`. Make sure to specify your config via the `APP_CONFIG` | ||
environment variable. | ||
|
||
To change your source code in running container, use Docker's | ||
[exec](https://docs.docker.com/reference/commandline/exec/) command: | ||
|
||
``` | ||
docker exec -it <CONTAINER_ID> /bin/bash | ||
``` | ||
|
||
After you enter into the running container, your current directory is set | ||
to `/opt/app-root/src`, where the source code is located. | ||
|
||
|
||
See also | ||
-------- | ||
Dockerfile and other sources are available on https://github.com/sclorg/s2i-python-container. | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This is for the purpose of building this container | ||
# on the centos container pipeline. | ||
job-id: python-35-centos7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Set current user in nss_wrapper | ||
USER_ID=$(id -u) | ||
GROUP_ID=$(id -g) | ||
|
||
if [ x"$USER_ID" != x"0" -a x"$USER_ID" != x"1001" ]; then | ||
|
||
NSS_WRAPPER_PASSWD=/opt/app-root/etc/passwd | ||
NSS_WRAPPER_GROUP=/etc/group | ||
|
||
cat /etc/passwd | sed -e 's/^default:/builder:/' > $NSS_WRAPPER_PASSWD | ||
|
||
echo "default:x:${USER_ID}:${GROUP_ID}:Default Application User:${HOME}:/sbin/nologin" >> $NSS_WRAPPER_PASSWD | ||
|
||
export NSS_WRAPPER_PASSWD | ||
export NSS_WRAPPER_GROUP | ||
|
||
LD_PRELOAD=libnss_wrapper.so | ||
export LD_PRELOAD | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# IMPORTANT: Do not add more content to this file unless you know what you are | ||
# doing. This file is sourced everytime the shell session is opened. | ||
# This will make scl collection binaries work out of box. | ||
unset BASH_ENV PROMPT_COMMAND ENV | ||
source scl_source enable httpd24 rh-nodejs6 rh-python35 | ||
source /opt/app-root/bin/activate |
Oops, something went wrong.