Skip to content

Commit

Permalink
Add hot-reload to entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
webb-ben committed Dec 16, 2024
1 parent a1c94fa commit f2413b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
26 changes: 25 additions & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
# =================================================================
#
# Authors: Just van den Broecke <[email protected]>
# Ben Webb <[email protected]>
#
# Copyright (c) 2019 Just van den Broecke
# Copyright (c) 2024 Ben Webb
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -102,8 +104,30 @@ case ${entry_cmd} in
--bind ${CONTAINER_HOST}:${CONTAINER_PORT} \
pygeoapi.flask_app:APP
;;

# Run pygeoapi server with hot reload
hot-reload)
# Lock all Python files (for gunicorn hot reload)
find . -type f -name "*.py" | xargs chmod 0444

# 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} \
--reload \
--reload-extra-file ${PYGEOAPI_CONFIG} \
pygeoapi.flask_app:APP

touch ${PYGEOAPI_CONFIG}
;;

*)
error "unknown command arg: must be run (default) or test"
error "unknown command arg: must be run (default), hot-reload, or test"
;;
esac

Expand Down
10 changes: 9 additions & 1 deletion docs/source/running-with-docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ To run with the default built-in configuration and data:
...then browse to http://localhost:5000

You can also run pygeoapi with hot-reload of the configuration enabled

.. code-block:: bash
docker run -p 5000:80 -it geopython/pygeoapi hot-reload
You can also run all unit tests to verify:

.. code-block:: bash
Expand Down Expand Up @@ -91,8 +97,10 @@ The base Docker image supports two additional environment variables for configur
.. code-block:: bash
docker run -p 5000:80 -e PYGEOAPI_SERVER_ADMIN=true -it geopython/pygeoapi
# with hot-reload
docker run -p 5000:80 -e PYGEOAPI_SERVER_ADMIN=true -it geopython/pygeoapi hot-reload
This does not enable hot reloading of the `pygoeapi` configuration. To learn more about the Admin API see :ref:`admin-api`.
To learn more about the Admin API see :ref:`admin-api`.


Deploying on a sub-path
Expand Down

0 comments on commit f2413b9

Please sign in to comment.