Skip to content

Commit 9a2102b

Browse files
authored
Refactored to fix multiple issues.
* Removed references to `django-box` from README. The `django-box` repository was archived over 5 years ago and many people coming to this now will have no idea what Vagrant or VirtualBox even are. * Removed obsolete configuration for Travis CI. Travis CI was used when GitHub Actions was still very new and had limited support. Since then, Travis CI became less tolerant of open source projects and runtimes increased significantly. GitHub Actions provides much more flexibility and can be looked into as a replacement for this matrix of tests. * Removed obsolete configuration for Azure Pipelines. This looks incomplete and was likely considered as an alternative to Travis CI at some point. We should look into GitHub Actions as a replacement for running a matrix of tests. * Removed obsolete script for pushing images to Docker Hub. Ownership of the repository for images on Docker Hub is likely in the hands of the original author rather than the Django project itself. In addition, we should probably look at making use of the GitHub Container Repository instead which will be easier to manage and control. * Removed broken support for Oracle Database. We will be able to support Oracle again now that they have started publishing container images themselves via their own repository. It's easier to remove this broken support and start again, however, as - aside from using a very old version of Oracle Database - this approach required many hacks. * Removed obsolete version attribute from compose file. This raises a warning when running `docker compose`, so remove it. * Removed obsolete `GEOIP_PATH` setting. Django now bundles test Maxmind GeoIP and GeoLite databases which means that this setting - and a manual download of these databases - is no longer required. * Removed unused `PIP_CACHE_VOLUME` environment variable. Unused since 9c8e95f. * Renamed docker and compose files. Instead of `docker-compose.yml`, rename to `compose.yml` as supported by the Compose Specification. Also rename to `Containerfile` instead of using `Dockerfile` to be more tool-agnostic. It would be good to also support Podman if and when it supports all of the features we require. * Consolidated settings into a single file. Most settings are exactly the same, so by dynamically generating the `DATABASES` setting we can ensure greater consistency and reduce the maintenance required. The `TEST_RUNNER` and `TEST_OUTPUT_DIR` settings have been hidden behind an `XUNIT` environment variable. These are typically only useful in CI, specifically on Jenkins, suppress some output, and do not support various features such as debugging SQL output and test durations. * Preferred "PostgreSQL" over "Postgres". All other database use the full name, so do the same for PostgreSQL. * Grouped and reordered services in compose file. Grouped services and commands by type and ordered alphabetically within each section. * Removed obsolete entrypoint for MySQL. The MySQL native password authentication plugin is obsolete. * Extracted common compose configuration for services. This allow us to apply configuration consistently and reduce duplication. * Enforced single instance for backend services. And also ensure that they restart unless explicitly stopped. * Replaced `wait-for-it.sh` script with compose healthchecks. This integrates better with compose commands with feedback on service health. Note that this doesn't yet introduce healthchecks for selenium nodes as we'll be switching over to Selenium Grid in a future commit which works slightly differently and the current setup doesn't seem to work correctly. * Fixed indentation of compose file. * Improved name of memcached services. * Fixed MySQL to use the same credentials as other databases. Prior to this MySQL and MariaDB were creating a "django" user, but were using "root" because the user didn't have the appropriate permissions. Fixing that brings the credentials used in line with PostgreSQL. * Fixed support for Selenium using Selenium Grid. Also reintroduces healthchecks. * Optimized services for testing. This disables various features in databases and attempts to reduce disk writes such that testing is as fast as possible. * Reinstated support for Oracle database. This is now using the images provided by Oracle in their own container registry. * Added GIS support for MariaDB. * Added support for Redis cache backend. Ensures that tests can be run for the cache backend for Redis. * Added support for running Selenium with Edge. * Enabled cache backends for GIS tests. There's not much reason why these need to be disabled. * Created improved folder structure under `/django`. Use the top-level `/django` folder as a place to copy files and mount volumes. The Django source code will now be mounted to `/django/source` and any generated output, e.g. coverage, will be output to a mounted volume at `/django/output`. It is also no longer necessary to specify the `DJANGO_PATH` environment variable if you have your Django respository checked out alongside this one, e.g. ``` ~/Sources ├── django └── django-docker-box ``` If you keep your source elsewhere, then the default of `../django` can still be overridden using `DJANGO_PATH`. Currently the Django sources are mounted read-write. This is due to various tools that are currently configured to write output into the source tree, e.g. coverage. In addition, some tests may write files to the source tree instead of a temporary location. Hopefully we can gradually address these issues and then move to mounting the source tree read-only instead. This commit also sets up the Django source tree as an additional context instead of the default context. This will allow including files from this repository during the image build but also sets up sourcing requirements files from the source tree which will be crucial to improving the container file. * Extracted packages into separate files. It's much easier to maintain a list of packages to install in a separate file. We can also get the packages required to build the documentation from the requirements file in the Django source tree. * Changed user name in container from `test` to `django`. * Modernized and optimized container file. Use modern syntax including heredocs, cache mounts, etc. Also merge the requirements files to reduce to a single install command. * Switched to `uv` for installing packages. * Added a basic entrypoint script. This will be expanded in future for enabling coverage, etc. * Added a `LICENSE` file. * Added some labels to the container image. * Updated to use Debian Bookworm. Also update some packages to install the dev packages. These will install the correct runtime libraries and keeps this maintainable - the version numbers in the package names can change with each distro update, so using the dev package avoids manual updates. * Added support for running with PyPy. * Enforced color output when running in CI. Ensure that we'll get colored output when running in GitHub Actions. * Updated `.editorconfig`. * Replaced `flake8` with `pre-commit`. Using `pre-commit` makes it easier to run all linters with the versions pinned by Django. Also add `black` as a dependency so that migrations which are created when using these images will be formatted. * Added linting tools and workflow for this repository. * Added more entries to `.gitignore` file. * Reordered entries in the `.env` file. * Updated the charset for MariaDB/MySQL. Recently this was updated to use `utf8mb4` for Django 5.2 * Removed stale container image cache location. Hopefully we'll reinstate this in the future, but make use of GitHub Container Registry. It'll be easier to maintain and we should be able to publish all versions on a regular basis from a GitHub Actions workflow. * Reworked commands for building documentation, etc. * Bumped database versions to those supported on Django main. * Removed reference to `${PWD}` from `compose.yaml`. This isn't necessary - we can just use the current directory as there is a lot of other stuff already doing that. Using `${PWD}` makes using this on Windows more awkward as this environment variable is undefined by default. * Reworked documentation in `README.md`. Add much more guidance on using the tools within this repository.
1 parent 97d4b5a commit 9a2102b

