diff --git a/README.md b/README.md index 8e4fabd..b57dae8 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,58 @@ -MapProxy service application -============================ +# MapProxy service application Basic MapProxy service used internally by the Department of Biodiversity, Conservation and Attractions. -# Docker image +## Development -To build a new Docker image from the `Dockerfile`: +Development of the containerised application is based on the +installation instructions in the MapProxy documentation: + - docker image build -t ghcr.io/dbca-wa/mapproxy . +Additional reference can be made to the GitHub project Dockerfile: + -# Running Docker container +The recommended way to set up this project for development is using +[Poetry](https://python-poetry.org/docs/) to install and manage a virtual Python +environment. With Poetry installed, change into the project directory and run: -When running this image as a container, provide a configuration file -mounted at `/app/config/mapproxy.yaml` (this can be a bind-mounted -local file or a ConfigMap in Kubernetes). + poetry install -Example using a local bind-mount file: +Activate the virtualenv like so: - docker container run -p 8080:8080 -v $PWD/mapproxy.yaml:/app/config/mapproxy.yaml ghcr.io/dbca-wa/mapproxy + poetry shell -# Development +To run Python commands in the activated virtualenv, thereafter run them like so: -Development of the containerised application is based on the -installation instructions in the MapProxy documentation: -https://mapproxy.github.io/mapproxy/latest/install.html + gunicorn --config gunicorn.py wsgi -Additional reference can be made to the GitHub project Dockerfile: -https://github.com/mapproxy/mapproxy/blob/master/docker/Dockerfile +Manage new or updating project dependencies with Poetry also, like so: + + poetry add newpackage==1.0 + +## MapProxy configuration + +To configure the local MapProxy server, create a `config` directory in the project directory +(relative to `wsgi.py`) and create the following configuration files in there: + +- mapproxy.yaml +- logging.ini +- seed.yaml (optional) + +MapProxy configuration reference: + +## Docker image + +To build a new Docker image from the `Dockerfile`: + + docker image build -t ghcr.io/dbca-wa/mapproxy . + +## Running Docker container + +When running this image as a container, provide a configuration file +mounted at `/app/config/mapproxy.yaml` (this can be a bind-mounted +local file or a ConfigMap in Kubernetes). -# MapProxy configuration +Example using local configuration files bind-mounted into the container: -Reference: https://mapproxy.github.io/mapproxy/latest/configuration.html + docker container run -p 8080:8080 -v $PWD/config/mapproxy.yaml:/app/config/mapproxy.yaml -v $PWD/config/logging.ini:/app/config/logging.ini ghcr.io/dbca-wa/mapproxy diff --git a/kustomize/overlays/prod/kustomization.yaml b/kustomize/overlays/prod/kustomization.yaml index ed70391..2fc7490 100644 --- a/kustomize/overlays/prod/kustomization.yaml +++ b/kustomize/overlays/prod/kustomization.yaml @@ -10,6 +10,9 @@ configMapGenerator: files: - mapproxy.yaml - seed.yaml + - logging.ini +generatorOptions: + disableNameSuffixHash: true labels: - includeSelectors: true pairs: diff --git a/kustomize/overlays/prod/logging.ini b/kustomize/overlays/prod/logging.ini new file mode 100644 index 0000000..a587a8d --- /dev/null +++ b/kustomize/overlays/prod/logging.ini @@ -0,0 +1,33 @@ +[loggers] +keys=root,source_requests + +[handlers] +keys=mapproxy,source_requests + +[formatters] +keys=default,requests + +[logger_root] +level=INFO +handlers=mapproxy + +[logger_source_requests] +level=INFO +qualname=mapproxy.source.request +# propagate=0 -> do not show up in logger_root +propagate=0 +handlers=source_requests + +[handler_mapproxy] +class=StreamHandler +formatter=default + +[handler_source_requests] +class=StreamHandler +formatter=requests + +[formatter_default] +format=%(asctime)s - %(levelname)s - %(name)s - %(message)s + +[formatter_requests] +format=[%(asctime)s] %(message)s diff --git a/kustomize/overlays/uat/kustomization.yaml b/kustomize/overlays/uat/kustomization.yaml index 15d00fd..e9a309c 100644 --- a/kustomize/overlays/uat/kustomization.yaml +++ b/kustomize/overlays/uat/kustomization.yaml @@ -10,6 +10,9 @@ configMapGenerator: files: - mapproxy.yaml - seed.yaml + - logging.ini +generatorOptions: + disableNameSuffixHash: true labels: - includeSelectors: true pairs: diff --git a/kustomize/overlays/uat/logging.ini b/kustomize/overlays/uat/logging.ini new file mode 100644 index 0000000..a587a8d --- /dev/null +++ b/kustomize/overlays/uat/logging.ini @@ -0,0 +1,33 @@ +[loggers] +keys=root,source_requests + +[handlers] +keys=mapproxy,source_requests + +[formatters] +keys=default,requests + +[logger_root] +level=INFO +handlers=mapproxy + +[logger_source_requests] +level=INFO +qualname=mapproxy.source.request +# propagate=0 -> do not show up in logger_root +propagate=0 +handlers=source_requests + +[handler_mapproxy] +class=StreamHandler +formatter=default + +[handler_source_requests] +class=StreamHandler +formatter=requests + +[formatter_default] +format=%(asctime)s - %(levelname)s - %(name)s - %(message)s + +[formatter_requests] +format=[%(asctime)s] %(message)s diff --git a/wsgi.py b/wsgi.py index 5098f8d..377973b 100644 --- a/wsgi.py +++ b/wsgi.py @@ -3,7 +3,7 @@ from mapproxy.wsgiapp import make_wsgi_app # Configure logging. -logging.config.fileConfig("config/log.ini") +logging.config.fileConfig("config/logging.ini") # Set the logging level for all azure-* libraries (the azure-storage-blob library uses this one). # Reference: https://learn.microsoft.com/en-us/azure/developer/python/sdk/azure-sdk-logging