Skip to content

Commit

Permalink
Allow the usage of gunicorn.conf.py config file in gunicorn applications
Browse files Browse the repository at this point in the history
Fixes: sclorg#599
  • Loading branch information
hrnciar committed Jun 27, 2024
1 parent cea86df commit b663765
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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/
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

def application(environ, start_response):
start_response('200 OK', [('Content-Type','text/plain')])
return [b"Hello from gunicorn WSGI application!"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import multiprocessing

bind = "0.0.0.0:8085"
workers = multiprocessing.cpu_count() * 2 + 1

wsgi_app = "app:application"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gunicorn>=20.1.0; python_version >= '3.5'
3 changes: 3 additions & 0 deletions manifest-minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions src/s2i/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -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 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}"
Expand Down
2 changes: 1 addition & 1 deletion test/run
Original file line number Diff line number Diff line change
Expand Up @@ -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,gunicorn-python-configfile-different-port{% 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 %}
Expand Down

0 comments on commit b663765

Please sign in to comment.