Skip to content

Commit

Permalink
Add starlette / docker
Browse files Browse the repository at this point in the history
  • Loading branch information
webb-ben committed Dec 27, 2023
1 parent b78d28b commit 215d037
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ ENV TZ=${TZ} \
locales \
tzdata \
gunicorn \
uvicorn \
python3-dateutil \
python3-gevent \
python3-greenlet \
Expand Down Expand Up @@ -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 . \
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
14 changes: 14 additions & 0 deletions docker/examples/starlette/README.md
Original file line number Diff line number Diff line change
@@ -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`.
42 changes: 42 additions & 0 deletions docker/examples/starlette/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# =================================================================
#
# Authors: Benjamin Webb <[email protected]>
#
# 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

0 comments on commit 215d037

Please sign in to comment.