Skip to content

Commit

Permalink
Merge pull request #1417 from camptocamp/c2cwsgiutils
Browse files Browse the repository at this point in the history
Updates for c2cwsgiutils 5.0
  • Loading branch information
sbrunner authored Feb 7, 2022
2 parents 94f2e1f + 4ffe90d commit 3669d1e
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
!MANIFEST.in
!tilecloud_chain/*
!docker/run
!development.ini
!production.ini
!gunicorn.conf.py
!.prospector.yaml
!.bandit.yaml
!jsonschema-gentypes.yaml
15 changes: 8 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RUN \

# From c2cwsgiutils

CMD ["c2cwsgiutils-run"]
CMD ["gunicorn", "--paste=/app/production.ini"]

ENV TERM=linux \
LANG=C.UTF-8 \
Expand All @@ -49,7 +49,6 @@ ENV TERM=linux \

ENV C2C_BASE_PATH=/c2c \
C2C_SECRET=c2crulez \
C2CWSGIUTILS_CONFIG=/app/production.ini \
C2C_REDIS_URL= \
C2C_REDIS_SENTINELS= \
C2C_REDIS_TIMEOUT=3 \
Expand All @@ -69,18 +68,22 @@ ENV C2C_BASE_PATH=/c2c \
ENV TILEGENERATION_CONFIGFILE=/etc/tilegeneration/config.yaml \
TILEGENERATION_MAIN_CONFIGFILE=/etc/tilegeneration/config.yaml \
TILEGENERATION_HOSTSFILE=/etc/tilegeneration/hosts.yaml \
C2CWSGI_LOG_LEVEL=WARN \
TILECLOUD_CHAIN_LOG_LEVEL=INFO \
TILECLOUD_LOG_LEVEL=INFO \
C2CWSGIUTILS_LOG_LEVEL=WARN \
GUNICORN_LOG_LEVEL=WARN \
GUNICORN_ACCESS_LOG_LEVEL=INFO \
SQL_LOG_LEVEL=WARN \
OTHER_LOG_LEVEL=WARN \
TILECLOUD_CHAIN_LOG_LEVEL=INFO \
VISIBLE_ENTRY_POINT=/tiles/ \
TILE_NB_THREAD=2 \
METATILE_NB_THREAD=25 \
SERVER_NB_THREAD=10 \
TILE_QUEUE_SIZE=2 \
TILE_CHUNK_SIZE=1 \
TILE_SERVER_LOGLEVEL=quiet \
TILE_MAPCACHE_LOGLEVEL=verbose
TILE_MAPCACHE_LOGLEVEL=verbose \
DEVLOPEMENT=0

EXPOSE 8080

Expand All @@ -95,8 +98,6 @@ RUN \
mv docker/run /usr/bin/ && \
python3 -m compileall -q /app/tilecloud_chain

WORKDIR /etc/tilegeneration/

FROM base as tests

RUN pipenv sync --dev --system --clear
Expand Down
74 changes: 74 additions & 0 deletions development.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
###
# app configuration
# http://docs.pylonsproject.org/projects/pyramid/en/1.6-branch/narr/environment.html
###

[app:app]
use = egg:tilecloud-chain
filter-with = proxy-prefix

pyramid.reload_templates = %(DEVELOPMENT)s
pyramid.debug_authorization = %(DEVELOPMENT)s
pyramid.debug_notfound = %(DEVELOPMENT)s
pyramid.debug_routematch = %(DEVELOPMENT)s
pyramid.debug_templates = %(DEVELOPMENT)s
pyramid.default_locale_name = en

c2c.base_path = /c2c

tilegeneration_configfile = %(TILEGENERATION_CONFIGFILE)s

[pipeline:main]
pipeline = egg:c2cwsgiutils#client_info egg:c2cwsgiutils#profiler egg:c2cwsgiutils#sentry app

[filter:proxy-prefix]
use = egg:PasteDeploy#prefix
prefix = %(VISIBLE_ENTRY_POINT)s

###
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/1.6-branch/narr/logging.html
###

[loggers]
keys = root, c2cwsgi, tilecloud, tilecloud_chain

[handlers]
keys = console, json

[formatters]
keys = generic
format = %(levelname)-5.5s [%(name)s] %(message)s

[logger_root]
level = %(OTHER_LOG_LEVEL)s
handlers = %(LOG_TYPE)s

[logger_tilecloud]
level = %(TILECLOUD_LOG_LEVEL)s
handlers =
qualname = tilecloud

[logger_tilecloud_chain]
level = %(TILECLOUD_CHAIN_LOG_LEVEL)s
handlers =
qualname = tilecloud_chain

[logger_c2cwsgi]
level = %(C2CWSGIUTILS_LOG_LEVEL)s
handlers =
qualname = c2cwsgiutils

[handler_console]
class = StreamHandler
args = (sys.stdout,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s %(name)s %(message)s

[handler_json]
class = c2cwsgiutils.pyramid_logging.JsonLogHandler
args = (sys.stdout,)
level = NOTSET
66 changes: 66 additions & 0 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
###
# app configuration
# https://docs.gunicorn.org/en/stable/settings.html
###

import os

from c2cwsgiutils import get_config_defaults

bind = ":8080"

worker_class = "gthread"
workers = os.environ.get("GUNICORN_WORKERS", 2)
threads = os.environ.get("GUNICORN_THREADS", 10)

preload = "true"

accesslog = "-"
access_log_format = os.environ.get(
"GUNICORN_ACCESS_LOG_FORMAT",
'%(H)s %({Host}i)s %(m)s %(U)s?%(q)s "%(f)s" "%(a)s" %(s)s %(B)s %(D)s %(p)s',
)

###
# logging configuration
# https://docs.python.org/3/library/logging.config.html#logging-config-dictschema
###
logconfig_dict = {
"version": 1,
"root": {
"level": os.environ["OTHER_LOG_LEVEL"],
"handlers": [os.environ["LOG_TYPE"]],
},
"loggers": {
"gunicorn.error": {"level": os.environ["GUNICORN_LOG_LEVEL"]},
"gunicorn.access": {"level": os.environ["GUNICORN_ACCESS_LOG_LEVEL"]},
# "level = INFO" logs SQL queries.
# "level = DEBUG" logs SQL queries and results.
# "level = WARN" logs neither. (Recommended for production systems.)
"sqlalchemy.engine": {"level": os.environ["SQL_LOG_LEVEL"]},
"c2cwsgiutils": {"level": os.environ["C2CWSGIUTILS_LOG_LEVEL"]},
"tilecloud": {"level": os.environ["TILECLOUD_LOG_LEVEL"]},
"tilecloud_chain": {"level": os.environ["TILECLOUD_CHAIN_LOG_LEVEL"]},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "generic",
"stream": "ext://sys.stdout",
},
"json": {
"class": "c2cwsgiutils.pyramid_logging.JsonLogHandler",
"formatter": "generic",
"stream": "ext://sys.stdout",
},
},
"formatters": {
"generic": {
"format": "%(asctime)s [%(process)d] [%(levelname)-5.5s] %(message)s",
"datefmt": "[%Y-%m-%d %H:%M:%S %z]",
"class": "logging.Formatter",
}
},
}

raw_paste_global_conf = ["=".join(e) for e in get_config_defaults().items()]
53 changes: 4 additions & 49 deletions production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# http://docs.pylonsproject.org/projects/pyramid/en/1.6-branch/narr/environment.html
###

[app:main]
[app:app]
use = egg:tilecloud-chain
filter-with = proxy-prefix

Expand All @@ -18,54 +18,9 @@ c2c.base_path = /c2c

tilegeneration_configfile = %(TILEGENERATION_CONFIGFILE)s

[pipeline:main]
pipeline = egg:c2cwsgiutils#client_info egg:c2cwsgiutils#sentry app

[filter:proxy-prefix]
use = egg:PasteDeploy#prefix
prefix = %(VISIBLE_ENTRY_POINT)s

###
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/1.6-branch/narr/logging.html
###

[loggers]
keys = root, c2cwsgi, tilecloud, tilecloud_chain

[handlers]
keys = console, json

[formatters]
keys = generic
format = %(levelname)-5.5s [%(name)s] %(message)s

[logger_root]
level = %(OTHER_LOG_LEVEL)s
handlers = %(LOG_TYPE)s

[logger_tilecloud]
level = %(TILECLOUD_LOG_LEVEL)s
handlers =
qualname = tilecloud

[logger_tilecloud_chain]
level = %(TILECLOUD_CHAIN_LOG_LEVEL)s
handlers =
qualname = tilecloud_chain

[logger_c2cwsgi]
level = %(C2CWSGI_LOG_LEVEL)s
handlers =
qualname = c2cwsgiutils

[handler_console]
class = StreamHandler
args = (sys.stdout,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s %(name)s %(message)s

[handler_json]
class = c2cwsgiutils.pyramid_logging.JsonLogHandler
args = (sys.stdout,)
level = NOTSET

0 comments on commit 3669d1e

Please sign in to comment.