From ff6c668c47081c1c4b65734a87d61c338e896b3b Mon Sep 17 00:00:00 2001 From: Kolman-Freecss Date: Wed, 8 Feb 2023 21:56:18 +0100 Subject: [PATCH] - Update to Python 3.10 - Execute crontab using only the keyword 'crontab' - Creation and execution of a virtual environment inside docker - Tail the logs to check the logs directly on the console --- Dockerfile | 19 +++++++++++++++---- crontab | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9d69774..fc2c87d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,23 @@ -FROM python:3.7 +FROM python:3.10 + RUN apt-get update && apt-get -y install cron vim + WORKDIR /app + COPY crontab /etc/cron.d/crontab COPY hello.py /app/hello.py + RUN chmod 0644 /etc/cron.d/crontab -RUN /usr/bin/crontab /etc/cron.d/crontab +RUN crontab /etc/cron.d/crontab + +# Create a virtual environment +RUN python -m venv /opt/venv -# run crond as main process of container -CMD ["cron", "-f"] +# Activate the virtual environment +ENV PATH="/opt/venv/bin:$PATH" +# Create empty log (TAIL needs this) +RUN touch /tmp/out.log +# Run cron and tail the log +CMD cron && tail -f /tmp/out.log \ No newline at end of file diff --git a/crontab b/crontab index 142b69b..ac7af48 100644 --- a/crontab +++ b/crontab @@ -1,3 +1,3 @@ # START CRON JOB -* * * * * python /app/hello.py > /proc/1/fd/1 2>/proc/1/fd/2 -# END CRON JOB +* * * * * python3 /app/hello.py >>/tmp/out.log 2>/tmp/err.log +# END CRON JOB \ No newline at end of file