From ec7c2c4dbc4ce3e7b70b3cc79e6093848f214241 Mon Sep 17 00:00:00 2001 From: Benjamin Webb Date: Wed, 3 Jan 2024 11:03:09 -0500 Subject: [PATCH] Create admin docker example per https://github.com/geopython/pygeoapi/pull/1137 --- docker/admin/admin.config.yml | 101 ++++++++++++++++++++++++++++ docker/admin/docker-compose.yml | 46 +++++++++++++ docker/admin/entrypoint.sh | 115 ++++++++++++++++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 docker/admin/admin.config.yml create mode 100644 docker/admin/docker-compose.yml create mode 100755 docker/admin/entrypoint.sh diff --git a/docker/admin/admin.config.yml b/docker/admin/admin.config.yml new file mode 100644 index 0000000..9be4b91 --- /dev/null +++ b/docker/admin/admin.config.yml @@ -0,0 +1,101 @@ +# ================================================================= +# +# Authors: Benjamin Webb +# +# Copyright (c) 2023 Benjamin Webb +# +# 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: ${HOST} + port: ${PORT} + url: ${HOST}:${PORT} + admin: true + mimetype: application/json; charset=UTF-8 + encoding: utf-8 + languages: + - en-US + cors: true + pretty_print: true + limit: 10 + map: + url: https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png + attribution: Wikimedia + maps | Map data © OpenStreetMap + contributors + # manager: + # name: TinyDB + # connection: /tmp/pygeoapi-process-manager.db + # output_dir: /tmp/ + # ogc_schemas_location: /opt/schemas.opengis.net + # templates: + # path: /path/to/Jinja2/templates + # static: /path/to/static/folder # css/js/img + +logging: + level: DEBUG + #logfile: /tmp/pygeoapi.log + +metadata: + identification: + title: + en: pygeoapi default instance + description: + en: pygeoapi provides an API to geospatial data + keywords: + en: + - geospatial + - data + - api + keywords_type: theme + terms_of_service: https://creativecommons.org/licenses/by/4.0/ + url: http://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: Hours of Service + instructions: During hours of service. Off on weekends. + role: pointOfContact + +resources: + hello-world: + type: process + processor: + name: ${PYGEOAPI_PROCESS} diff --git a/docker/admin/docker-compose.yml b/docker/admin/docker-compose.yml new file mode 100644 index 0000000..b43c9f3 --- /dev/null +++ b/docker/admin/docker-compose.yml @@ -0,0 +1,46 @@ +# ================================================================= +# +# Authors: Benjamin Webb +# +# Copyright (c) 2023 Benjamin Webb +# +# 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" + +services: + + pygeoapi: + image: geopython/pygeoapi:latest + build: + context: ../../.. + volumes: + - ./admin.config.yml:/pygeoapi/local.config.yml + - ./entrypoint.sh:/entrypoint.sh + environment: + - HOST=http://localhost + - PORT=5000 + - PYGEOAPI_PROCESS=HelloWorld + ports: + - 5000:80 diff --git a/docker/admin/entrypoint.sh b/docker/admin/entrypoint.sh new file mode 100755 index 0000000..88ae996 --- /dev/null +++ b/docker/admin/entrypoint.sh @@ -0,0 +1,115 @@ +#!/bin/bash +# ================================================================= +# +# Authors: Just van den Broecke +# +# Copyright (c) 2019 Just van den Broecke +# +# 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. +# +# ================================================================= + +# pygeoapi entry script + +echo "START /entrypoint.sh" + +set +e + +export PYGEOAPI_HOME=/pygeoapi +export PYGEOAPI_CONFIG="${PYGEOAPI_HOME}/local.config.yml" +export PYGEOAPI_OPENAPI="${PYGEOAPI_HOME}/local.openapi.yml" + +# gunicorn env settings with defaults +SCRIPT_NAME=${SCRIPT_NAME:=/} +CONTAINER_NAME=${CONTAINER_NAME:=pygeoapi} +CONTAINER_HOST=${CONTAINER_HOST:=0.0.0.0} +CONTAINER_PORT=${CONTAINER_PORT:=80} +WSGI_WORKERS=${WSGI_WORKERS:=4} +WSGI_WORKER_TIMEOUT=${WSGI_WORKER_TIMEOUT:=6000} +WSGI_WORKER_CLASS=${WSGI_WORKER_CLASS:=gevent} + +# What to invoke: default is to run gunicorn server +entry_cmd=${1:-run} + +# Shorthand +function error() { + echo "ERROR: $@" + exit -1 +} + +# Workdir +cd ${PYGEOAPI_HOME} + +# Lock all python files (for gunicorn hot reload) +find . -type f -name "*.py" | xargs chmod -R 0444 + +echo "Trying to generate openapi.yml" +pygeoapi openapi generate ${PYGEOAPI_CONFIG} --output-file ${PYGEOAPI_OPENAPI} + +[[ $? -ne 0 ]] && error "openapi.yml could not be generated ERROR" + +echo "openapi.yml generated continue to pygeoapi" + +case ${entry_cmd} in + # Run Unit tests + test) + for test_py in $(ls tests/test_*.py) + do + # Skip tests requireing backend server or libs installed + case ${test_py} in + tests/test_elasticsearch__provider.py) + ;& + tests/test_sensorthings_provider.py) + ;& + tests/test_postgresql_provider.py) + ;& + tests/test_mongo_provider.py) + echo "Skipping: ${test_py}" + ;; + *) + python3 -m pytest ${test_py} + ;; + esac + done + ;; + + # Run pygeoapi server + run) + # SCRIPT_NAME should not have value '/' + [[ "${SCRIPT_NAME}" = '/' ]] && export SCRIPT_NAME="" && echo "make SCRIPT_NAME empty from /" + + echo "Start gunicorn name=${CONTAINER_NAME} on ${CONTAINER_HOST}:${CONTAINER_PORT} with ${WSGI_WORKERS} workers and SCRIPT_NAME=${SCRIPT_NAME}" + exec gunicorn --workers ${WSGI_WORKERS} \ + --worker-class=${WSGI_WORKER_CLASS} \ + --timeout ${WSGI_WORKER_TIMEOUT} \ + --name=${CONTAINER_NAME} \ + --bind ${CONTAINER_HOST}:${CONTAINER_PORT} \ + --reload \ + --reload-extra-file ${PYGEOAPI_CONFIG} \ + pygeoapi.flask_app:APP + ;; + *) + error "unknown command arg: must be run (default) or test" + ;; +esac + +echo "END /entrypoint.sh"