diff --git a/docker/examples/README.md b/docker/examples/README.md index e46e2fa..823b2e3 100644 --- a/docker/examples/README.md +++ b/docker/examples/README.md @@ -5,7 +5,9 @@ This folder contains the sub-folders: - simple - elastic - sensorthings +- mongo The [simple](simple) example will run pygeoapi with Docker with your local config. The [elastic](elastic) example demonstrates a docker compose configuration to run pygeoapi with local ElasticSearch backend. +The [mongo](mongo) example demonstrates a docker compose configuration to run pygeoapi with local MongoDB backend. The [sensorthings](sensorthings) example demonstrates various pygeoapi implementations of SensorThings API endpoints. diff --git a/docker/examples/mongo/README.md b/docker/examples/mongo/README.md new file mode 100644 index 0000000..6e67b21 --- /dev/null +++ b/docker/examples/mongo/README.md @@ -0,0 +1,19 @@ +# pygeoapi with MongoDB + +These folders contain a Docker Compose configuration necessary to setup a minimal +`pygeoapi` server that uses a local MongoDB backend service. Mongo Express is also provided, for convenience. + +This config is only for local development and testing. + +## MongoDB + +- official MongoDB: **5.0.3** on **Ubuntu Focal** +- ports **27017** + +## Building and Running + +These composition does not require building any images. Run the [Docker compose file](docker-compose.yml) in localhost: + +``` +docker-compose up +``` diff --git a/docker/examples/mongo/docker-compose.yml b/docker/examples/mongo/docker-compose.yml new file mode 100644 index 0000000..ce88efd --- /dev/null +++ b/docker/examples/mongo/docker-compose.yml @@ -0,0 +1,80 @@ +# ================================================================= +# +# Authors: Joana Simoes > +# +# Copyright (c) 2021 Joana Simoes +# +# 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. +# +# ================================================================= + +version: '3.3' + +services: + pygeoapi: + image: geopython/pygeoapi:latest + + container_name: pygeoapi_mongo + + entrypoint: + - /mongo-entrypoint.sh + + ports: + - 5000:80 + + volumes: + - ./pygeoapi/docker.config.yml:/pygeoapi/local.config.yml + - ./pygeoapi/mongo-entrypoint.sh:/mongo-entrypoint.sh + - ./pygeoapi/wait-for-mongo.sh:/wait-for-mongo.sh + - datavolume:/pygeoapi/tests/data + links: + - mongo + + depends_on: + - mongo + + mongo: + image: mongo:5.0.3 + container_name: mongo + ports: + - 27017:27017 + volumes: + - ./docker-entrypoint-initdb.d/add_data.sh:/docker-entrypoint-initdb.d/add_data.sh:ro + - datavolume:/pygeoapi/tests/data + environment: + MONGO_INITDB_DATABASE: pop_places + + mongo-express: + image: mongo-express + restart: always + container_name: mongo_express + links: + - mongo + depends_on: + - mongo + ports: + - 8081:8081 + + +volumes: + datavolume: {} + diff --git a/docker/examples/mongo/docker-entrypoint-initdb.d/add_data.sh b/docker/examples/mongo/docker-entrypoint-initdb.d/add_data.sh new file mode 100755 index 0000000..743643b --- /dev/null +++ b/docker/examples/mongo/docker-entrypoint-initdb.d/add_data.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# ================================================================= +# +# Authors: Joana Simoes +# +# Copyright (c) 2021 Joana Simoes +# +# 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. +# +# ================================================================= + +jq --compact-output ".features" /pygeoapi/tests/data/ne_110m_populated_places_simple.geojson > /tmp/output.geojson; + +mongoimport --db pop_places -c places --file "/tmp/output.geojson" --jsonArray diff --git a/docker/examples/mongo/pygeoapi/docker.config.yml b/docker/examples/mongo/pygeoapi/docker.config.yml new file mode 100644 index 0000000..aa817c2 --- /dev/null +++ b/docker/examples/mongo/pygeoapi/docker.config.yml @@ -0,0 +1,118 @@ +# ================================================================= +# +# Authors: Joana Simoes +# +# Copyright (c) 2021 Joana Simoes +# +# 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. +# +# ================================================================= + + +# Default config for base Docker Image, override via DockerVolume +# mapping with your own config. +server: + bind: + host: 0.0.0.0 + port: 80 + url: http://localhost:5000 + mimetype: application/json; charset=UTF-8 + encoding: utf-8 + language: en-US + cors: true + pretty_print: true + limit: 10 + # templates: /path/to/templates + map: + url: https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png + attribution: 'Wikimedia maps | Map data © OpenStreetMap contributors' + ogc_schemas_location: /schemas.opengis.net + +logging: + level: ERROR + #logfile: /tmp/pygeoapi.log + +metadata: + identification: + title: pygeoapi Demo instance - running latest GitHub version + description: pygeoapi provides an API to geospatial data + keywords: + - geospatial + - data + - api + keywords_type: theme + terms_of_service: https://creativecommons.org/licenses/by/4.0/ + url: https://github.com/geopython/pygeoapi + license: + name: CC-BY 4.0 license + url: https://creativecommons.org/licenses/by/4.0/ + provider: + name: pygeoapi Development Team + url: https://pygeoapi.io + contact: + name: Kralidis, Tom + position: Lead Dev + address: Mailing Address + city: City + stateorprovince: Administrative Area + postalcode: Zip or Postal Code + country: Canada + phone: +xx-xxx-xxx-xxxx + fax: +xx-xxx-xxx-xxxx + email: you@example.org + url: Contact URL + hours: Hours of Service + instructions: During hours of service. Off on weekends. + role: pointOfContact + +resources: + ne_110m_populated_places_simple: + type: collection + title: ne_110m_populated_places_simple + description: Populated places of the world + keywords: + - Population, places + links: + - type: text/html + rel: canonical + title: information + href: http://www.naturalearthdata.com/ + hreflang: en-US + extents: + spatial: + bbox: [-180,-90,180,90] + crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84 + temporal: + begin: 2011-11-11 + end: null # or empty (either means open ended) + providers: + - type: feature + name: MongoDB + data: mongodb://mongo:27017/pop_places + collection: places + id_field: id + + + hello-world: + type: process + processor: + name: HelloWorld diff --git a/docker/examples/mongo/pygeoapi/wait-for-mongo.sh b/docker/examples/mongo/pygeoapi/wait-for-mongo.sh new file mode 100755 index 0000000..0c92962 --- /dev/null +++ b/docker/examples/mongo/pygeoapi/wait-for-mongo.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# ================================================================= +# +# Authors: Joana Simoes +# +# Copyright (c) 2021 Joana Simoes +# +# 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. +# +# ================================================================= + +set -e +cmd="$@" + +: ${MONGO_HOST:=mongo} +: ${MONGO_PORT:=27017} + +until nc -z $MONGO_HOST $MONGO_PORT +do + echo "Waiting for Mongo ($MONGO_HOST:$MONGO_PORT) to start..." + sleep 0.5 +done + +echo "Mongo has started!" + +exec $cmd +