diff mbox series

[error-report-web,2/5] Add docker/run-tests.sh to run the tests in a container.

Message ID 20261018014510.72203-5-tim.orling@konsulko.com
State New
Headers show
Series Add GitHub Actions CI and run tests with Docker | expand

Commit Message

Tim Orling Oct. 18, 2026, 1:43 a.m. UTC
Build the image and test against a throwaway MySQL, as layerindex-web
does. -Wa shows deprecation warnings. Read SECRET_KEY from the
environment in settings.py.docker, and keep .git and .env out of the
image and .env out of git.

AI-Generated: Claude Opus 5.5
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 .dockerignore              | 10 ++++++++++
 .gitignore                 |  1 +
 docker/run-tests.sh        | 32 ++++++++++++++++++++++++++++++++
 project/settings.py.docker |  2 +-
 4 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 .dockerignore
 create mode 100755 docker/run-tests.sh
diff mbox series

Patch

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..adce5c5
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,10 @@ 
+.git
+.env
+.devcontainer
+.ruff_cache
+__pycache__
+*.pyc
+*.sqlite3
+*.patch
+venv
+.venv
diff --git a/.gitignore b/.gitignore
index a6c3d2d..2b8f143 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ 
 pull-*/
 venv
 *.sqlite3
+.env
diff --git a/docker/run-tests.sh b/docker/run-tests.sh
new file mode 100755
index 0000000..54aaa8b
--- /dev/null
+++ b/docker/run-tests.sh
@@ -0,0 +1,32 @@ 
+#!/bin/sh
+# Run the tests in the app image against a throwaway MySQL. Used by CI.
+#
+# SPDX-License-Identifier: MIT
+
+set -e
+
+IMAGE=${IMAGE:-error-report-web-test}
+NET=error-report-web-test
+DB=error-report-web-test-db
+
+docker build -t "$IMAGE" .
+
+docker network create $NET >/dev/null
+trap 'docker rm -f $DB >/dev/null; docker network rm $NET >/dev/null' EXIT
+
+# Root so Django can create the test database; testingpw isn't a secret.
+docker run -d --name $DB --network $NET --network-alias db \
+    -e MYSQL_ROOT_PASSWORD=testingpw -e MYSQL_DATABASE=errorreport \
+    mysql:8.0.36 >/dev/null
+until docker exec $DB mysql -h127.0.0.1 -uroot -ptestingpw -e 'SELECT 1' >/dev/null 2>&1; do
+    if [ "$(docker inspect -f '{{.State.Running}}' $DB)" != true ]; then
+        docker logs $DB | tail -5; exit 1
+    fi
+    sleep 1
+done
+
+# -Wa shows deprecation warnings, i.e. what breaks on the next Django.
+docker run --rm --network $NET \
+    -e SECRET_KEY=ci-only \
+    -e MYSQL_DATABASE=errorreport -e MYSQL_USER=root -e MYSQL_PASSWORD=testingpw \
+    "$IMAGE" python3 -Wa manage.py test --noinput Post
diff --git a/project/settings.py.docker b/project/settings.py.docker
index b7ff669..9f98715 100644
--- a/project/settings.py.docker
+++ b/project/settings.py.docker
@@ -127,7 +127,7 @@  STATICFILES_FINDERS = (
 )
 
 # Make this unique, and don't share it with anybody.
-SECRET_KEY = 'changeme'
+SECRET_KEY = os.environ.get('SECRET_KEY', 'changeme')
 
 MIDDLEWARE = [
     'django.middleware.common.CommonMiddleware',