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

Add hot-reload option to docker entrypoint #1880

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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]>
# Benjamin Webb <[email protected]>
#
# Copyright (c) 2019 Just van den Broecke
# Copyright (c) 2024 Benjamin 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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this touch is actually executed?
As far as I understand it, exec gunicorn replaces the bash process with gunicorn and thus stops any further execution of the script, or is this somehow different here?

;;

*)
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