-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
87 lines (71 loc) · 2.46 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
# syntax = docker/dockerfile:1
# This Dockerfile uses multi-stage build to customize DEV and PROD images:
# https://docs.docker.com/develop/develop-images/multistage-build/
FROM python:3.11.4-slim-bookworm AS development_build
LABEL maintainer="abxsantos"
LABEL vendor="abxsantos"
# `DJANGO_ENV` arg is used to make prod / dev builds:
ARG DJANGO_ENV \
# Needed for fixing permissions of files created by Docker:
UID=1000 \
GID=1000
ENV DJANGO_ENV=${DJANGO_ENV} \
# python:
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PYTHONDONTWRITEBYTECODE=1 \
# pip:
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_DEFAULT_TIMEOUT=100 \
PIP_ROOT_USER_ACTION=ignore \
# poetry:
POETRY_VERSION=1.5.1 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_CREATE=false \
POETRY_HOME='/usr/local'
SHELL ["/bin/bash", "-eo", "pipefail", "-c"]
# System deps (we don't use exact versions because it is hard to update them,
# pin when needed):
# hadolint ignore=DL3008
RUN apt-get update && apt-get upgrade -y \
&& apt-get install --no-install-recommends -y \
brotli \
curl \
gettext \
git \
# Installing `poetry` package manager:
# https://github.com/python-poetry/poetry
&& curl -sSL 'https://install.python-poetry.org' | python - \
&& poetry --version \
# Cleaning cache:
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
WORKDIR /code
RUN groupadd -g "${GID}" -r web \
&& useradd -d '/code' -g web -l -r -u "${UID}" web \
&& chown web:web -R '/code' \
# Static and media files:
&& mkdir -p '/var/www/django/static' '/var/www/django/media' \
&& chown web:web '/var/www/django/static' '/var/www/django/media'
# Copy only requirements, to cache them in docker layer
COPY --chown=web:web ./pyproject.toml ./poetry.lock /code/
# Project initialization:
# hadolint ignore=SC2046
RUN echo "$DJANGO_ENV" \
&& poetry version \
# Install deps:
&& poetry run pip install -U pip \
&& poetry install \
$(if [ "$DJANGO_ENV" = 'production' ]; then echo '--only main'; fi) \
--no-interaction --no-ansi
# The following stage is only for production:
# https://wemake-django-template.readthedocs.io/en/latest/pages/template/production.html
FROM development_build AS production_build
COPY --chown=web:web . /code
RUN chmod -R 755 /var/www/django/static
# Running as non-root user:
USER web
CMD [ "./scripts/gunicorn.sh" ]
EXPOSE 8080