diff --git a/Dockerfile b/Dockerfile index c9374fc..c53642b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,7 @@ RUN . /etc/os-release \ && echo "deb http://deb.debian.org/debian ${VERSION_CODENAME} non-free non-free-firmware" \ > /etc/apt/sources.list.d/non-free.list \ && 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/* WORKDIR /src diff --git a/cbreader/settings/base.py b/cbreader/settings/base.py index 4113a49..cea146b 100644 --- a/cbreader/settings/base.py +++ b/cbreader/settings/base.py @@ -7,6 +7,7 @@ import os from datetime import timedelta from pathlib import Path from typing import Dict, List +from urllib.parse import quote import dj_database_url from dotenv import load_dotenv @@ -72,8 +73,19 @@ WSGI_APPLICATION = "cbreader.wsgi.application" 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: - DATABASES = {"default": dj_database_url.config(conn_max_age=500)} + DATABASES = {"default": dj_database_url.parse(DATABASE_URL, conn_max_age=500)} else: DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": os.path.join(BASE_DIR, "db.sqlite3")}} diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index af4bedf..26cda3e 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -30,6 +30,9 @@ services: - ${COMIC_BOOK_HOST_PATH}:${COMIC_BOOK_VOLUME} - media_files:/media - .env:/src/.env + # The image HEALTHCHECK probes the web port, which this service never serves. + healthcheck: + disable: true command: sh entrypoint-cron.sh restart: unless-stopped diff --git a/docker-compose.yml b/docker-compose.yml index 483c70b..2a729dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,6 +30,9 @@ services: - ${COMIC_BOOK_HOST_PATH}:${COMIC_BOOK_VOLUME} - media_files:/media - .env:/src/.env + # The image HEALTHCHECK probes the web port, which this service never serves. + healthcheck: + disable: true command: sh entrypoint-cron.sh restart: unless-stopped