From 659ea7c3fb02dbfbccc145d4d271df39d1f23281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sat, 17 Aug 2024 20:53:11 +0200 Subject: [PATCH] feat: add cron to container --- Dockerfile | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 54c0e01..26fb371 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,13 +3,33 @@ FROM python:3.12-bookworm # Labels LABEL MAINTAINER="Jan-Ole Hübner " +# Install cron +RUN apt-get update && apt-get install -y cron + +# Add the requirements ADD requirements.txt / RUN pip3 install -r /requirements.txt # Environment ENV PYTHONIOENCODING=utf-8 + +# Add the application code ADD . / -# Chmod +# Add the cron job +RUN echo "*/15 * * * * python3 /get_price.py >> /var/log/cron.log 2>&1" > /etc/cron.d/get_price + +# Give execution rights on the cron job +RUN chmod 0644 /etc/cron.d/get_price + +# Apply the cron job +RUN crontab /etc/cron.d/get_price + +# Create the log file to be able to run tail +RUN touch /var/log/cron.log + +# Chmod for your main application script RUN chmod 755 /pulse.py -CMD ["python3","/pulse.py"] \ No newline at end of file + +# Run the command on container startup +CMD cron && tail -f /var/log/cron.log