Skip to content

Commit

Permalink
chore: add user info in uwsgi request logs
Browse files Browse the repository at this point in the history
Refs KER-367
  • Loading branch information
danipran committed Jun 5, 2024
1 parent abaef4c commit 2541fdb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,31 @@ ENV STATIC_ROOT /srv/static
# while in Docker. Maybe the buffer is larger?
ENV PYTHONUNBUFFERED True

COPY --chown=kerrokantasi:kerrokantasi requirements.txt .
COPY --chown=kerrokantasi:kerrokantasi requirements-prod.txt .

# less & netcat-openbsd are there for in-container manual debugging
# kerrokantasi needs gdal
RUN apt-get update && apt-get install -y postgresql-client less netcat-openbsd gettext locales gdal-bin python3-gdal

# we need the Finnish locale built
RUN sed -i 's/^# *\(fi_FI.UTF-8\)/\1/' /etc/locale.gen
RUN locale-gen

RUN pip install --upgrade pip setuptools wheel && \
pip install --no-cache-dir uwsgi
RUN apt-get update \
&& apt-get install -y \
postgresql-client \
less \
netcat-openbsd \
gettext \
locales \
gdal-bin \
python3-gdal \
# Build finnish locale
&& sed -i 's/^# *\(fi_FI.UTF-8\)/\1/' /etc/locale.gen \
&& locale-gen \
&& pip install --upgrade pip setuptools wheel \
&& pip install --no-cache-dir -r ./requirements.txt \
&& pip install --no-cache-dir -r ./requirements-prod.txt

# Sentry CLI for sending events from non-Python processes to Sentry
# eg. https://docs.sentry.io/cli/send-event/#bash-hook
RUN curl -sL https://sentry.io/get-cli/ | bash

# Copy requirements files to image for preloading dependencies
# in their own layer
COPY requirements.txt ./

# deploy/requirements.txt must reference the base requirements
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

# Statics are kept inside container image for serving using whitenoise
Expand Down
5 changes: 5 additions & 0 deletions deploy/uwsgi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ uwsgi:
ignore-sigpipe: true
ignore-write-errors: true
disable-write-exception: true

logger-req: stdio
log-format: '"remote_addr": "%(addr)", "x_forwarded_for":"%(var.HTTP_X_FORWARDED_FOR)", "request_id":"%(var.HTTP_X_REQUEST_ID)", "remote_user":"%(user)", "bytes_sent":%(size), "request_time":%(secs), "status":%(status), "host":"%(host)", "request_proto":"%(proto)", "path":"%(uri)", "request_length":%(cl), "http_referer":"%(referer)", "http_user_agent":"%(uagent)"'
log-req-encoder: format {"time":"${strftime:%%Y:%%m:%%d %%H:%%M:%%S}", "source":"uwsgi-req", ${msg}}
log-req-encoder: nl

0 comments on commit 2541fdb

Please sign in to comment.