Skip to content

Commit 8b1a987

Browse files
authored
Support enviornment vars in base Docker image (#1873)
* Support enviornment vars in base Docker image * Update running with docker documentation * s/PYGEOAPI_URL/PYGEOAPI_SERVER_URL/g * s/PYGEOAPI_ADMIN_API/PYGEOAPI_SERVER_ADMIN/g
1 parent cbbd0eb commit 8b1a987

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

docker/default.config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ server:
3838
bind:
3939
host: 0.0.0.0
4040
port: 80
41-
url: http://localhost:5000
41+
url: ${PYGEOAPI_SERVER_URL:-http://localhost:5000}
4242
mimetype: application/json; charset=UTF-8
4343
encoding: utf-8
4444
gzip: false
4545
language: en-US
4646
cors: true
4747
pretty_print: true
48+
admin: ${PYGEOAPI_SERVER_ADMIN:-false}
4849
limit: 10
4950
# templates: /path/to/templates
5051
map:

docs/source/running-with-docker.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ Or you can create a ``Dockerfile`` extending the base image and **copy** in your
7171
7272
A corresponding example can be found in https://github.com/geopython/demo.pygeoapi.io/tree/master/services/pygeoapi_master
7373

74+
Environment Variables for Configuration
75+
---------------------------------------
76+
77+
The base Docker image supports two additional environment variables for configuring the `pygeoapi` server behavior:
78+
79+
1. **`PYGEOAPI_SERVER_URL`**:
80+
This variable sets the `pygeoapi` server URL in the configuration. It is useful for dynamically configuring the server URL during container deployment. For example:
81+
82+
.. code-block:: bash
83+
84+
docker run -p 2018:80 -e PYGEOAPI_SERVER_URL='http://localhost:2018' -it geopython/pygeoapi
85+
86+
This ensures the service URLs in the configuration file are automatically updated to reflect the specified URL.
87+
88+
2. **`PYGEOAPI_SERVER_ADMIN`**:
89+
This boolean environment variable enables or disables the `pygeoapi` Admin API. By default, the Admin API is disabled. To enable it:
90+
91+
.. code-block:: bash
92+
93+
docker run -p 5000:80 -e PYGEOAPI_SERVER_ADMIN=true -it geopython/pygeoapi
94+
95+
This does not enable hot reloading of the `pygoeapi` configuration. To learn more about the Admin API see :ref:`admin-api`.
96+
97+
7498
Deploying on a sub-path
7599
-----------------------
76100

tests/pygeoapi-test-config-envvars.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ server:
3131
bind:
3232
host: 0.0.0.0
3333
port: ${PYGEOAPI_PORT}
34-
url: ${PYGEOAPI_URL:-http://localhost:5000/}
34+
url: ${PYGEOAPI_SERVER_URL:-http://localhost:5000/}
3535
mimetype: application/json; charset=UTF-8
3636
encoding: utf-8
3737
language: en-US

tests/test_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_config_envvars():
5959
'pygeoapi default instance my title'
6060
assert config['server']['api_rules']['url_prefix'] == ''
6161

62-
os.environ['PYGEOAPI_URL'] = 'https://localhost:5000'
62+
os.environ['PYGEOAPI_SERVER_URL'] = 'https://localhost:5000'
6363
os.environ['PYGEOAPI_PREFIX'] = 'v1'
6464

6565
with open(get_test_file_path('pygeoapi-test-config-envvars.yml')) as fh:

0 commit comments

Comments
 (0)