forked from geopython/pygeoapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·159 lines (134 loc) · 5.08 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·159 lines (134 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
# =================================================================
#
# Authors: Just van den Broecke <justb4@gmail.com>
# Benjamin Webb <benjamin.miller.webb@gmail.com>
# Tom Kralidis <tomkralidis@gmail.com>
#
# Copyright (c) 2019 Just van den Broecke
# Copyright (c) 2024 Benjamin Webb
# Copyright (c) 2025 Tom Kralidis
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# =================================================================
# pygeoapi entry script
echo "START /entrypoint.sh"
set +e
export PYGEOAPI_HOME=/pygeoapi
if [[ -z "$PYGEOAPI_CONFIG" ]]; then
export PYGEOAPI_CONFIG="${PYGEOAPI_HOME}/local.config.yml"
fi
if [[ -z "$PYGEOAPI_OPENAPI" ]]; then
export PYGEOAPI_OPENAPI="${PYGEOAPI_HOME}/local.openapi.yml"
fi
if [[ -z "$PYGEOAPI_ASYNCAPI" ]]; then
export PYGEOAPI_ASYNCAPI="${PYGEOAPI_HOME}/local.asyncapi.yml"
fi
# gunicorn env settings with defaults
SCRIPT_NAME=${SCRIPT_NAME:=/}
CONTAINER_NAME=${CONTAINER_NAME:=pygeoapi}
CONTAINER_HOST=${CONTAINER_HOST:=0.0.0.0}
CONTAINER_PORT=${CONTAINER_PORT:=80}
WSGI_APP=${WSGI_APP:=pygeoapi.flask_app:APP}
WSGI_WORKERS=${WSGI_WORKERS:=4}
WSGI_WORKER_TIMEOUT=${WSGI_WORKER_TIMEOUT:=6000}
WSGI_WORKER_CLASS=${WSGI_WORKER_CLASS:=gevent}
# pygeoapi env settings with defaults
PYGEOAPI_OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION=${PYGEOAPI_OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION:=true}
if [ ${PYGEOAPI_OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION} = false ] ; then
OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION='--no-fail-on-invalid-collection'
else
OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION='--fail-on-invalid-collection'
fi
# What to invoke: default is to run gunicorn server
entry_cmd=${1:-run}
# Shorthand
function error() {
echo "ERROR: $@"
exit -1
}
# Workdir
cd ${PYGEOAPI_HOME}
echo "Default config in ${PYGEOAPI_CONFIG}"
echo "Trying to generate openapi.yml"
/venv/bin/pygeoapi openapi generate ${OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION}
[[ $? -ne 0 ]] && error "openapi.yml could not be generated ERROR"
echo "openapi.yml generated continue to pygeoapi"
echo "Trying to generate asyncapi.yml"
/venv/bin/pygeoapi asyncapi generate
[[ $? -ne 0 ]] && echo "asyncapi.yml could not be generated; skipping"
start_gunicorn() {
# SCRIPT_NAME should not have value '/'
[[ "${SCRIPT_NAME}" = '/' ]] && export SCRIPT_NAME="" && echo "make SCRIPT_NAME empty from /"
echo "Starting gunicorn name=${CONTAINER_NAME} on ${CONTAINER_HOST}:${CONTAINER_PORT} with ${WSGI_WORKERS} workers and SCRIPT_NAME=${SCRIPT_NAME}"
exec /venv/bin/gunicorn --workers ${WSGI_WORKERS} \
--worker-class=${WSGI_WORKER_CLASS} \
--timeout ${WSGI_WORKER_TIMEOUT} \
--name=${CONTAINER_NAME} \
--bind ${CONTAINER_HOST}:${CONTAINER_PORT} \
${@} \
${WSGI_APP}
}
case ${entry_cmd} in
# Run Unit tests
test)
for test_py in $(ls tests/test_*.py)
do
# Skip tests requiring backend server or libs installed
case ${test_py} in
tests/test_elasticsearch__provider.py)
;&
tests/test_sensorthings_provider.py)
;&
tests/test_postgresql_provider.py)
;&
tests/test_mongo_provider.py)
echo "Skipping: ${test_py}"
;;
*)
/venv/bin/python3 -m pytest ${test_py}
;;
esac
done
;;
# Run pygeoapi server
run)
# Start
start_gunicorn
;;
# Run pygeoapi server with hot reload
run-with-hot-reload)
# Lock all Python files (for gunicorn hot reload), if running with user root
if [[ $(id -u) -eq 0 ]]
then
echo "Running pygeoapi as root"
find . -type f -name "*.py" | xargs chmod 0444
fi
# Start with hot reload options
start_gunicorn --reload --reload-extra-file ${PYGEOAPI_CONFIG}
;;
*)
error "unknown command arg: must be run (default), run-with-hot-reload, or test"
;;
esac
echo "END /entrypoint.sh"