Skip to content

Commit 5d75055

Browse files
authored
Docker: add env var to enable building OpenAPI document with invalid collections (#2188) (#2192)
1 parent 104807e commit 5d75055

File tree

5 files changed

+37
-31
lines changed

5 files changed

+37
-31
lines changed

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ FROM ubuntu:noble-20250910
3838

3939
LABEL maintainer="Just van den Broecke <[email protected]>"
4040

41-
# Docker file for full geoapi server with libs/packages for all providers.
41+
# Dockerfile for a full pygeoapi server with libs/packages for all providers.
4242
# Server runs with gunicorn. You can override ENV settings.
4343
# Defaults:
4444
# SCRIPT_NAME=/
@@ -48,6 +48,7 @@ LABEL maintainer="Just van den Broecke <[email protected]>"
4848
# WSGI_WORKERS=4
4949
# WSGI_WORKER_TIMEOUT=6000
5050
# WSGI_WORKER_CLASS=gevent
51+
# PYGEOAPI_OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION=true
5152

5253
# Calls entrypoint.sh to run. Inspect it for options.
5354
# Contains some test data. Also allows you to verify by running all unit tests.

docker/entrypoint.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ WSGI_WORKERS=${WSGI_WORKERS:=4}
5757
WSGI_WORKER_TIMEOUT=${WSGI_WORKER_TIMEOUT:=6000}
5858
WSGI_WORKER_CLASS=${WSGI_WORKER_CLASS:=gevent}
5959

60+
# pygeoapi env settings with defaults
61+
PYGEOAPI_OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION=${PYGEOAPI_OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION:=true}
62+
63+
if [ ${PYGEOAPI_OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION} = false ] ; then
64+
OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION='--no-fail-on-invalid-collection'
65+
else
66+
OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION='--fail-on-invalid-collection'
67+
fi
68+
6069
# What to invoke: default is to run gunicorn server
6170
entry_cmd=${1:-run}
6271

@@ -72,7 +81,7 @@ cd ${PYGEOAPI_HOME}
7281
echo "Default config in ${PYGEOAPI_CONFIG}"
7382

7483
echo "Trying to generate openapi.yml"
75-
/venv/bin/pygeoapi openapi generate ${PYGEOAPI_CONFIG} --output-file ${PYGEOAPI_OPENAPI}
84+
/venv/bin/pygeoapi openapi generate ${PYGEOAPI_CONFIG} --output-file ${PYGEOAPI_OPENAPI} ${OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION}
7685

7786
[[ $? -ne 0 ]] && error "openapi.yml could not be generated ERROR"
7887

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
.. _running-with-docker:
1+
.. _docker:
22

33
Docker
44
======
55

6-
pygeoapi provides an official `Docker`_ image which is made available on both the `geopython Docker Hub`_ and our `GitHub Container Registry`_. Additional
7-
Docker examples can be found in the `pygeoapi GitHub repository`_, each with sample configurations, test data,
8-
deployment scenarios and provider backends.
6+
pygeoapi provides an official Docker image which is made available on the `geopython Docker Hub`_ as well as the `GitHub Container Registry`_. Additional Docker examples can be found in the `pygeoapi-examples GitHub repository`_, each with sample configurations, test data, deployment scenarios and provider backends.
97

108
The `pygeoapi demo server`_ runs various services from Docker images which also serve as `useful examples`_.
119

@@ -15,7 +13,7 @@ The `pygeoapi demo server`_ runs various services from Docker images which also
1513
The basics
1614
----------
1715

18-
The official pygeoapi Docker image will start a pygeoapi Docker container using `Gunicorn <https://docs.gunicorn.org/en/latest/>`_ on internal port 80.
16+
The official pygeoapi Docker image will start a pygeoapi Docker container using `Gunicorn <https://gunicorn.org>`_ on internal port 80.
1917

2018
Either ``IMAGE`` can be called with the ``docker`` command, ``geopython/pygeoapi`` from DockerHub or ``ghcr.io/geopython/pygeoapi`` from the GitHub Container Registry. Examples below use ``geopython/pygeoapi``.
2119

@@ -80,19 +78,23 @@ A corresponding example can be found in https://github.com/geopython/demo.pygeoa
8078
Environment Variables for Configuration
8179
---------------------------------------
8280

83-
In addition to **`PYGEOAPI_CONFIG`** and **`PYGEOAPI_OPENAPI`**, the base Docker image supports additional environment variables for configuring the `pygeoapi` server behavior:
81+
In addition to ``PYGEOAPI_CONFIG`` and ``PYGEOAPI_OPENAPI``, the base Docker image supports additional environment variables for configuring server behavior:
8482

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

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

94-
2. **`PYGEOAPI_SERVER_ADMIN`**:
95-
This boolean environment variable enables or disables the `pygeoapi` Admin API. By default, the Admin API is disabled. To enable it:
91+
* ``PYGEOAPI_OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION``: enables or disables generation of the OpenAPI document if one or more collections are invalid (default is ``true``)
92+
93+
.. code-block:: bash
94+
95+
docker run -p 5000:80 -e PYGEOAPI_OPENAPI_GENERATE_FAIL_ON_INVALID_COLLECTION=false -it geopython/pygeoapi
96+
97+
* ``PYGEOAPI_SERVER_ADMIN``: enables or disables the `pygeoapi` Admin API (default is ``false``)
9698

9799
.. code-block:: bash
98100
@@ -102,44 +104,40 @@ In addition to **`PYGEOAPI_CONFIG`** and **`PYGEOAPI_OPENAPI`**, the base Docker
102104
103105
To learn more about the Admin API see :ref:`admin-api`.
104106

105-
3. **`CONTAINER_HOST`**:
106-
This variable sets the listening address for incoming connections. Normally the server is listening on ``localhost`` (the default), but other values are also possible.
107+
* ``CONTAINER_HOST``: sets the listening address for incoming connections (default is ``localhost``)
107108

108109
.. code-block:: bash
109110
110111
docker run -p 5000:80 -e CONTAINER_HOST=192.168.0.7 -it geopython/pygeoapi
111112
112-
4. **`CONTAINER_PORT`**:
113-
This variable sets the listening port for incoming connections. The default port is ``80``; in this example, we change it to ``5001``.
113+
* ``CONTAINER_PORT``: sets the listening port for incoming connections (default is ``80``)
114114

115115
.. code-block:: bash
116116
117117
docker run -p 5000:5001 -e CONTAINER_PORT=5001 -it geopython/pygeoapi
118118
119-
5. **`WSGI_WORKERS`**:
120-
121-
This variable sets the number of workers used by the Gunicorn server, the default being ``4``.
122-
For performance reasons, `it is not recommended to use a high number of workers <https://docs.gunicorn.org/en/latest/design.html#how-many-workers>`_ .
119+
* ``WSGI_WORKERS``: sets the number of workers used by the Gunicorn server (default is ``4``)
123120

124121
.. code-block:: bash
125122
126123
docker run -p 5000:80 -e WSGI_WORKERS=10 -it geopython/pygeoapi
127124
128-
6. **`WSGI_WORKER_TIMEOUT`**:
125+
.. note::
126+
For performance reasons, `it is not recommended to use a high number of workers <https://docs.gunicorn.org/en/latest/design.html#how-many-workers>`_
129127

130-
Gunicorn workers silent for more than the seconds set by this variable are killed and restarted. The default value is ``6000``.
128+
* ``WSGI_WORKER_TIMEOUT``: sets the number of seconds before silent Gunicorn workers are killed and restarted (default is ``6000``)
131129

132130
.. code-block:: bash
133131
134132
docker run -p 5000:80 -e WSGI_WORKERS=10 -it geopython/pygeoapi
135133
136-
You can read more about this and other Gunicorn settings in the `official documentation <https://docs.gunicorn.org/en/stable/>`_
134+
.. note::
135+
More information on Gunicorn settings can be found in the `official Gunicorn documentation <https://docs.gunicorn.org>`_
137136

138137
Deploying on a sub-path
139138
-----------------------
140139

141-
By default the ``pygeoapi`` Docker image will run from the ``root`` path (``/``). If you need to run from a
142-
sub-path and have all internal URLs properly configured, you can set the ``SCRIPT_NAME`` environment variable.
140+
By default the ``pygeoapi`` Docker image will run from the ``root`` path (``/``). If you need to run from a sub-path and have all internal URLs properly configured, you can set the ``SCRIPT_NAME`` environment variable.
143141

144142
For example to run with ``my.config.yml`` on ``http://localhost:5000/mypygeoapi``:
145143

@@ -176,11 +174,9 @@ Docker is an easy and reproducible approach to deploying systems.
176174
Additional approaches are welcome and encouraged; see :ref:`contributing` for more information on
177175
how to contribute to and improve the documentation
178176

179-
180-
.. _`Docker`: https://www.docker.com
181177
.. _`geopython Docker Hub`: https://hub.docker.com/r/geopython/pygeoapi
182178
.. _`GitHub Container Registry`: https://github.com/geopython/pygeoapi/pkgs/container/pygeoapi
183-
.. _`pygeoapi GitHub repository`: https://github.com/geopython/pygeoapi
179+
.. _`pygeoapi-examples GitHub repository`: https://github.com/geopython/pygeoapi-examples
184180
.. _`pygeoapi demo server`: https://demo.pygeoapi.io
185181
.. _`useful examples`: https://github.com/geopython/demo.pygeoapi.io/tree/master/services
186182
.. _`Docker Compose`: https://docs.docker.com/compose/

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ reference documentation on all aspects of the project.
3434
configuration
3535
administration
3636
running
37-
running-with-docker
37+
docker
3838
tour
3939
openapi
4040
publishing/index

docs/source/running.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Since pygeoapi is a Python API at its core, it can be served via numerous web se
77
So far, pygeoapi can be served via Flask `WSGI`_, Starlette `ASGI`_, and `Django`_.
88

99
This section covers how pygeoapi can be run in development environments and in production environments.
10-
For running pygeoapi using docker, refer to the :ref:`running-with-docker` section.
10+
For running pygeoapi using Docker, refer to the :ref:`docker` section.
1111

1212
Running in development
1313
----------------------
@@ -194,7 +194,7 @@ Running in production
194194
Running ``pygeoapi serve`` in production is not recommended or advisable. Preferred options are described below.
195195

196196
.. seealso::
197-
:ref:`running-with-docker` for container-based production installations.
197+
:ref:`docker` for container-based production installations.
198198

199199
Apache and mod_wsgi
200200
^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)