Skip to content

Commit

Permalink
Support enviornment vars in base Docker image (#1873)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
webb-ben authored Dec 14, 2024
1 parent cbbd0eb commit 8b1a987
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docker/default.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ server:
bind:
host: 0.0.0.0
port: 80
url: http://localhost:5000
url: ${PYGEOAPI_SERVER_URL:-http://localhost:5000}
mimetype: application/json; charset=UTF-8
encoding: utf-8
gzip: false
language: en-US
cors: true
pretty_print: true
admin: ${PYGEOAPI_SERVER_ADMIN:-false}
limit: 10
# templates: /path/to/templates
map:
Expand Down
24 changes: 24 additions & 0 deletions docs/source/running-with-docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ Or you can create a ``Dockerfile`` extending the base image and **copy** in your
A corresponding example can be found in https://github.com/geopython/demo.pygeoapi.io/tree/master/services/pygeoapi_master

Environment Variables for Configuration
---------------------------------------

The base Docker image supports two additional environment variables for configuring the `pygeoapi` server behavior:

1. **`PYGEOAPI_SERVER_URL`**:
This variable sets the `pygeoapi` server URL in the configuration. It is useful for dynamically configuring the server URL during container deployment. For example:

.. code-block:: bash
docker run -p 2018:80 -e PYGEOAPI_SERVER_URL='http://localhost:2018' -it geopython/pygeoapi
This ensures the service URLs in the configuration file are automatically updated to reflect the specified URL.

2. **`PYGEOAPI_SERVER_ADMIN`**:
This boolean environment variable enables or disables the `pygeoapi` Admin API. By default, the Admin API is disabled. To enable it:

.. code-block:: bash
docker run -p 5000:80 -e PYGEOAPI_SERVER_ADMIN=true -it geopython/pygeoapi
This does not enable hot reloading of the `pygoeapi` configuration. To learn more about the Admin API see :ref:`admin-api`.


Deploying on a sub-path
-----------------------

Expand Down
2 changes: 1 addition & 1 deletion tests/pygeoapi-test-config-envvars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ server:
bind:
host: 0.0.0.0
port: ${PYGEOAPI_PORT}
url: ${PYGEOAPI_URL:-http://localhost:5000/}
url: ${PYGEOAPI_SERVER_URL:-http://localhost:5000/}
mimetype: application/json; charset=UTF-8
encoding: utf-8
language: en-US
Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_config_envvars():
'pygeoapi default instance my title'
assert config['server']['api_rules']['url_prefix'] == ''

os.environ['PYGEOAPI_URL'] = 'https://localhost:5000'
os.environ['PYGEOAPI_SERVER_URL'] = 'https://localhost:5000'
os.environ['PYGEOAPI_PREFIX'] = 'v1'

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

0 comments on commit 8b1a987

Please sign in to comment.