From c33740a3b6c71145aefae7fa1f3e571b3613912f Mon Sep 17 00:00:00 2001 From: Benjamin Webb <40066515+webb-ben@users.noreply.github.com> Date: Sun, 15 Dec 2024 20:14:49 -0500 Subject: [PATCH] Add hot-reload to entrypoint --- docker/entrypoint.sh | 26 +++++++++++++++++++++++++- docs/source/running-with-docker.rst | 10 +++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 28f0592d2..4e5073ca8 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -2,8 +2,10 @@ # ================================================================= # # Authors: Just van den Broecke +# Benjamin Webb # # 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 @@ -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 diff --git a/docs/source/running-with-docker.rst b/docs/source/running-with-docker.rst index 87a644bb4..dc7f2f419 100644 --- a/docs/source/running-with-docker.rst +++ b/docs/source/running-with-docker.rst @@ -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 @@ -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