-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDockerfile
More file actions
87 lines (80 loc) · 3.53 KB
/
Dockerfile
File metadata and controls
87 lines (80 loc) · 3.53 KB
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
FROM python:3.12-slim-bookworm AS base
LABEL company="20tab" project="{{ cookiecutter.project_slug }}" service="backend" stage="base"
ARG DEBIAN_FRONTEND=noninteractive
ARG USER=appuser
ENV APPUSER=$USER \
LANG=C.UTF-8 \
LC_ALL=C.UTF-8 \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
VIRTUAL_ENV=/opt/venv \
WORKDIR=/app
WORKDIR $WORKDIR
RUN useradd --skel /dev/null --create-home $APPUSER
RUN chown $APPUSER:$APPUSER $WORKDIR
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
ARG PACKAGES_PATH=${VIRTUAL_ENV}/lib/python3.12/site-packages
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
libpq5 \
&& rm -rf /var/lib/apt/lists/*
COPY --chown=$APPUSER ./requirements/base.txt requirements/base.txt
RUN python3 -m venv $VIRTUAL_ENV \
&& chown -R $APPUSER:$APPUSER $VIRTUAL_ENV
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
gcc \
libc6-dev \
libpq-dev \
&& su $APPUSER -c "python3 -m pip install --no-cache-dir -r requirements/base.txt" \
&& apt-get purge --assume-yes --auto-remove \
gcc \
libc6-dev \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
COPY --chown=$APPUSER ./requirements/common.txt requirements/common.txt
RUN su $APPUSER -c "python3 -m pip install --no-cache-dir -r requirements/common.txt" \
&& (find ${PACKAGES_PATH} -regex '^.*/locale/.*/*.\(mo\|po\)$' -not -path '*/en*' -not -path '*/it*' -delete || true)
FROM base AS test
LABEL company="20tab" project="{{ cookiecutter.project_slug }}" service="backend" stage="test"
ENV DJANGO_CONFIGURATION=Testing
USER $APPUSER
COPY --chown=$APPUSER ./requirements/test.txt requirements/test.txt
RUN python3 -m pip install --no-cache-dir -r requirements/test.txt
COPY --chown=$APPUSER . .
CMD ./scripts/test.sh
FROM base AS remote
LABEL company="20tab" project="{{ cookiecutter.project_slug }}" service="backend" stage="remote"
ENV DJANGO_CONFIGURATION=Remote INTERNAL_SERVICE_PORT={{ cookiecutter.internal_service_port }}
USER $APPUSER
ARG PACKAGES_PATH=${VIRTUAL_ENV}/lib/python3.12/site-packages
COPY --chown=$APPUSER ./requirements/remote.txt requirements/remote.txt
RUN python3 -m pip install --no-cache-dir -r requirements/remote.txt \
&& (find ${PACKAGES_PATH}/boto*/data/* -maxdepth 0 -type d -not -name s3* -exec rm -rf {} \; || true)
COPY --chown=$APPUSER . .
RUN DJANGO_SECRET_KEY=build python3 -m manage collectstatic --clear --link --noinput
ENTRYPOINT ["./scripts/entrypoint.sh"]
CMD ["python3", "-m", "gunicorn", "{{ cookiecutter.django_settings_dirname }}.asgi"]
FROM base AS local
LABEL company="20tab" project="{{ cookiecutter.project_slug }}" service="backend" stage="local"
ENV DJANGO_CONFIGURATION=Local INTERNAL_SERVICE_PORT={{ cookiecutter.internal_service_port }}
ARG PACKAGES_PATH=${VIRTUAL_ENV}/lib/python3.12/site-packages
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
curl \
gcc \
gettext \
git \
graphviz \
libpq-dev \
make \
openssh-client \
postgresql-client
USER $APPUSER
COPY --chown=$APPUSER ./requirements/local.txt requirements/local.txt
RUN python3 -m pip install --no-cache-dir -r requirements/local.txt \
&& (find ${PACKAGES_PATH} -regex '^.*/locale/.*/*.\(mo\|po\)$' -not -path '*/en*' -not -path '*/it*' -delete || true)
COPY --chown=$APPUSER . .
RUN DJANGO_SECRET_KEY=build python3 -m manage collectstatic --clear --link --noinput
ENTRYPOINT ["./scripts/entrypoint.sh"]
CMD python3 -m manage runserver 0.0.0.0:${INTERNAL_SERVICE_PORT}