34 files changed

+969
-783
lines changed

.azure.yml

-8
This file was deleted.

.dockerignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.git/
2-
.dockerignore/
3-
django
2+
.dockerignore
3+
output/

.editorconfig

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
root = true
22

33
[*]
4-
indent_style = space
4+
charset = utf-8
5+
end_of_line = lf
56
indent_size = 4
7+
indent_style = space
68
insert_final_newline = true
79
trim_trailing_whitespace = true
8-
end_of_line = lf
9-
charset = utf-8
1010

11-
[*.yml]
11+
[*.{yaml,yml}]
1212
indent_size = 2

.env

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
PYTHON_IMPLEMENTATION=python
12
PYTHON_VERSION=3.10
2-
POSTGRES_VERSION=13
3-
POSTGIS_VERSION=3.0
4-
MYSQL_VERSION=8
53
MARIADB_VERSION=10.5
6-
PIP_CACHE_VOLUME=pip-cache
4+
MYSQL_VERSION=8.0
5+
ORACLE_VERSION=23.5.0.0
6+
POSTGRESQL_VERSION=14
7+
POSTGIS_VERSION=3.1

.github/workflows/lint.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
name: Lint
3+
4+
on: # yamllint disable-line rule:truthy
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
permissions:
15+
contents: read
16+
17+
env:
18+
COLUMNS: '120'
19+
FORCE_COLOR: '1'
20+
21+
jobs:
22+
pre-commit:
23+
runs-on: ubuntu-latest
24+
name: pre-commit
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
with:
29+
persist-credentials: false
30+
- name: Set up Python
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version: '3.13'
34+
cache: pip
35+
- name: Install packages
36+
run: python -m pip install --upgrade pip pre-commit
37+
- name: Run linting tools
38+
run: pre-commit run --all-files
39+
env:
40+
PRE_COMMIT_COLOR: always

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
__pycache__/
12
.idea/
2-
oracle/*.zip
3+
.mypy_cache/
4+
.ruff_cache/

.hadolint.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
ignored:
3+
- DL3013 # Don't complain when upgrading to latest version of pip
4+
- DL3022 # Due to use of additional_contexts in compose.yaml
5+
- DL3042 # Caching is desired with RUN --mount=type=cache

.pre-commit-config.yaml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
ci:
3+
autoupdate_schedule: weekly
4+
repos:
5+
- repo: meta
6+
hooks:
7+
- id: check-hooks-apply
8+
- id: check-useless-excludes
9+
- repo: https://github.com/pre-commit/pre-commit-hooks
10+
rev: v5.0.0
11+
hooks:
12+
- id: check-added-large-files
13+
- id: check-builtin-literals
14+
- id: check-case-conflict
15+
- id: check-docstring-first
16+
- id: check-executables-have-shebangs
17+
- id: check-merge-conflict
18+
- id: check-shebang-scripts-are-executable
19+
# - id: check-toml
20+
- id: check-vcs-permalinks
21+
- id: check-yaml
22+
- id: debug-statements
23+
- id: detect-private-key
24+
- id: end-of-file-fixer
25+
- id: file-contents-sorter
26+
args: [--unique]
27+
files: ^(?:packages|requirements)\.txt$
28+
- id: fix-byte-order-marker
29+
- id: fix-encoding-pragma
30+
args: [--remove]
31+
- id: requirements-txt-fixer
32+
- id: trailing-whitespace
33+
- repo: https://github.com/astral-sh/ruff-pre-commit
34+
rev: v0.8.2
35+
hooks:
36+
- id: ruff
37+
args: [--exit-non-zero-on-fix, --fix]
38+
- id: ruff-format
39+
args: [--check]
40+
- repo: https://github.com/adrienverge/yamllint.git
41+
rev: v1.35.1
42+
hooks:
43+
- id: yamllint
44+
args: [--strict]
45+
- repo: https://github.com/hadolint/hadolint
46+
rev: v2.12.0
47+
hooks:
48+
- id: hadolint-docker
49+
name: hadolint
50+
- repo: https://github.com/woodruffw/zizmor-pre-commit
51+
rev: v0.9.2
52+
hooks:
53+
- id: zizmor

.travis.yml

-88
This file was deleted.

Containerfile

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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"]

Dockerfile

-37
This file was deleted.

LICENSE

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright (c) Django Software Foundation and individual contributors.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
13+
14+
3. Neither the name of Django nor the names of its contributors may be used
15+
to endorse or promote products derived from this software without
16+
specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)