|
| 1 | +--- |
| 2 | +myst: |
| 3 | + html_meta: |
| 4 | + "description": "Plone 6 Docker image recipes" |
| 5 | + "property=og:description": "Plone 6 Docker image recipes" |
| 6 | + "property=og:title": "Plone 6 image recipes" |
| 7 | + "keywords": "Plone 6, install, installation, Docker, containers, official images" |
| 8 | +--- |
| 9 | + |
| 10 | +# Docker recipes |
| 11 | + |
| 12 | +This chapter offers some useful recipes when working with Plone containers. |
| 13 | + |
| 14 | + |
| 15 | +## Remove access log from Plone containers |
| 16 | + |
| 17 | +When you generate a project using [Cookieplone](https://github.com/plone/cookieplone), it creates Plone containers for your project that are based on the official [`plone/plone-backend`](https://github.com/plone/plone-backend) images. |
| 18 | + |
| 19 | +When you run your container or the official `plone/plone-backend` image with logging, the output mixes both the event log and the access log, making it hard to follow the logs you may have added to your application. |
| 20 | +In such cases, you may have a Docker Compose setup with several components including a proxy server that already provides access logs. |
| 21 | +Instead of duplicating the logging output, it is common to remove the access logging from the Plone container. |
| 22 | + |
| 23 | +To do so, create a custom {file}`zope.ini` file in your project's {file}`backend` folder with the following content. |
| 24 | + |
| 25 | +```{code-block} ini |
| 26 | +:emphasize-lines: 17-20 |
| 27 | +
|
| 28 | +[app:zope] |
| 29 | +use = egg:Zope#main |
| 30 | +zope_conf = %(here)s/%(config_file)s |
| 31 | +
|
| 32 | +[server:main] |
| 33 | +use = egg:waitress#main |
| 34 | +host = 0.0.0.0 |
| 35 | +port = 8080 |
| 36 | +threads = 2 |
| 37 | +clear_untrusted_proxy_headers = false |
| 38 | +max_request_body_size = 1073741824 |
| 39 | +
|
| 40 | +[filter:translogger] |
| 41 | +use = egg:Paste#translogger |
| 42 | +setup_console_handler = False |
| 43 | +
|
| 44 | +[pipeline:main] |
| 45 | +pipeline = |
| 46 | + egg:Zope#httpexceptions |
| 47 | + zope |
| 48 | +
|
| 49 | +[loggers] |
| 50 | +keys = root, waitress.queue, waitress, wsgi |
| 51 | +
|
| 52 | +[handlers] |
| 53 | +keys = accesslog, eventlog |
| 54 | +
|
| 55 | +[formatters] |
| 56 | +keys = generic, message |
| 57 | +
|
| 58 | +[formatter_generic] |
| 59 | +format = %(asctime)s %(levelname)s [%(name)s:%(lineno)s][%(threadName)s] %(message)s |
| 60 | +datefmt = %Y-%m-%d %H:%M:%S |
| 61 | +
|
| 62 | +[formatter_message] |
| 63 | +format = %(message)s |
| 64 | +
|
| 65 | +[logger_root] |
| 66 | +level = INFO |
| 67 | +handlers = eventlog |
| 68 | +
|
| 69 | +[logger_waitress.queue] |
| 70 | +level = INFO |
| 71 | +handlers = eventlog |
| 72 | +qualname = waitress.queue |
| 73 | +propagate = 0 |
| 74 | +
|
| 75 | +[logger_waitress] |
| 76 | +level = INFO |
| 77 | +handlers = eventlog |
| 78 | +qualname = waitress |
| 79 | +propagate = 0 |
| 80 | +
|
| 81 | +[logger_wsgi] |
| 82 | +level = WARN |
| 83 | +handlers = accesslog |
| 84 | +qualname = wsgi |
| 85 | +propagate = 0 |
| 86 | +
|
| 87 | +[handler_accesslog] |
| 88 | +class = StreamHandler |
| 89 | +args = (sys.stdout,) |
| 90 | +level = INFO |
| 91 | +formatter = message |
| 92 | +
|
| 93 | +[handler_eventlog] |
| 94 | +class = StreamHandler |
| 95 | +args = (sys.stderr,) |
| 96 | +level = INFO |
| 97 | +formatter = generic |
| 98 | +``` |
| 99 | + |
| 100 | +Comparing this file with the [original `zope.ini` file](https://github.com/plone/plone-backend/blob/6.1.x/skeleton/etc/zope.ini) that comes with the `plone/plone-backend` container, you may realize that the only change is the `translogger` configuration was removed from the `pipeline` section. |
| 101 | +This [`translogger` middleware produces logs in the Apache Combined Log Format](https://docs.pylonsproject.org/projects/waitress/en/latest/logging.html). |
| 102 | +The above configuration removes it from the setup. |
| 103 | + |
| 104 | +After adding the {file}`zope.ini` file in your project, adjust the {file}`Dockerfile` by inserting the command `COPY zope.ini etc/` before the `RUN` command as highlighted below. |
| 105 | +This new command copies the {file}`zope.ini` file into the container. |
| 106 | + |
| 107 | +```{code-block} dockerfile |
| 108 | +:emphasize-lines: 4 |
| 109 | +
|
| 110 | +# Add local code |
| 111 | +COPY scripts/ scripts/ |
| 112 | +COPY . src |
| 113 | +COPY zope.ini etc/ |
| 114 | +
|
| 115 | +# Install local requirements and pre-compile mo files |
| 116 | +RUN <<EOT |
| 117 | +``` |
| 118 | + |
| 119 | +After making these changes, build the project container as usual. |
| 120 | +It will no longer output the access log, but will continue to output the event log. |
0 commit comments