Skip to content

Commit

Permalink
Update Kustomize definitions (logging, generatorOptions), update README.
Browse files Browse the repository at this point in the history
  • Loading branch information
ropable committed Nov 5, 2024
1 parent 231adbb commit 495a50c
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 20 deletions.
62 changes: 43 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
<https://mapproxy.github.io/mapproxy/latest/install.html>

docker image build -t ghcr.io/dbca-wa/mapproxy .
Additional reference can be made to the GitHub project Dockerfile:
<https://github.com/mapproxy/mapproxy/blob/master/docker/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: <https://mapproxy.github.io/mapproxy/latest/configuration.html>

## 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
3 changes: 3 additions & 0 deletions kustomize/overlays/prod/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ configMapGenerator:
files:
- mapproxy.yaml
- seed.yaml
- logging.ini
generatorOptions:
disableNameSuffixHash: true
labels:
- includeSelectors: true
pairs:
Expand Down
33 changes: 33 additions & 0 deletions kustomize/overlays/prod/logging.ini
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions kustomize/overlays/uat/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ configMapGenerator:
files:
- mapproxy.yaml
- seed.yaml
- logging.ini
generatorOptions:
disableNameSuffixHash: true
labels:
- includeSelectors: true
pairs:
Expand Down
33 changes: 33 additions & 0 deletions kustomize/overlays/uat/logging.ini
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 495a50c

Please sign in to comment.