From 85a821ff0fab61cd70c68c1ebe36fdf92bdf6757 Mon Sep 17 00:00:00 2001 From: gabdevele Date: Wed, 17 Jun 2026 19:42:57 +0200 Subject: [PATCH] feat: update database path configuration and improve entrypoint script for SQLite handling --- .gitignore | 1 + README.md | 6 ++++++ docker-compose.yml | 3 +++ entrypoint.sh | 7 ++++--- federation_authority/federation_authority/settingslocal.py | 2 +- .../federation_authority/settingslocal.py.example | 2 +- provider/provider/settingslocal.py | 2 +- provider/provider/settingslocal.py.example | 2 +- relying_party/relying_party/settingslocal.py | 2 +- relying_party/relying_party/settingslocal.py.example | 2 +- 10 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index efa03eb..4775950 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ */db.sqlite3 +*/db/db.sqlite3 */logs/ */static/ diff --git a/README.md b/README.md index 52fa223..37d6d52 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,12 @@ curl -sS http://127.0.0.1:5555/api/v1/auth/cie/session/ docker compose down -v ``` +If the stack was started before June 17, 2026 DB path fix, also remove legacy SQLite files that were created outside named volumes: + +```bash +rm -f federation_authority/db.sqlite3 provider/db.sqlite3 relying_party/db.sqlite3 +``` + ## Logs ```bash docker compose logs -f diff --git a/docker-compose.yml b/docker-compose.yml index 01dca17..8fb4b41 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,7 @@ services: DJANGO_SECRET_KEY: ${FEDERATION_AUTHORITY_SECRET_KEY:-visione-cie-authority-local-dev} DJANGO_ALLOWED_HOSTS: ${CIE_AUTH_ALLOWED_HOSTS:-*} DJANGO_TRUST_ANCHOR: ${DJANGO_TRUST_ANCHOR:-http://federation-authority:8000} + DJANGO_DB_PATH: /app/federation_authority/db/db.sqlite3 LOAD_FIXTURE_ON_EMPTY_DB: ${FEDERATION_AUTHORITY_LOAD_FIXTURE_ON_EMPTY_DB:-true} expose: - "8000" @@ -28,6 +29,7 @@ services: DJANGO_ALLOWED_HOSTS: ${CIE_AUTH_ALLOWED_HOSTS:-*} DJANGO_TRUST_ANCHOR: ${DJANGO_TRUST_ANCHOR:-http://federation-authority:8000} DJANGO_PROVIDER_ISSUER: ${DJANGO_PROVIDER_ISSUER:-http://provider:8002/oidc/op} + DJANGO_DB_PATH: /app/provider/db/db.sqlite3 LOAD_FIXTURE_ON_EMPTY_DB: ${PROVIDER_LOAD_FIXTURE_ON_EMPTY_DB:-true} expose: - "8002" @@ -53,6 +55,7 @@ services: DJANGO_RP_SHARED_SECRET: ${DJANGO_RP_SHARED_SECRET:-change-me-for-local-dev} DJANGO_RP_DEFAULT_PROVIDER: ${DJANGO_RP_DEFAULT_PROVIDER:-http://provider:8002/oidc/op} DJANGO_RP_BASE_URL: ${DJANGO_RP_BASE_URL:-http://relying-party:8001} + DJANGO_DB_PATH: /app/relying_party/db/db.sqlite3 LOAD_FIXTURE_ON_EMPTY_DB: ${RELYING_PARTY_LOAD_FIXTURE_ON_EMPTY_DB:-true} expose: - "8001" diff --git a/entrypoint.sh b/entrypoint.sh index 4e0ceac..53d6687 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,12 +3,13 @@ set -eu APP_DIR="$1" PORT="$2" +DB_PATH="${DJANGO_DB_PATH:-$APP_DIR/db/db.sqlite3}" cd "$APP_DIR" -mkdir -p logs static +mkdir -p logs static "$(dirname "$DB_PATH")" -if [ ! -f "$APP_DIR/db.sqlite3" ] && [ "${LOAD_FIXTURE_ON_EMPTY_DB:-true}" = "true" ]; then +if [ ! -f "$DB_PATH" ] && [ "${LOAD_FIXTURE_ON_EMPTY_DB:-true}" = "true" ]; then TMP_DUMP="$(mktemp)" python /app/scripts/rewrite_dumps.py dumps/example.json "$TMP_DUMP" python manage.py migrate @@ -22,7 +23,7 @@ fi # Collect them into STATIC_ROOT so the explicit /static/ URL can serve them. python manage.py collectstatic --noinput -if grep -aEq '127\.0\.0\.1|provider:8002' "$APP_DIR/db.sqlite3"; then +if grep -aEq '127\.0\.0\.1|provider:8002' "$DB_PATH"; then echo "Refusing to start: bootstrap data still contains internal/local URLs" >&2 exit 1 fi diff --git a/federation_authority/federation_authority/settingslocal.py b/federation_authority/federation_authority/settingslocal.py index bd0e1b8..a21f23b 100644 --- a/federation_authority/federation_authority/settingslocal.py +++ b/federation_authority/federation_authority/settingslocal.py @@ -66,7 +66,7 @@ DJAGGER_DOCUMENT = { DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'NAME': os.getenv('DJANGO_DB_PATH', os.path.join(BASE_DIR, 'db', 'db.sqlite3')), } } diff --git a/federation_authority/federation_authority/settingslocal.py.example b/federation_authority/federation_authority/settingslocal.py.example index f8d2696..8e34a8e 100644 --- a/federation_authority/federation_authority/settingslocal.py.example +++ b/federation_authority/federation_authority/settingslocal.py.example @@ -191,7 +191,7 @@ DATABASES = { # }, 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'NAME': os.getenv('DJANGO_DB_PATH', os.path.join(BASE_DIR, 'db', 'db.sqlite3')), } } diff --git a/provider/provider/settingslocal.py b/provider/provider/settingslocal.py index 7600bf1..245dd17 100644 --- a/provider/provider/settingslocal.py +++ b/provider/provider/settingslocal.py @@ -70,7 +70,7 @@ DJAGGER_DOCUMENT = { DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'NAME': os.getenv('DJANGO_DB_PATH', os.path.join(BASE_DIR, 'db', 'db.sqlite3')), } } diff --git a/provider/provider/settingslocal.py.example b/provider/provider/settingslocal.py.example index 0b20753..6514098 100644 --- a/provider/provider/settingslocal.py.example +++ b/provider/provider/settingslocal.py.example @@ -79,7 +79,7 @@ DATABASES = { # }, 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'NAME': os.getenv('DJANGO_DB_PATH', os.path.join(BASE_DIR, 'db', 'db.sqlite3')), } } diff --git a/relying_party/relying_party/settingslocal.py b/relying_party/relying_party/settingslocal.py index 9b36207..748cb57 100644 --- a/relying_party/relying_party/settingslocal.py +++ b/relying_party/relying_party/settingslocal.py @@ -76,7 +76,7 @@ DJAGGER_DOCUMENT = { DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'NAME': os.getenv('DJANGO_DB_PATH', os.path.join(BASE_DIR, 'db', 'db.sqlite3')), } } diff --git a/relying_party/relying_party/settingslocal.py.example b/relying_party/relying_party/settingslocal.py.example index 71364a3..640d253 100644 --- a/relying_party/relying_party/settingslocal.py.example +++ b/relying_party/relying_party/settingslocal.py.example @@ -81,7 +81,7 @@ DATABASES = { # }, 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'NAME': os.getenv('DJANGO_DB_PATH', os.path.join(BASE_DIR, 'db', 'db.sqlite3')), } }