Skip to content

Commit f2413b9

Browse files
committed
Add hot-reload to entrypoint
1 parent a1c94fa commit f2413b9

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

docker/entrypoint.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# =================================================================
33
#
44
# Authors: Just van den Broecke <[email protected]>
5+
# Ben Webb <[email protected]>
56
#
67
# Copyright (c) 2019 Just van den Broecke
8+
# Copyright (c) 2024 Ben Webb
79
#
810
# Permission is hereby granted, free of charge, to any person
911
# obtaining a copy of this software and associated documentation
@@ -102,8 +104,30 @@ case ${entry_cmd} in
102104
--bind ${CONTAINER_HOST}:${CONTAINER_PORT} \
103105
pygeoapi.flask_app:APP
104106
;;
107+
108+
# Run pygeoapi server with hot reload
109+
hot-reload)
110+
# Lock all Python files (for gunicorn hot reload)
111+
find . -type f -name "*.py" | xargs chmod 0444
112+
113+
# SCRIPT_NAME should not have value '/'
114+
[[ "${SCRIPT_NAME}" = '/' ]] && export SCRIPT_NAME="" && echo "make SCRIPT_NAME empty from /"
115+
116+
echo "Start gunicorn name=${CONTAINER_NAME} on ${CONTAINER_HOST}:${CONTAINER_PORT} with ${WSGI_WORKERS} workers and SCRIPT_NAME=${SCRIPT_NAME}"
117+
exec gunicorn --workers ${WSGI_WORKERS} \
118+
--worker-class=${WSGI_WORKER_CLASS} \
119+
--timeout ${WSGI_WORKER_TIMEOUT} \
120+
--name=${CONTAINER_NAME} \
121+
--bind ${CONTAINER_HOST}:${CONTAINER_PORT} \
122+
--reload \
123+
--reload-extra-file ${PYGEOAPI_CONFIG} \
124+
pygeoapi.flask_app:APP
125+
126+
touch ${PYGEOAPI_CONFIG}
127+
;;
128+
105129
*)
106-
error "unknown command arg: must be run (default) or test"
130+
error "unknown command arg: must be run (default), hot-reload, or test"
107131
;;
108132
esac
109133

docs/source/running-with-docker.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ To run with the default built-in configuration and data:
2929
3030
...then browse to http://localhost:5000
3131

32+
You can also run pygeoapi with hot-reload of the configuration enabled
33+
34+
.. code-block:: bash
35+
36+
docker run -p 5000:80 -it geopython/pygeoapi hot-reload
37+
3238
You can also run all unit tests to verify:
3339

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

97105

98106
Deploying on a sub-path

0 commit comments

Comments
 (0)