Skip to content
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

Update starlette documentation #1461

Merged
merged 5 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ ENV TZ=${TZ} \
locales \
tzdata \
gunicorn \
uvicorn \
python3-dateutil \
python3-gevent \
python3-greenlet \
Expand Down Expand Up @@ -123,6 +124,7 @@ RUN \
# Install remaining pygeoapi deps
&& pip3 install -r requirements-docker.txt \
&& pip3 install -r requirements-admin.txt \
&& pip3 install -r requirements-starlette.txt \

# Install pygeoapi
&& pip3 install -e . \
Expand Down
4 changes: 2 additions & 2 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CONTAINER_PORT=${CONTAINER_PORT:=80}
WSGI_WORKERS=${WSGI_WORKERS:=4}
WSGI_WORKER_TIMEOUT=${WSGI_WORKER_TIMEOUT:=6000}
WSGI_WORKER_CLASS=${WSGI_WORKER_CLASS:=gevent}
WSGI_APP_FRAMEWORK=${WSGI_APP_FRAMEWORK:="pygeoapi.flask_app:APP"}

# What to invoke: default is to run gunicorn server
entry_cmd=${1:-run}
Expand Down Expand Up @@ -93,14 +94,13 @@ case ${entry_cmd} in
run)
# SCRIPT_NAME should not have value '/'
[[ "${SCRIPT_NAME}" = '/' ]] && export SCRIPT_NAME="" && echo "make SCRIPT_NAME empty from /"

echo "Start gunicorn name=${CONTAINER_NAME} on ${CONTAINER_HOST}:${CONTAINER_PORT} with ${WSGI_WORKERS} workers and SCRIPT_NAME=${SCRIPT_NAME}"
exec gunicorn --workers ${WSGI_WORKERS} \
--worker-class=${WSGI_WORKER_CLASS} \
--timeout ${WSGI_WORKER_TIMEOUT} \
--name=${CONTAINER_NAME} \
--bind ${CONTAINER_HOST}:${CONTAINER_PORT} \
pygeoapi.flask_app:APP
${WSGI_APP_FRAMEWORK}
;;
*)
error "unknown command arg: must be run (default) or test"
Expand Down
28 changes: 27 additions & 1 deletion docs/source/running-with-docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The basics

The official pygeoapi Docker image will start a pygeoapi Docker container using Gunicorn on internal port 80.

Either ``IMAGE`` can be called with the ``docker`` command, ``geopython/pygeoapi`` from DockerHub or ``ghcr.io/geophython/pygeoapi`` from the GitHub Container Registry. Examples below use ``geopython/pygeoapi``.
Either ``IMAGE`` can be called with the ``docker`` command, ``geopython/pygeoapi`` from DockerHub or ``ghcr.io/geopython/pygeoapi`` from the GitHub Container Registry. Examples below use ``geopython/pygeoapi``.

To run with the default built-in configuration and data:

Expand Down Expand Up @@ -103,6 +103,32 @@ Below is a corresponding ``docker-compose`` approach:

A corresponding example can be found in https://github.com/geopython/demo.pygeoapi.io/tree/master/services/pygeoapi_master

Deploying with Starlette
------------------------

By default the ``pygeoapi`` Docker image will run using ``Flask``. If you need to run using a
different framework, you can set the ``WSGI_APP_FRAMEWORK`` and ``WSGI_WORKER_CLASS`` environment variables.

.. code-block:: bash

docker run -p 5000:80 -e WSGI_APP_FRAMEWORK='pygeoapi.starlette_app:APP' -e WSGI_WORKER_CLASS='uvicorn.workers.UvicornH11Worker' -it geopython/pygeoapi

Below is a corresponding ``docker-compose`` approach:

.. code-block:: yaml

version: "3"
services:
pygeoapi:
image: geopython/pygeoapi:latest
ports:
- "5000:80"
environment:
- WSGI_APP_FRAMEWORK=pygeoapi.starlette_app:APP
- WSGI_WORKER_CLASS=uvicorn.workers.UvicornH11Worker

A corresponding example can be found in the pygeoapi examples.

Summary
-------

Expand Down
2 changes: 1 addition & 1 deletion docs/source/running.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ It is simple to run using the following command:

.. code-block:: bash
gunicorn pygeoapi.starlette_app:app -w 4 -k uvicorn.workers.UvicornWorker
gunicorn pygeoapi.starlette_app:APP -w 4 -k uvicorn.workers.UvicornH11Worker
.. note::
Uvicorn is as easy to install as ``pip3 install uvicorn``
Expand Down
Loading