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 4, 2024
1 parent cea86df commit 42c95eb
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 2 deletions.
57 changes: 57 additions & 0 deletions examples/gunicorn-using-configfile-test-app/.gitignore
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/
4 changes: 4 additions & 0 deletions examples/gunicorn-using-configfile-test-app/app.py
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!"]
6 changes: 6 additions & 0 deletions examples/gunicorn-using-configfile-test-app/gunicorn.conf.py
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-using-configfile-test-app
dest: test/gunicorn-using-configfile-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-using-configfile-test-app
dest: test/gunicorn-using-configfile-test-app

- src: ../../examples/locale-test-app
dest: test/locale-test-app

Expand Down
9 changes: 8 additions & 1 deletion src/s2i/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,15 @@ fi

if is_gunicorn_installed; then
setup_py=$(find "$HOME" -maxdepth 2 -type f -name 'setup.py' -print -quit)
# Look for gunicorn>=20.1.0 to utilize gunicorn.conf.py
rpmdev-vercmp $(rpm -q --queryformat '%{VERSION}' python3-gunicorn) "20.1.0"
vercmp_result=$?
grep "wsgi_app" gunicorn.conf.py
grep_result=$?
if [[ $ver -eq 11 || $ver -eq 0 ]] && [[ -f "gunicorn.conf.py" ]] && [[ $grep_result -eq 0 ]]; then
echo "Using gunicorn.conf.py"
# Look for wsgi module in the current directory
if [[ -z "$APP_MODULE" && -f "./wsgi.py" ]]; then
elif [[ -z "$APP_MODULE" && -f "./wsgi.py" ]]; then
APP_MODULE=wsgi
elif [[ -z "$APP_MODULE" && -f "$setup_py" ]]; then
APP_MODULE="$(python "$setup_py" --name)"
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-using-configfile,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 %}
Expand Down

0 comments on commit 42c95eb

Please sign in to comment.