-
-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate gunicorn as the dev/prod web server #1401
Closed
ricardogsilva
wants to merge
11
commits into
geopython:master
from
ricardogsilva:use-gunicorn-for-dev
Closed
Integrate gunicorn as the dev/prod web server #1401
ricardogsilva
wants to merge
11
commits into
geopython:master
from
ricardogsilva:use-gunicorn-for-dev
Conversation
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
ricardogsilva
changed the title
Use gunicorn as the dev server
Integrate gunicorn as the dev/prod web server
Nov 14, 2023
…d openapi files from the click context
5 tasks
As per RFC4, this Pull Request has been inactive for 90 days. In order to manage maintenance burden, it will be automatically closed in 7 days. |
As per RFC4, this Pull Request has been closed due to there being no activity for more than 90 days. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR refactors the pygeoapi codebase to use
gunicorn
as its main web server. Additionally, it also promotespygeoapi serve
as a robust method of running pygeoapi both in dev and prod - this is thanks to it now being backed by gunicorn.Both
flask
,django
andstarlette
support is included and theDockerfile
is also modified. The docs are also updated with usage instructions for dev and prod and also with samples for setting up custom flask/starlette/django applications. The api rules tests also become simpler, as there is no need to mess with global objects or env variables in order to get flask and starlette apps suitable for testing anymore.External changes are minimal. In a nutshell:
Basically, when the
--debug
flag is set,pygeoapi serve
will configure gunicorn to:DEBUG
as its log levelWhen the
--debug
flag is not set,pygeoapi serve
will still run with gunicorn but it won't turn on any of the previously mentioned capabilitiesThis PR does not change the pygeoapi business logic in any way, nor does it change its web interface - or at least it should not, if you find that it does, then it is a bug in the PR 😅
The refactoring done to each web framework support in pygeoapi is mostly about not using global variables for initialization of the pygeoapi config and API, and wrapping the creation of each framework's WSGI (or ASGI) application inside a factory function. This pattern works nicely with gunicorn and it also has a nice side-effect of reducing the number of things that happen implicitly on import time, making the codebase more predictable. Also note that, when running the starlette application, this PR uses gunicorn's uvicorn worker.
Additionally, retrieving the location of pygeoapi's configuration file is now strictly done in the context of the
pigeoapi.cli
click handler. This means that there is only one place in the code where pygeoapi is trying to find its own config file, as opposed to the previous implementation, where this happened in multiple places. This PR is also making use of click's ability to recognize options either as explicit arguments or as environment variables, which allows both of these usages to work OK:This allows the removal of some redundant bits of code and makes it easier to debug.
Related Issue / Discussion
Contributions and Licensing
(as per https://github.com/geopython/pygeoapi/blob/master/CONTRIBUTING.md#contributions-and-licensing)