diff --git a/Dockerfile b/Dockerfile index ebb0eb9e42..b7e6186210 100644 --- a/Dockerfile +++ b/Dockerfile @@ -90,6 +90,7 @@ ENV TZ=${TZ} \ locales \ tzdata \ gunicorn \ + uvicorn \ python3-dateutil \ python3-gevent \ python3-greenlet \ @@ -121,6 +122,7 @@ RUN \ # Install remaining pygeoapi deps && pip3 install -r requirements-docker.txt \ + && pip3 install -r requirements-starlette.txt \ # Install pygeoapi && pip3 install -e . \ diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index b81bed89f0..039dc4378e 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -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} @@ -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" diff --git a/docker/examples/starlette/README.md b/docker/examples/starlette/README.md new file mode 100644 index 0000000000..e37df4bbaf --- /dev/null +++ b/docker/examples/starlette/README.md @@ -0,0 +1,14 @@ +# pygeoapi with Starlette + +This folder contains the docker-compose configuration necessary to setup an example +`pygeoapi` server using Starlette as the web framework. + +## Building and Running + +To build and run the [Docker compose file](docker-compose.yml) in localhost: + +``` +docker compose up [--build] [-d] +``` + +Navigate to `localhost:5000`. diff --git a/docker/examples/starlette/docker-compose.yml b/docker/examples/starlette/docker-compose.yml new file mode 100644 index 0000000000..38ac5ea5ce --- /dev/null +++ b/docker/examples/starlette/docker-compose.yml @@ -0,0 +1,42 @@ +# ================================================================= +# +# Authors: Benjamin Webb +# +# Copyright (c) 2023 Benjamin Webb +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# ================================================================= + +version: "3" + +services: + + pygeoapi: + image: geopython/pygeoapi:latest + build: + context: ../../.. + environment: + - WSGI_APP_FRAMEWORK=pygeoapi.starlette_app:APP + - WSGI_WORKER_CLASS=uvicorn.workers.UvicornH11Worker + ports: + - 5000:80