Skip to content

Commit 39ab7d1

Browse files
committed
feat: update Dockerfile, use common uwsgi config
- Make Dockerfile more in line with other projects' Dockerfiles - Use City of Helsinki common uwsgi configurations Refs: RATYK-199
1 parent 0709e55 commit 39ab7d1

2 files changed

Lines changed: 41 additions & 15 deletions

File tree

.docker/Dockerfile

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,77 @@
22
FROM registry.access.redhat.com/ubi9/python-312 AS appbase
33
# ==============================
44

5+
# Branch or tag used to pull python-uwsgi-common.
6+
ARG UWSGI_COMMON_REF="main"
7+
58
USER root
69
WORKDIR /app
710

811
ENV PYTHONDONTWRITEBYTECODE 1
912
ENV PYTHONUNBUFFERED 1
1013

11-
COPY --chown=default:root requirements*.txt .
14+
COPY requirements.txt .
15+
COPY requirements-prod.txt .
1216

13-
RUN dnf update -y && dnf install -y \
17+
RUN dnf update -y \
18+
&& dnf install -y \
1419
nmap-ncat \
1520
gettext \
1621
&& pip install -U pip setuptools wheel \
1722
&& pip install --no-cache-dir -r requirements.txt \
1823
&& pip install --no-cache-dir -r requirements-prod.txt \
19-
&& mkdir -p /usr/local/lib/uwsgi/plugins \
20-
&& uwsgi --build-plugin https://github.com/City-of-Helsinki/uwsgi-sentry \
21-
&& mv sentry_plugin.so /usr/local/lib/uwsgi/plugins/ \
2224
&& dnf clean all
2325

26+
# Build and copy specific python-uwsgi-common files.
27+
ADD https://github.com/City-of-Helsinki/python-uwsgi-common/archive/"${UWSGI_COMMON_REF}".tar.gz /usr/src/
28+
RUN mkdir -p /usr/src/python-uwsgi-common \
29+
&& tar --strip-components=1 -xzf /usr/src/"${UWSGI_COMMON_REF}".tar.gz -C /usr/src/python-uwsgi-common \
30+
&& mkdir /etc/uwsgi \
31+
&& cp /usr/src/python-uwsgi-common/uwsgi-base.ini /etc/uwsgi/ \
32+
&& uwsgi --build-plugin /usr/src/python-uwsgi-common \
33+
&& rm -rf /usr/src/"${UWSGI_COMMON_REF}".tar.gz \
34+
&& rm -rf /usr/src/python-uwsgi-common \
35+
&& uwsgi --build-plugin https://github.com/City-of-Helsinki/uwsgi-sentry \
36+
&& mkdir -p /usr/local/lib/uwsgi/plugins \
37+
&& mv sentry_plugin.so /usr/local/lib/uwsgi/plugins
38+
2439
ENTRYPOINT ["/app/.docker/docker-entrypoint.sh"]
25-
EXPOSE 8000/tcp
2640

2741
# ==============================
2842
FROM appbase AS development
2943
# ==============================
30-
31-
COPY --chown=default:root requirements-dev.txt .
44+
COPY requirements-dev.txt .
3245
RUN pip install --no-cache-dir -r requirements-dev.txt
3346

3447
ENV DEV_SERVER=True
48+
ENV PIP_TOOLS_CACHE_DIR="/tmp/pip-tools-cache"
3549

36-
COPY --chown=default:root . .
50+
RUN groupadd -g 1000 appuser \
51+
&& useradd -u 1000 -g appuser -ms /bin/bash appuser \
52+
&& chown -R appuser:root /app
3753

38-
USER root
54+
COPY --chown=appuser:root . .
55+
56+
USER appuser
57+
EXPOSE 8000/tcp
3958

4059
# ==============================
4160
FROM appbase AS staticbuilder
4261
# ==============================
4362

44-
ENV STATIC_ROOT=/app/static
45-
COPY --chown=default:root . .
46-
RUN SECRET_KEY="only-used-for-collectstatic" ENABLE_ADMIN_APP="True" \
63+
ENV STATIC_ROOT="/app/static"
64+
COPY . .
65+
66+
RUN mkdir -p tirehtoori/static \
67+
&& SECRET_KEY="only-used-for-collectstatic" ENABLE_ADMIN_APP="True" \
4768
python manage.py collectstatic --noinput
4869

4970
# ==============================
5071
FROM appbase AS production
5172
# ==============================
5273

53-
COPY --from=staticbuilder --chown=default:root /app/static /app/static
54-
COPY --chown=default:root . .
74+
COPY --from=staticbuilder /app/static /app/static
75+
COPY . .
5576

5677
USER default
78+
EXPOSE 8000/tcp

.docker/uwsgi.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
[uwsgi]
22
# https://uwsgi-docs.readthedocs.io/en/latest/Options.html
3+
strict = true # Fail if any option is unknown
4+
5+
# Use base ini file to configure common settings
6+
include = /etc/uwsgi/uwsgi-base.ini
37

48
http = :8000
59
http-timeout = 60

0 commit comments

Comments
 (0)