**Improve database handling and disable redundant health checks**

- Added logic to construct `DATABASE_URL` from `DB_*` variables to prevent accidental fallback to SQLite during Docker Compose deployments.
- Updated `DATABASES` configuration to use `dj_database_url.parse` instead of deprecated `config`.
- Disabled health checks for services that do not expose a web port to avoid unnecessary probes.
- Removed unused `libmariadb-dev` and `pkg-config` dependencies from the `Dockerfile`.
This commit is contained in:
ajurna committed 2026-10-14 12:32:11 +01:00
1 parent 77a80dd322
commit a9e9bfb480
4 files changed
+20 -2

No files matched your search

+1 -1
View File
@@ -32,7 +32,7 @@ RUN . /etc/os-release \
&& echo "deb http://deb.debian.org/debian ${VERSION_CODENAME} non-free non-free-firmware" \ && echo "deb http://deb.debian.org/debian ${VERSION_CODENAME} non-free non-free-firmware" \
> /etc/apt/sources.list.d/non-free.list \ > /etc/apt/sources.list.d/non-free.list \
&& apt update \ && apt update \
&& apt install -y --no-install-recommends cron unrar libmariadb-dev pkg-config \ && apt install -y --no-install-recommends cron unrar \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
WORKDIR /src WORKDIR /src
+13 -1
View File
@@ -7,6 +7,7 @@ import os
from datetime import timedelta from datetime import timedelta
from pathlib import Path from pathlib import Path
from typing import Dict, List from typing import Dict, List
from urllib.parse import quote
import dj_database_url import dj_database_url
from dotenv import load_dotenv from dotenv import load_dotenv
@@ -72,8 +73,19 @@ WSGI_APPLICATION = "cbreader.wsgi.application"
DATABASE_URL = os.getenv("DATABASE_URL") DATABASE_URL = os.getenv("DATABASE_URL")
# docker-compose passes DB_* variables, not a URL. Without building one from them the
# app silently falls back to sqlite inside the container, and the web and cron
# containers end up with two separate databases.
if not DATABASE_URL and os.getenv("DB_HOST"):
DATABASE_URL = "postgres://{}:{}@{}/{}".format(
quote(os.getenv("DB_USER", "postgres"), safe=""),
quote(os.getenv("DB_PASS", ""), safe=""),
os.getenv("DB_HOST"),
os.getenv("DB_DATABASE", "postgres"),
)
if DATABASE_URL: if DATABASE_URL:
DATABASES = {"default": dj_database_url.config(conn_max_age=500)} DATABASES = {"default": dj_database_url.parse(DATABASE_URL, conn_max_age=500)}
else: else:
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": os.path.join(BASE_DIR, "db.sqlite3")}} DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": os.path.join(BASE_DIR, "db.sqlite3")}}
+3
View File
@@ -30,6 +30,9 @@ services:
- ${COMIC_BOOK_HOST_PATH}:${COMIC_BOOK_VOLUME} - ${COMIC_BOOK_HOST_PATH}:${COMIC_BOOK_VOLUME}
- media_files:/media - media_files:/media
- .env:/src/.env - .env:/src/.env
# The image HEALTHCHECK probes the web port, which this service never serves.
healthcheck:
disable: true
command: sh entrypoint-cron.sh command: sh entrypoint-cron.sh
restart: unless-stopped restart: unless-stopped
+3
View File
@@ -30,6 +30,9 @@ services:
- ${COMIC_BOOK_HOST_PATH}:${COMIC_BOOK_VOLUME} - ${COMIC_BOOK_HOST_PATH}:${COMIC_BOOK_VOLUME}
- media_files:/media - media_files:/media
- .env:/src/.env - .env:/src/.env
# The image HEALTHCHECK probes the web port, which this service never serves.
healthcheck:
disable: true
command: sh entrypoint-cron.sh command: sh entrypoint-cron.sh
restart: unless-stopped restart: unless-stopped