Skip to content

Commit

Permalink
I had to remove reload functionality as configuration option as there…
Browse files Browse the repository at this point in the history
… is a bug with Gunicorn running Uvicorn workers.
  • Loading branch information
max-pfeiffer committed Nov 28, 2021
1 parent fb9d690 commit 7459dc4
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 32 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Docker Hub: [pfeiffermax/uvicorn-gunicorn-poetry](https://hub.docker.com/r/pfeif

GitHub Repository: [https://github.com/max-pfeiffer/uvicorn-gunicorn-poetry](https://github.com/max-pfeiffer/uvicorn-gunicorn-poetry)

**IMPORTANT:** Please be aware of a bug with Gunicorn: [worker reload with Uvicorn workers is currently broken.](https://github.com/benoitc/gunicorn/issues/2339)
So the latest version of that image does not provide that functionality any more.

## Usage
It just provides a platform that you can use to build upon your own multistage builds. So it consequently does not contain an
application itself. Please check out the [example application](https://github.com/max-pfeiffer/uvicorn-gunicorn-poetry/tree/master/examples/fast_api_multistage_build)
Expand Down Expand Up @@ -83,11 +86,6 @@ if you would like to do a deep dive. Following environment variables are support

**default:** `-`

### [Debugging](https://docs.gunicorn.org/en/stable/settings.html#debugging)
`RELOAD` : Restart workers when code changes.

**default:** `False`

### [Worker processes](https://docs.gunicorn.org/en/stable/settings.html#worker-processes)
`WORKERS` : The number of worker processes for handling requests. By default this is set to one
worker as this image is meant to be used on a production grade Kubernetes environment. There you
Expand Down
10 changes: 7 additions & 3 deletions build/gunicorn_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"loglevel": "info",
"accesslog": "-",
"errorlog": "-",
"reload": False,
# "reload": False,
"worker_tmp_dir": "/dev/shm",
}

Expand All @@ -22,7 +22,11 @@

# Debugging
# https://docs.gunicorn.org/en/stable/settings.html#debugging
reload = bool(os.getenv("RELOAD", DEFAULT_GUNICORN_CONFIG["reload"]))

# There is a bug with Gunicorn reload with uvicorn workers, so this features is
# not available any more until this bug became fixed
# see: https://github.com/benoitc/gunicorn/issues/2339
# reload = bool(os.getenv("RELOAD", DEFAULT_GUNICORN_CONFIG["reload"]))

# Worker processes
# https://docs.gunicorn.org/en/stable/settings.html#worker-processes
Expand Down Expand Up @@ -53,7 +57,7 @@
"loglevel": loglevel,
"errorlog": errorlog,
"accesslog": accesslog,
"reload": reload,
# "reload": reload,
"worker_tmp_dir": worker_tmp_dir,
}
print(json.dumps(log_data))
4 changes: 2 additions & 2 deletions examples/fast_api_multistage_build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG BASE_IMAGE_NAME_AND_TAG=pfeiffermax/uvicorn-gunicorn-poetry:python3.9.8-slim-bullseye-2021-11-15
ARG BASE_IMAGE_NAME_AND_TAG=pfeiffermax/uvicorn-gunicorn-poetry:1.0.0-python3.9.8-slim-bullseye
FROM ${BASE_IMAGE_NAME_AND_TAG} as base-image

WORKDIR /application_root
Expand Down Expand Up @@ -40,7 +40,7 @@ CMD ["--cov=app", "--cov-report=xml:/test_coverage_reports/unit_tests_coverage.x

FROM base-image as development-image
ENV WORKERS="1" \
RELOAD="True" \
# RELOAD="True" \
LOG_LEVEL="debug"

COPY --from=base-image $VIRTUAL_ENVIRONMENT_PATH $VIRTUAL_ENVIRONMENT_PATH
Expand Down
41 changes: 21 additions & 20 deletions examples/fast_api_multistage_build/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions examples/fast_api_multistage_build/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ testpaths = [
"tests",
]

# https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-via-a-file
[tool.black]
line-length = 80
target-version = ['py39']

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ black = "21.10b0"

# https://docs.pytest.org/en/latest/reference/customize.html
[tool.pytest.ini_options]
addopts = "--ignore=tests/functionality/test_worker_reload.py"
testpaths = [
"tests",
]

# https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-via-a-file
[tool.black]
line-length = 80
target-version = ['py39']

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion tests/configuration/test_default_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def verify_container(container: UvicornGunicornPoetryContainerConfig) -> None:
assert config_data["loglevel"] == DEFAULT_GUNICORN_CONFIG["loglevel"]
assert config_data["accesslog"] == DEFAULT_GUNICORN_CONFIG["accesslog"]
assert config_data["errorlog"] == DEFAULT_GUNICORN_CONFIG["errorlog"]
assert config_data["reload"] == DEFAULT_GUNICORN_CONFIG["reload"]
# assert config_data["reload"] == DEFAULT_GUNICORN_CONFIG["reload"]
assert (
config_data["worker_tmp_dir"]
== DEFAULT_GUNICORN_CONFIG["worker_tmp_dir"]
Expand Down
2 changes: 1 addition & 1 deletion tests/configuration/test_development_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def verify_container(container: UvicornGunicornPoetryContainerConfig) -> None:
assert config_data["loglevel"] == DEVELOPMENT_GUNICORN_CONFIG["loglevel"]
assert config_data["accesslog"] == DEVELOPMENT_GUNICORN_CONFIG["accesslog"]
assert config_data["errorlog"] == DEVELOPMENT_GUNICORN_CONFIG["errorlog"]
assert config_data["reload"] == DEVELOPMENT_GUNICORN_CONFIG["reload"]
# assert config_data["reload"] == DEVELOPMENT_GUNICORN_CONFIG["reload"]
assert (
config_data["worker_tmp_dir"]
== DEVELOPMENT_GUNICORN_CONFIG["worker_tmp_dir"]
Expand Down

0 comments on commit 7459dc4

Please sign in to comment.