diff --git a/examples/gunicorn-python-configfile-different-port-test-app/.gitignore b/examples/gunicorn-python-configfile-different-port-test-app/.gitignore new file mode 100644 index 00000000..ba746605 --- /dev/null +++ b/examples/gunicorn-python-configfile-different-port-test-app/.gitignore @@ -0,0 +1,57 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ diff --git a/examples/gunicorn-python-configfile-different-port-test-app/app.py b/examples/gunicorn-python-configfile-different-port-test-app/app.py new file mode 100644 index 00000000..09fee1b7 --- /dev/null +++ b/examples/gunicorn-python-configfile-different-port-test-app/app.py @@ -0,0 +1,4 @@ + +def application(environ, start_response): + start_response('200 OK', [('Content-Type','text/plain')]) + return [b"Hello from gunicorn WSGI application!"] diff --git a/examples/gunicorn-python-configfile-different-port-test-app/gunicorn.conf.py b/examples/gunicorn-python-configfile-different-port-test-app/gunicorn.conf.py new file mode 100644 index 00000000..bcb267f6 --- /dev/null +++ b/examples/gunicorn-python-configfile-different-port-test-app/gunicorn.conf.py @@ -0,0 +1,6 @@ +import multiprocessing + +bind = "0.0.0.0:8085" +workers = multiprocessing.cpu_count() * 2 + 1 + +wsgi_app = "app:application" diff --git a/examples/gunicorn-python-configfile-different-port-test-app/requirements.txt b/examples/gunicorn-python-configfile-different-port-test-app/requirements.txt new file mode 100644 index 00000000..b0d8963f --- /dev/null +++ b/examples/gunicorn-python-configfile-different-port-test-app/requirements.txt @@ -0,0 +1 @@ +gunicorn>=20.1.0; python_version >= '3.5' diff --git a/manifest-minimal.yml b/manifest-minimal.yml index 91c2e9fa..fd85adfa 100644 --- a/manifest-minimal.yml +++ b/manifest-minimal.yml @@ -142,6 +142,9 @@ SYMLINK_RULES: - src: ../../examples/gunicorn-config-different-port-test-app dest: test/gunicorn-config-different-port-test-app + - src: ../../examples/gunicorn-python-configfile-different-port-test-app + dest: test/gunicorn-python-configfile-different-port-test-app + - src: ../../examples/locale-test-app dest: test/locale-test-app diff --git a/manifest.yml b/manifest.yml index 9e71f094..4e3b1745 100644 --- a/manifest.yml +++ b/manifest.yml @@ -141,6 +141,9 @@ SYMLINK_RULES: - src: ../../examples/gunicorn-config-different-port-test-app dest: test/gunicorn-config-different-port-test-app + - src: ../../examples/gunicorn-python-configfile-different-port-test-app + dest: test/gunicorn-python-configfile-different-port-test-app + - src: ../../examples/locale-test-app dest: test/locale-test-app diff --git a/src/s2i/bin/run b/src/s2i/bin/run index 2a982cd1..c52bf893 100755 --- a/src/s2i/bin/run +++ b/src/s2i/bin/run @@ -49,6 +49,19 @@ function maybe_run_in_init_wrapper() { fi } +# Look for gunicorn>=20.1.0 to utilize gunicorn.conf.py +if is_gunicorn_installed && [[ -f "gunicorn.conf.py" ]]; then + ret=$(python -c 'import gunicorn +ver = gunicorn.version_info +print(0) if ver[0]>=21 or (ver[0] == 20 and ver[1] >= 1) else print(1)') + grep -q "wsgi_app" gunicorn.conf.py && grep_result=0 || grep_result=1 + if [[ $ret -eq 0 ]] && [[ $grep_result -eq 0 ]]; then + echo "---> Using gunicorn.conf.py" + echo "---> Serving application with gunicorn ..." + exec gunicorn + fi +fi + APP_HOME=$(readlink -f "${APP_HOME:-.}") # Change the working directory to APP_HOME PYTHONPATH="$(pwd)${PYTHONPATH:+:$PYTHONPATH}" diff --git a/test/run b/test/run index f0d50c67..d304bf30 100755 --- a/test/run +++ b/test/run @@ -6,7 +6,7 @@ # IMAGE_NAME specifies a name of the candidate image used for testing. # The image has to be available before this script is executed. # -declare -a COMMON_WEB_APPS=({gunicorn-config-different-port,gunicorn-different-port,django-different-port,standalone,setup,setup-requirements,django,numpy,app-home,locale,pipenv,pipenv-and-micropipenv-should-fail,app-module,pyuwsgi-pipenv{% if spec.version.startswith("3.") %},micropipenv,standalone-custom-pypi-index{% endif %}}-test-app) +declare -a COMMON_WEB_APPS=({gunicorn-config-different-port,gunicorn-different-port,gunicorn-python-configfile-different-port,django-different-port,standalone,setup,setup-requirements,django,numpy,app-home,locale,pipenv,pipenv-and-micropipenv-should-fail,app-module,pyuwsgi-pipenv{% if spec.version.startswith("3.") %},micropipenv,standalone-custom-pypi-index{% endif %}}-test-app) declare -a FULL_WEB_APPS=({setup-cfg,npm-virtualenv-uwsgi,mod-wsgi,pin-pipenv-version{% if spec.version.startswith("3.") %},micropipenv-requirements,poetry-src-layout{% endif %}}-test-app) declare -a MINIMAL_WEB_APPS=() {% if spec.minimal %}