Skip to content

Commit 3832ea8

Browse files
authored
Make PyGeoAPI to run rootless (Tested in Openshift) (#2088)
* Allowed to modify PYGEOAPI_CONFIG and PYGEOAPI_OPENAPI envs on container start. * commented chmod command. This is useless on rootless container and could be switched back on root * Update entrypoint.sh Add condition to chmod python files when running pygeoapi as root
1 parent 8a7f8c1 commit 3832ea8

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

docker/entrypoint.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ echo "START /entrypoint.sh"
3737
set +e
3838

3939
export PYGEOAPI_HOME=/pygeoapi
40-
export PYGEOAPI_CONFIG="${PYGEOAPI_HOME}/local.config.yml"
41-
export PYGEOAPI_OPENAPI="${PYGEOAPI_HOME}/local.openapi.yml"
40+
41+
if [[ -z "$PYGEOAPI_CONFIG" ]]; then
42+
export PYGEOAPI_CONFIG="${PYGEOAPI_HOME}/local.config.yml"
43+
fi
44+
if [[ -z "$PYGEOAPI_OPENAPI" ]]; then
45+
export PYGEOAPI_OPENAPI="${PYGEOAPI_HOME}/local.openapi.yml"
46+
fi
4247

4348
# gunicorn env settings with defaults
4449
SCRIPT_NAME=${SCRIPT_NAME:=/}
@@ -62,6 +67,8 @@ function error() {
6267
# Workdir
6368
cd ${PYGEOAPI_HOME}
6469

70+
echo "Default config in ${PYGEOAPI_CONFIG}"
71+
6572
echo "Trying to generate openapi.yml"
6673
pygeoapi openapi generate ${PYGEOAPI_CONFIG} --output-file ${PYGEOAPI_OPENAPI}
6774

@@ -114,8 +121,12 @@ case ${entry_cmd} in
114121

115122
# Run pygeoapi server with hot reload
116123
run-with-hot-reload)
117-
# Lock all Python files (for gunicorn hot reload)
118-
find . -type f -name "*.py" | xargs chmod 0444
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
119130

120131
# Start with hot reload options
121132
start_gunicorn --reload --reload-extra-file ${PYGEOAPI_CONFIG}

0 commit comments

Comments
 (0)