Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -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
Expand Down
143 changes: 143 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
---
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 }}

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 }}
6 changes: 3 additions & 3 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terminal colors break some tests that look for terminal output on Python 3.13.


# Create user and prepare directories.
RUN <<EOF
Expand Down Expand Up @@ -58,7 +58,7 @@
SHELL ["/bin/bash", "-c"]

ENV DJANGO_SETTINGS_MODULE=settings
ENV PYTHONPATH="${PYTHONPATH}:/django/source/"

Check warning on line 61 in Containerfile

View workflow job for this annotation

GitHub Actions / build-push-image (python, 3.12, 5.1)

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$PYTHONPATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

Check warning on line 61 in Containerfile

View workflow job for this annotation

GitHub Actions / build-push-image (python, 3.12, 4.2)

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$PYTHONPATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

Check warning on line 61 in Containerfile

View workflow job for this annotation

GitHub Actions / build-push-image (python, 3.13, 5.1)

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$PYTHONPATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

Check warning on line 61 in Containerfile

View workflow job for this annotation

GitHub Actions / build-push-image (python, 3.12, 5.2)

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$PYTHONPATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

Check warning on line 61 in Containerfile

View workflow job for this annotation

GitHub Actions / build-push-image (python, 3.13, 5.2)

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$PYTHONPATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

Check warning on line 61 in Containerfile

View workflow job for this annotation

GitHub Actions / build-push-image (python, 3.12, main)

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$PYTHONPATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

Check warning on line 61 in Containerfile

View workflow job for this annotation

GitHub Actions / build-push-image (python, 3.13, 4.2)

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$PYTHONPATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

Check warning on line 61 in Containerfile

View workflow job for this annotation

GitHub Actions / build-push-image (python, 3.13, main)

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$PYTHONPATH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/
USER django:django
VOLUME /django/output
VOLUME /django/source
Expand Down
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import django


def _build_databases_setting():
Expand Down Expand Up @@ -57,6 +58,10 @@ def _build_databases_setting():

DATABASES = _build_databases_setting()

# 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"]

SECRET_KEY = "django_tests_secret_key"
Expand Down
Loading