Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored to fix multiple issues. #48

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open

Conversation

ngnpope
Copy link
Member

@ngnpope ngnpope commented Dec 19, 2024

As it's nearly Christmas 🎄 I thought I'd share this gift 🎁

Tagging those who have expressed interest: @charettes @sarahboyce


Includes the following changes (in no particular order):

  • Removed outdated configuration for Azure Pipelines
  • Removed outdated configuration for Travis CI
  • Removed obsolete PIP_CACHE_VOLUME from .env
  • Removed obsolete entries from .gitignore
  • Removed obsolete support for unofficial Oracle images
  • Removed obsolete docker_push.sh script
  • Added workflow for linting in GitHub Actions
  • Added pre-commit, hadolint, ruff, yamllint, and zizmor for linting
  • Defaulted DJANGO_PATH to ../django, i.e. assume adjacent checkouts
  • Removed reference to ${PWD} which is not available on Windows
  • Updated Dockerfile to use modern syntax, including:
    • Using here documents with RUN to avoid backslash escaping
    • Using --mount=type=cache,... with RUN to improve build speed
  • Updated apt-get and pip installation to be more optimal:
    • Enabled caching of downloads for both commands
    • Extracted packages to external files
    • Combined requirements files to optimise dependency resolution
    • Switched to using uv for installation of Python dependencies
  • Included set -o errexit -o nounset -o pipefail -o xtrace for RUN
  • Added forced color output, etc. to Dockerfile for use in CI
  • Tided up the location of injected and generated files in the image
  • Added preliminary support for alternative Python interpreters, specifically PyPy
  • Updated docker-compose.yml to use modern features:
    • Dropped the non-required version property
    • Used additional_contexts to source files from multiple places
    • Used deploy: mode: global for databases, caches, etc.
    • Reverted to using healthcheck in place of wait-for-it.sh
  • Added configuration to speed up database services
  • Added support for Oracle Database Free 23ai
  • Added GIS support for MariaDB and Oracle
  • Added a container for Redis to enable testing the Redis cache backend
  • Added Edge support for testing with Selenium
  • Fixed building of documentation using Sphinx
  • Renamed Dockerfile to Containerfile
  • Renamed docker-compose.yml to compose.yml
  • Merged settings files into a single dynamic file to reduce maintenance
  • Updated README to document all of the changes and features
  • Added a LICENSE file using the same license as Django

Fixes #4, closes #5, resolves #8, fixes #42, closes #47.

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.
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.
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.
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.
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.
This raises a warning when running `docker compose`, so remove it.
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.
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.
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.
All other database use the full name, so do the same for PostgreSQL.
Grouped services and commands by type and ordered alphabetically within
each section.
The MySQL native password authentication plugin is obsolete.
This allow us to apply configuration consistently and reduce
duplication.
And also ensure that they restart unless explicitly stopped.
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.
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.
Also reintroduces healthchecks.
This disables various features in databases and attempts to reduce disk
writes such that testing is as fast as possible.
This is now using the images provided by Oracle in their own container
registry.
Ensures that tests can be run for the cache backend for Redis.
There's not much reason why these need to be disabled.
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.
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.
Use modern syntax including heredocs, cache mounts, etc. Also merge the
requirements files to reduce to a single install command.
This will be expanded in future for enabling coverage, etc.
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.
Ensure that we'll get colored output when running in GitHub Actions.
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.
Recently this was updated to use `utf8mb4` for Django 5.2
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.
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.
Add much more guidance on using the tools within this repository.
@charettes
Copy link
Member

That's quite the 🎄 gift indeed Nick!!!

I should be able to give it a run during the holidays but assuming this is based on your work in the Oracle issue branch I can confirm that I've been using with success for Oracle, MySQL, and Postgres for about 6 months now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Selenium tests are broken Add MariaDB GIS builds. Oracle setup seems to be broken.
2 participants