33#
44# Authors: Just van den Broecke <[email protected] >55# Benjamin Webb <[email protected] >6+ # Tom Kralidis <[email protected] >67#
78# Copyright (c) 2019 Just van den Broecke
89# Copyright (c) 2024 Benjamin Webb
10+ # Copyright (c) 2025 Tom Kralidis
911#
1012# Permission is hereby granted, free of charge, to any person
1113# obtaining a copy of this software and associated documentation
@@ -39,10 +41,10 @@ set +e
3941export PYGEOAPI_HOME=/pygeoapi
4042
4143if [[ -z " $PYGEOAPI_CONFIG " ]]; then
42- export PYGEOAPI_CONFIG=" ${PYGEOAPI_HOME} /local.config.yml"
44+ export PYGEOAPI_CONFIG=" ${PYGEOAPI_HOME} /local.config.yml"
4345fi
4446if [[ -z " $PYGEOAPI_OPENAPI " ]]; then
45- export PYGEOAPI_OPENAPI=" ${PYGEOAPI_HOME} /local.openapi.yml"
47+ export PYGEOAPI_OPENAPI=" ${PYGEOAPI_HOME} /local.openapi.yml"
4648fi
4749
4850# gunicorn env settings with defaults
@@ -60,8 +62,8 @@ entry_cmd=${1:-run}
6062
6163# Shorthand
6264function error() {
63- echo " ERROR: $@ "
64- exit -1
65+ echo " ERROR: $@ "
66+ exit -1
6567}
6668
6769# Workdir
@@ -70,71 +72,71 @@ cd ${PYGEOAPI_HOME}
7072echo " Default config in ${PYGEOAPI_CONFIG} "
7173
7274echo " Trying to generate openapi.yml"
73- pygeoapi openapi generate ${PYGEOAPI_CONFIG} --output-file ${PYGEOAPI_OPENAPI}
75+ /venv/bin/ pygeoapi openapi generate ${PYGEOAPI_CONFIG} --output-file ${PYGEOAPI_OPENAPI}
7476
7577[[ $? -ne 0 ]] && error " openapi.yml could not be generated ERROR"
7678
7779echo " openapi.yml generated continue to pygeoapi"
7880
7981start_gunicorn () {
80- # SCRIPT_NAME should not have value '/'
81- [[ " ${SCRIPT_NAME} " = ' /' ]] && export SCRIPT_NAME=" " && echo " make SCRIPT_NAME empty from /"
82-
83- echo " Starting gunicorn name=${CONTAINER_NAME} on ${CONTAINER_HOST} :${CONTAINER_PORT} with ${WSGI_WORKERS} workers and SCRIPT_NAME=${SCRIPT_NAME} "
84- exec gunicorn --workers ${WSGI_WORKERS} \
85- --worker-class=${WSGI_WORKER_CLASS} \
86- --timeout ${WSGI_WORKER_TIMEOUT} \
87- --name=${CONTAINER_NAME} \
88- --bind ${CONTAINER_HOST} :${CONTAINER_PORT} \
89- ${@ } \
90- ${WSGI_APP}
82+ # SCRIPT_NAME should not have value '/'
83+ [[ " ${SCRIPT_NAME} " = ' /' ]] && export SCRIPT_NAME=" " && echo " make SCRIPT_NAME empty from /"
84+
85+ echo " Starting gunicorn name=${CONTAINER_NAME} on ${CONTAINER_HOST} :${CONTAINER_PORT} with ${WSGI_WORKERS} workers and SCRIPT_NAME=${SCRIPT_NAME} "
86+ exec /venv/bin/ gunicorn --workers ${WSGI_WORKERS} \
87+ --worker-class=${WSGI_WORKER_CLASS} \
88+ --timeout ${WSGI_WORKER_TIMEOUT} \
89+ --name=${CONTAINER_NAME} \
90+ --bind ${CONTAINER_HOST} :${CONTAINER_PORT} \
91+ ${@ } \
92+ ${WSGI_APP}
9193}
9294
9395case ${entry_cmd} in
94- # Run Unit tests
95- test)
96- for test_py in $( ls tests/test_* .py)
97- do
98- # Skip tests requiring backend server or libs installed
99- case ${test_py} in
100- tests/test_elasticsearch__provider.py)
101- ;&
102- tests/test_sensorthings_provider.py)
103- ;&
104- tests/test_postgresql_provider.py)
105- ;&
106- tests/test_mongo_provider.py)
107- echo " Skipping: ${test_py} "
108- ;;
109- * )
110- python3 -m pytest ${test_py}
111- ;;
112- esac
113- done
114- ;;
115-
116- # Run pygeoapi server
117- run)
118- # Start
119- start_gunicorn
120- ;;
121-
122- # Run pygeoapi server with hot reload
123- run-with-hot-reload)
124- # Lock all Python files (for gunicorn hot reload), if running with user root
125- if [[ $( id -u) -eq 0 ]]
126- then
127- echo " Running pygeoapi as root"
128- find . -type f -name " *.py" | xargs chmod 0444
129- fi
130-
131- # Start with hot reload options
132- start_gunicorn --reload --reload-extra-file ${PYGEOAPI_CONFIG}
133- ;;
134-
135- * )
136- error " unknown command arg: must be run (default), run-with-hot-reload, or test"
137- ;;
96+ # Run Unit tests
97+ test)
98+ for test_py in $( ls tests/test_* .py)
99+ do
100+ # Skip tests requiring backend server or libs installed
101+ case ${test_py} in
102+ tests/test_elasticsearch__provider.py)
103+ ;&
104+ tests/test_sensorthings_provider.py)
105+ ;&
106+ tests/test_postgresql_provider.py)
107+ ;&
108+ tests/test_mongo_provider.py)
109+ echo " Skipping: ${test_py} "
110+ ;;
111+ * )
112+ /venv/bin/ python3 -m pytest ${test_py}
113+ ;;
114+ esac
115+ done
116+ ;;
117+
118+ # Run pygeoapi server
119+ run)
120+ # Start
121+ start_gunicorn
122+ ;;
123+
124+ # Run pygeoapi server with hot reload
125+ run-with-hot-reload)
126+ # Lock all Python files (for gunicorn hot reload), if running with user root
127+ if [[ $( id -u) -eq 0 ]]
128+ then
129+ echo " Running pygeoapi as root"
130+ find . -type f -name " *.py" | xargs chmod 0444
131+ fi
132+
133+ # Start with hot reload options
134+ start_gunicorn --reload --reload-extra-file ${PYGEOAPI_CONFIG}
135+ ;;
136+
137+ * )
138+ error " unknown command arg: must be run (default), run-with-hot-reload, or test"
139+ ;;
138140esac
139141
140142echo " END /entrypoint.sh"
0 commit comments