This repository has been archived by the owner on Aug 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
84 lines (56 loc) · 2.02 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
FROM public.ecr.aws/docker/library/python:3.9.5-slim-buster AS requirements_builder
WORKDIR /app
COPY ./deployment/.ssh/ /root/.ssh/
RUN chmod 400 /root/.ssh/id_rsa
COPY --chown=1000:1000 docker-entrypoint.sh .
COPY requirements/requirements.txt /tmp/requirements.txt
ENV BUILD_DEPENDENCIES="\
gcc \
make \
libsasl2-dev \
git \
openssh-client"
RUN set -ex \
&& apt-get update \
&& apt-get install -y --no-install-recommends ${BUILD_DEPENDENCIES} libldap2-dev libmariadbclient-dev curl iputils-ping vim-tiny libpango-1.0-0 libpangoft2-1.0-0 libpangocairo-1.0-0\
&& python -m venv /venv \
&& . /venv/bin/activate \
&& pip install -U pip \
&& pip install --no-deps -r /tmp/requirements.txt \
&& apt-get remove -y ${BUILD_DEPENDENCIES} \
&& apt-get autoremove -y
ENTRYPOINT [ "/app/docker-entrypoint.sh" ]
FROM requirements_builder AS dev
COPY requirements/requirements_test.txt /tmp/requirements_test.txt
RUN set -ex \
&& apt-get update \
&& apt-get install -y --no-install-recommends ${BUILD_DEPENDENCIES}
RUN . /venv/bin/activate \
&& pip install --no-deps -r /tmp/requirements_test.txt
ENV PYTHONUNBUFFERED=1 \
DJANGO_SETTINGS_MODULE="pdf_gen_poc.settings"
COPY . .
EXPOSE 8000
# collect static
RUN /venv/bin/python manage.py collectstatic --noinput
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
FROM requirements_builder AS production
ARG USER=pdf_gen_poc
ENV UID=1000 \
GID=1000
RUN set -ex \
&& addgroup --gid ${GID} --system ${USER} \
&& adduser --system --gecos ${USER} --gid ${GID} -u ${UID} ${USER}
ENV PYTHONUNBUFFERED=1 \
DJANGO_SETTINGS_MODULE="pdf_gen_poc.settings"
RUN chown 1000:1000 .
COPY --chown=1000:1000 . .
RUN set -ex \
&& find /app -depth \( -name '*.pyo' -o -name '*.pyc' -o -name 'test' -o -name 'tests' \) -exec rm -rf '{}' +
# collect static
RUN . /venv/bin/activate \
&& /venv/bin/python manage.py collectstatic --noinput
# Switch to non-root user
USER ${USER}
EXPOSE 8000
CMD ["uwsgi", "pdf_gen_poc/uwsgi.ini"]