From 295e6e7e95f04d1ed7a05ac70cabf3dcf88c5bd1 Mon Sep 17 00:00:00 2001 From: Benjamin Webb Date: Wed, 28 Jan 2026 11:50:28 -0700 Subject: [PATCH 1/2] Basic PubSub Setup --- docker/pubsub/Dockerfile | 7 ++ docker/pubsub/README.md | 15 +++ docker/pubsub/docker-compose.yml | 17 ++++ docker/pubsub/mosquitto.conf | 16 +++ docker/pubsub/pygeoapi.config.yml | 157 ++++++++++++++++++++++++++++++ 5 files changed, 212 insertions(+) create mode 100644 docker/pubsub/Dockerfile create mode 100644 docker/pubsub/README.md create mode 100644 docker/pubsub/docker-compose.yml create mode 100644 docker/pubsub/mosquitto.conf create mode 100644 docker/pubsub/pygeoapi.config.yml diff --git a/docker/pubsub/Dockerfile b/docker/pubsub/Dockerfile new file mode 100644 index 0000000..864be80 --- /dev/null +++ b/docker/pubsub/Dockerfile @@ -0,0 +1,7 @@ +FROM geopython/pygeoapi:latest + +RUN cp tests/data/open.canada.ca/sample-records.tinydb /sample-records.tinydb +RUN /venv/bin/python3 -m pip install "gunicorn<24" "paho-mqtt" +RUN /venv/bin/python3 -m pip install --target /pygeoapi --no-deps --upgrade https://github.com/geopython/pygeoapi/archive/refs/heads/ogcapi-pubsub.zip + +COPY pygeoapi.config.yml /pygeoapi/local.config.yml diff --git a/docker/pubsub/README.md b/docker/pubsub/README.md new file mode 100644 index 0000000..e776d53 --- /dev/null +++ b/docker/pubsub/README.md @@ -0,0 +1,15 @@ +# OGC API - Pub/Sub with pygeoapi + +This directory contains the necessary components to deploy an MQTT broker and a pygeoapi +instance with OGC API - Pub/Sub enabled. + +This example is set up to have communication between the following containers: + + - *Mosquitto*: MQTT Broker that publishes notifications. + - *pygeoapi*: Publishes MQTT notifications through the docker network to the broker + +To run: + +```bash +docker compose up -d --build +``` diff --git a/docker/pubsub/docker-compose.yml b/docker/pubsub/docker-compose.yml new file mode 100644 index 0000000..905b232 --- /dev/null +++ b/docker/pubsub/docker-compose.yml @@ -0,0 +1,17 @@ +services: + mqtt: + image: eclipse-mosquitto:2.0 + container_name: mosquitto + ports: + - "1883:1883" + - "8884:8884" + volumes: + - ./mosquitto.conf:/mosquitto/config/mosquitto.conf + + pygeoapi: + build: + context: . + ports: + - "5000:80" + depends_on: + - mqtt diff --git a/docker/pubsub/mosquitto.conf b/docker/pubsub/mosquitto.conf new file mode 100644 index 0000000..fa701a7 --- /dev/null +++ b/docker/pubsub/mosquitto.conf @@ -0,0 +1,16 @@ +persistence true +persistence_location /mosquitto/data/ +log_dest file /mosquitto/log/mosquitto.log +log_dest stdout +log_timestamp_format %Y-%m-%dT%H:%M:%S + +## MQTT Listener +listener 1883 +protocol mqtt + +## WebSockets Listener +listener 8884 +protocol websockets + +# Allow anonymous connections +allow_anonymous true diff --git a/docker/pubsub/pygeoapi.config.yml b/docker/pubsub/pygeoapi.config.yml new file mode 100644 index 0000000..21117e0 --- /dev/null +++ b/docker/pubsub/pygeoapi.config.yml @@ -0,0 +1,157 @@ +# ================================================================= +# +# Authors: Tom Kralidis +# +# 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. +# +# ================================================================= + +server: + bind: + host: 0.0.0.0 + port: 5000 + url: http://localhost:5000 + mimetype: application/json; charset=UTF-8 + encoding: utf-8 + gzip: false + languages: + # First language is the default language + - en-US + - fr-CA + # cors: true + pretty_print: true + limits: + default_items: 20 + max_items: 50 + # templates: + # path: /path/to/Jinja2/templates + # static: /path/to/static/folder # css/js/img + map: + url: https://tile.openstreetmap.org/{z}/{x}/{y}.png + attribution: '© OpenStreetMap contributors' +# manager: +# name: TinyDB +# connection: /tmp/pygeoapi-process-manager.db +# output_dir: /tmp/ + # ogc_schemas_location: /opt/schemas.opengis.net + admin: false # enable admin api + + +pubsub: + name: MQTT + broker: + type: mqtt + url: mqtt://host.docker.internal:1883 + channel: my/service/topic + +logging: + level: ERROR + #logfile: /tmp/pygeoapi.log + +metadata: + identification: + title: + en: pygeoapi default instance + fr: instance par défaut de pygeoapi + description: + en: pygeoapi provides an API to geospatial data + fr: pygeoapi fournit une API aux données géospatiales + keywords: + en: + - geospatial + - data + - api + fr: + - géospatiale + - données + - api + keywords_type: theme + terms_of_service: https://creativecommons.org/licenses/by/4.0/ + url: https://example.org + license: + name: CC-BY 4.0 license + url: https://creativecommons.org/licenses/by/4.0/ + provider: + name: Organization Name + url: https://pygeoapi.io + contact: + name: Lastname, Firstname + position: Position Title + address: Mailing Address + city: City + stateorprovince: Administrative Area + postalcode: Zip or Postal Code + country: Country + phone: +xx-xxx-xxx-xxxx + fax: +xx-xxx-xxx-xxxx + email: you@example.org + url: Contact URL + hours: Mo-Fr 08:00-17:00 + instructions: During hours of service. Off on weekends. + role: pointOfContact + +resources: + canada-metadata: + type: collection + title: + en: Open Canada sample data + fr: Exemple de donn\u00e9es Canada Ouvert + description: + en: Sample metadata records from open.canada.ca + fr: Exemples d'enregistrements de m\u00e9tadonn\u00e9es sur ouvert.canada.ca + keywords: + en: + - canada + - open data + fr: + - canada + - donn\u00e9es ouvertes + links: + - type: text/html + rel: canonical + title: information + href: https://open.canada.ca/en/open-data + hreflang: en-CA + - type: text/html + rel: alternate + title: informations + href: https://ouvert.canada.ca/fr/donnees-ouvertes + hreflang: fr-CA + extents: + spatial: + bbox: [-180,-90,180,90] + crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84 + providers: + - type: record + name: TinyDBCatalogue + data: /sample-records.tinydb + id_field: externalId + time_field: created + title_field: title + editable: true + + hello-world: + type: process + processor: + name: HelloWorld From afc4a1615bb57c8b74fc237da6493a7d227408ab Mon Sep 17 00:00:00 2001 From: Benjamin Webb Date: Thu, 29 Jan 2026 16:10:20 -0700 Subject: [PATCH 2/2] Update dockerfile --- docker/pubsub/Dockerfile | 4 +--- docker/pubsub/pygeoapi.config.yml | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/docker/pubsub/Dockerfile b/docker/pubsub/Dockerfile index 864be80..efb9274 100644 --- a/docker/pubsub/Dockerfile +++ b/docker/pubsub/Dockerfile @@ -1,7 +1,5 @@ FROM geopython/pygeoapi:latest -RUN cp tests/data/open.canada.ca/sample-records.tinydb /sample-records.tinydb -RUN /venv/bin/python3 -m pip install "gunicorn<24" "paho-mqtt" -RUN /venv/bin/python3 -m pip install --target /pygeoapi --no-deps --upgrade https://github.com/geopython/pygeoapi/archive/refs/heads/ogcapi-pubsub.zip +RUN /venv/bin/python3 -m pip install -r /pygeoapi/requirements-pubsub.txt COPY pygeoapi.config.yml /pygeoapi/local.config.yml diff --git a/docker/pubsub/pygeoapi.config.yml b/docker/pubsub/pygeoapi.config.yml index 21117e0..62178c3 100644 --- a/docker/pubsub/pygeoapi.config.yml +++ b/docker/pubsub/pygeoapi.config.yml @@ -145,7 +145,7 @@ resources: providers: - type: record name: TinyDBCatalogue - data: /sample-records.tinydb + data: tests/data/open.canada.ca/sample-records.tinydb id_field: externalId time_field: created title_field: title