From dee5c445ed0287b0e43cf7abc0f56e9da29db22e Mon Sep 17 00:00:00 2001 From: Tobias McNulty Date: Tue, 16 Sep 2025 21:39:41 -0400 Subject: [PATCH 1/6] Added Actions workflow to publish Docker images --- .github/workflows/docker-publish.yml | 82 ++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..2388741 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,82 @@ +--- +name: Publish Docker images for Django Docker Box + +on: # yamllint disable-line rule:truthy + push: + branches: [pkgs] + +env: + REGISTRY: ghcr.io + REGISTRY_WITH_PATH: ghcr.io/${{ github.repository_owner }} + +jobs: + build-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + matrix: + python_implementation: [python] + python_version: ["3.12", "3.13"] + django_version: ["4.2", "5.1", "5.2", "main"] + exclude: + # Exclude PyPy versions that are not available + - python_implementation: pypy + python_version: "3.12" + - python_implementation: pypy + python_version: "3.13" + env: + # yamllint disable rule:line-length + DOCKER_IMAGE_TAG: ${{ matrix.python_implementation }}-${{ matrix.python_version }}-django-${{ matrix.django_version }} + # yamllint enable rule:line-length + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_WITH_PATH }}/django-docker-box + tags: | + type=raw,value=${{ env.DOCKER_IMAGE_TAG }} + - name: Download Django source + # yamllint disable rule:line-length + run: | + if [ "${{ matrix.django_version }}" = "main" ]; then + branch=main + dirname=django-main + else + branch=stable/${{ matrix.django_version }}.x + dirname=django-stable-${{ matrix.django_version }}.x + fi + curl -L https://github.com/django/django/archive/refs/heads/$branch.tar.gz | tar xz + mv $dirname django-src + # yamllint enable rule:line-length + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: Containerfile + push: ${{ github.event_name != 'pull_request' }} + build-args: | + PYTHON_IMPLEMENTATION=${{ matrix.python_implementation }} + PYTHON_VERSION=${{ matrix.python_version }} + DJANGO_PATH=django-src + build-contexts: | + src=django-src + # yamllint disable rule:line-length + cache-from: type=registry,ref=${{ env.REGISTRY_WITH_PATH }}/django-docker-box:buildcache-${{ env.DOCKER_IMAGE_TAG }} + cache-to: type=registry,ref=${{ env.REGISTRY_WITH_PATH }}/django-docker-box:buildcache-${{ env.DOCKER_IMAGE_TAG }},mode=max + # yamllint enable rule:line-length + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From 55d99b19f55fff6471b29be6397742dde2ea86cc Mon Sep 17 00:00:00 2001 From: Tobias McNulty Date: Tue, 16 Sep 2025 22:25:20 -0400 Subject: [PATCH 2/6] Ran tests in published images --- .github/workflows/docker-publish.yml | 61 ++++++++++++++++++++++++++++ compose.yml | 2 +- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 2388741..04e7f95 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -80,3 +80,64 @@ jobs: # yamllint enable rule:line-length tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + + test-image: + needs: build-push-image + runs-on: ubuntu-latest + strategy: + matrix: + python_implementation: [python] + python_version: ["3.12", "3.13"] + django_version: ["5.2", "main"] + test_service: + - mariadb + - mysql + - oracle + - postgresql + - sqlite + - mariadb-gis + - mysql-gis + - oracle-gis + - postgresql-gis + - sqlite-gis + fail-fast: false + env: + REGISTRY: ghcr.io + REGISTRY_PATH: ghcr.io/${{ github.repository_owner }}/django-docker-box + # yamllint disable rule:line-length + IMAGE_TAG: ${{ matrix.python_implementation }}-${{ matrix.python_version }}-django-${{ matrix.django_version }} + # yamllint enable rule:line-length + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.workflow_run.head_sha }} + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Pull image + run: | + docker pull ${{ env.REGISTRY_PATH }}:${{ env.IMAGE_TAG }} + # yamllint disable rule:line-length + - name: Download Django source + run: | + if [ "${{ matrix.django_version }}" = "main" ]; then + branch=main + dirname=django-main + else + branch=stable/${{ matrix.django_version }}.x + dirname=django-stable-${{ matrix.django_version }}.x + fi + curl -L https://github.com/django/django/archive/refs/heads/$branch.tar.gz | tar xz + mv $dirname django-src + # yamllint enable rule:line-length + - name: Run tests for ${{ matrix.test_service }} + run: | + export DOCKER_BOX_IMAGE=${{ env.REGISTRY_PATH }}:${{ env.IMAGE_TAG }} + export DJANGO_PATH=./django-src/ + docker compose run --rm ${{ matrix.test_service }} diff --git a/compose.yml b/compose.yml index fc65ac7..6336228 100644 --- a/compose.yml +++ b/compose.yml @@ -1,7 +1,7 @@ --- x-base: &base - image: django-docker-box:${PYTHON_IMPLEMENTATION}-${PYTHON_VERSION} + image: ${DOCKER_BOX_IMAGE:-django-docker-box:${PYTHON_IMPLEMENTATION}-${PYTHON_VERSION}} # yamllint disable-line rule:line-length build: context: . dockerfile: ./Containerfile From 8b33902ebdfaa5c00be1f16d6251385050b419ef Mon Sep 17 00:00:00 2001 From: Tobias McNulty Date: Tue, 16 Sep 2025 23:43:33 -0400 Subject: [PATCH 3/6] Revert "Removed DEFAULT_AUTO_FIELD setting." This reverts commit 162ffe9bc46c39b61e577fe79624217a682e997d. --- settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/settings.py b/settings.py index 4ed62a4..40cd183 100644 --- a/settings.py +++ b/settings.py @@ -57,6 +57,8 @@ def _build_databases_setting(): DATABASES = _build_databases_setting() +DEFAULT_AUTO_FIELD = "django.db.models.AutoField" + PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"] SECRET_KEY = "django_tests_secret_key" From 63094e5af011df51417d64d4665c242fad8efb07 Mon Sep 17 00:00:00 2001 From: Tobias McNulty Date: Tue, 16 Sep 2025 23:46:33 -0400 Subject: [PATCH 4/6] Only set DEFAULT_AUTO_FIELD for Django <= 5.2 --- settings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/settings.py b/settings.py index 40cd183..85fd0da 100644 --- a/settings.py +++ b/settings.py @@ -1,4 +1,5 @@ import os +import django def _build_databases_setting(): @@ -57,7 +58,9 @@ def _build_databases_setting(): DATABASES = _build_databases_setting() -DEFAULT_AUTO_FIELD = "django.db.models.AutoField" +# Only set DEFAULT_AUTO_FIELD for Django <= 5.2 +if django.VERSION < (5, 3): + DEFAULT_AUTO_FIELD = "django.db.models.AutoField" PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"] From 0ba71c19b01feaf22b5d4030735b655aa65ba832 Mon Sep 17 00:00:00 2001 From: Tobias McNulty Date: Wed, 17 Sep 2025 08:36:11 -0400 Subject: [PATCH 5/6] Disabled colors in terminal output --- Containerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Containerfile b/Containerfile index 8c5be34..ebaa615 100644 --- a/Containerfile +++ b/Containerfile @@ -19,9 +19,9 @@ ENV DEBIAN_FRONTEND=noninteractive ENV PYTHONUNBUFFERED=1 # Force colored output for various tooling in CI. -ENV COLUMNS=120 -ENV FORCE_COLOR=1 -ENV TERM="xterm-256color" +# ENV COLUMNS=120 +# ENV FORCE_COLOR=1 +# ENV TERM="xterm-256color" # Create user and prepare directories. RUN < Date: Wed, 17 Sep 2025 09:46:23 -0400 Subject: [PATCH 6/6] Upgraded `MARIADB_VERSION=10.11` --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index 00657df..677f27f 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ PYTHON_IMPLEMENTATION=python PYTHON_VERSION=3.12 -MARIADB_VERSION=10.6 +MARIADB_VERSION=10.11 MYSQL_VERSION=8.0 ORACLE_VERSION=23.5.0.0 POSTGRESQL_VERSION=14