|
2 | 2 | FROM registry.access.redhat.com/ubi9/python-312 AS appbase |
3 | 3 | # ============================== |
4 | 4 |
|
| 5 | +# Branch or tag used to pull python-uwsgi-common. |
| 6 | +ARG UWSGI_COMMON_REF="main" |
| 7 | + |
5 | 8 | USER root |
6 | 9 | WORKDIR /app |
7 | 10 |
|
8 | 11 | ENV PYTHONDONTWRITEBYTECODE 1 |
9 | 12 | ENV PYTHONUNBUFFERED 1 |
10 | 13 |
|
11 | | -COPY --chown=default:root requirements*.txt . |
| 14 | +COPY requirements.txt . |
| 15 | +COPY requirements-prod.txt . |
12 | 16 |
|
13 | | -RUN dnf update -y && dnf install -y \ |
| 17 | +RUN dnf update -y \ |
| 18 | + && dnf install -y \ |
14 | 19 | nmap-ncat \ |
15 | 20 | gettext \ |
16 | 21 | && pip install -U pip setuptools wheel \ |
17 | 22 | && pip install --no-cache-dir -r requirements.txt \ |
18 | 23 | && 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/ \ |
22 | 24 | && dnf clean all |
23 | 25 |
|
| 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 | + |
24 | 39 | ENTRYPOINT ["/app/.docker/docker-entrypoint.sh"] |
25 | | -EXPOSE 8000/tcp |
26 | 40 |
|
27 | 41 | # ============================== |
28 | 42 | FROM appbase AS development |
29 | 43 | # ============================== |
30 | | - |
31 | | -COPY --chown=default:root requirements-dev.txt . |
| 44 | +COPY requirements-dev.txt . |
32 | 45 | RUN pip install --no-cache-dir -r requirements-dev.txt |
33 | 46 |
|
34 | 47 | ENV DEV_SERVER=True |
| 48 | +ENV PIP_TOOLS_CACHE_DIR="/tmp/pip-tools-cache" |
35 | 49 |
|
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 |
37 | 53 |
|
38 | | -USER root |
| 54 | +COPY --chown=appuser:root . . |
| 55 | + |
| 56 | +USER appuser |
| 57 | +EXPOSE 8000/tcp |
39 | 58 |
|
40 | 59 | # ============================== |
41 | 60 | FROM appbase AS staticbuilder |
42 | 61 | # ============================== |
43 | 62 |
|
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" \ |
47 | 68 | python manage.py collectstatic --noinput |
48 | 69 |
|
49 | 70 | # ============================== |
50 | 71 | FROM appbase AS production |
51 | 72 | # ============================== |
52 | 73 |
|
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 . . |
55 | 76 |
|
56 | 77 | USER default |
| 78 | +EXPOSE 8000/tcp |
0 commit comments