|
| 1 | +# syntax=docker/dockerfile:1.12 |
| 2 | + |
| 3 | +ARG PYTHON_IMPLEMENTATION=python |
| 4 | +ARG PYTHON_VERSION=3.10 |
| 5 | +FROM ${PYTHON_IMPLEMENTATION}:${PYTHON_VERSION}-slim-bookworm |
| 6 | + |
| 7 | +LABEL org.opencontainers.image.authors="Django Software Foundation" |
| 8 | +LABEL org.opencontainers.image.url="https://github.com/django/django-docker-box" |
| 9 | +LABEL org.opencontainers.image.documentation="https://github.com/django/django-docker-box" |
| 10 | +LABEL org.opencontainers.image.source="https://github.com/django/django-docker-box" |
| 11 | +LABEL org.opencontainers.image.vendor="Django Software Foundation" |
| 12 | +LABEL org.opencontainers.image.licenses="BSD-3-Clause" |
| 13 | +LABEL org.opencontainers.image.title="Django Docker Box" |
| 14 | +LABEL org.opencontainers.image.description="Container image for developing and testing Django." |
| 15 | + |
| 16 | +SHELL ["/bin/bash", "-o", "errexit", "-o", "nounset", "-o", "pipefail", "-o", "xtrace", "-c"] |
| 17 | + |
| 18 | +ENV DEBIAN_FRONTEND=noninteractive |
| 19 | +ENV PYTHONUNBUFFERED=1 |
| 20 | + |
| 21 | +# Force colored output for various tooling in CI. |
| 22 | +ENV COLUMNS=120 |
| 23 | +ENV FORCE_COLOR=1 |
| 24 | +ENV TERM="xterm-256color" |
| 25 | + |
| 26 | +# Create user and prepare directories. |
| 27 | +RUN <<EOF |
| 28 | + useradd --home-dir=/django --no-create-home --no-log-init django |
| 29 | + mkdir --parents /django/{.cache,output,source} |
| 30 | + chown --recursive django:django /django |
| 31 | +EOF |
| 32 | + |
| 33 | +# Install system dependencies from package manager. |
| 34 | +COPY --chown=django:django packages.txt /django/ |
| 35 | +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ |
| 36 | + --mount=type=cache,target=/var/lib/apt,sharing=locked <<EOF |
| 37 | + rm --force /etc/apt/apt.conf.d/docker-clean |
| 38 | + echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache |
| 39 | + apt-get update --quiet --yes |
| 40 | + xargs --arg-file=/django/packages.txt apt-get install --no-install-recommends --yes |
| 41 | +EOF |
| 42 | + |
| 43 | +# Install all Python requirements in a single command. |
| 44 | +COPY --chown=django:django requirements.txt /django/requirements/extra.txt |
| 45 | +COPY --chown=django:django --from=src tests/requirements/ /django/requirements/ |
| 46 | +COPY --chown=django:django --from=src docs/requirements.txt /django/requirements/docs.txt |
| 47 | +COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/ |
| 48 | +RUN --mount=type=cache,target=/root/.cache/uv <<EOF |
| 49 | + cat /django/requirements/*.txt \ |
| 50 | + | grep --invert-match '^#' \ |
| 51 | + | sort --unique --version-sort \ |
| 52 | + | tee /django/requirements.txt |
| 53 | + uv pip install --requirement=/django/requirements.txt --system |
| 54 | +EOF |
| 55 | + |
| 56 | +COPY --chown=django:django entrypoint.bash /django/ |
| 57 | + |
| 58 | +SHELL ["/bin/bash", "-c"] |
| 59 | + |
| 60 | +ENV DJANGO_SETTINGS_MODULE=settings |
| 61 | +ENV PYTHONPATH="${PYTHONPATH}:/django/source/" |
| 62 | +USER django:django |
| 63 | +VOLUME /django/output |
| 64 | +VOLUME /django/source |
| 65 | +WORKDIR /django/source/tests |
| 66 | +ENTRYPOINT ["/django/entrypoint.bash"] |
0 commit comments