From 74bebe64519c9bfdb1e9a9230c8a8fe5394304b2 Mon Sep 17 00:00:00 2001 From: Marwin Schulz Date: Fri, 20 Mar 2026 09:16:29 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20cron=20container:=20switch=20dcron?= =?UTF-8?q?=E2=86=92cron,=20export=20env=20vars=20for=20cron=20jobs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - dcron doesn't support /etc/cron.d/ (vixie-cron format) — replace with standard 'cron' (vixie cron) which does - Cron jobs run with a stripped environment and couldn't reach the database; fix by dumping Docker env vars to /etc/environment at startup and sourcing it in the cron job entry Co-Authored-By: Claude Sonnet 4.6 --- Dockerfile.cron | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Dockerfile.cron b/Dockerfile.cron index 8b1a4bb..afa77b6 100644 --- a/Dockerfile.cron +++ b/Dockerfile.cron @@ -2,7 +2,7 @@ FROM python:3.12-slim WORKDIR /app -RUN apt-get update && apt-get install -y --no-install-recommends dcron && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y --no-install-recommends cron && rm -rf /var/lib/apt/lists/* COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt @@ -10,9 +10,12 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . # Write cron job: refresh podcast feeds every hour -RUN echo "0 * * * * root cd /app && python manage.py refresh_feeds >> /var/log/cron.log 2>&1" \ +# The job sources /etc/environment so Docker env vars (DB path, secret key etc.) are available. +RUN echo "0 * * * * root . /etc/environment; cd /app && python manage.py refresh_feeds >> /var/log/cron.log 2>&1" \ > /etc/cron.d/podcast-refresh && \ chmod 0644 /etc/cron.d/podcast-refresh && \ touch /var/log/cron.log -CMD ["dcron", "-f"] +# Dump Docker env vars into /etc/environment at container start so cron jobs can read them, +# then launch vixie cron in foreground. +CMD ["bash", "-c", "printenv > /etc/environment && cron -f"]