From 9515b25a7bebb7d0f60fca4a785e9a7c4417f9ed Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Mon, 2 Oct 2023 01:32:03 +0800 Subject: [PATCH] Added cronjob to Dockerfile --- Dockerfile | 22 +++++++++++++++++++++- cronjob | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 cronjob diff --git a/Dockerfile b/Dockerfile index f446d4d..8123801 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,9 @@ RUN apt-get update && apt-get install -y \ libminizip-dev \ libspatialite-dev \ gdal-bin \ - libsqlite3-mod-spatialite + libsqlite3-mod-spatialite \ + cron \ + vim # Create directory RUN mkdir /code @@ -40,5 +42,23 @@ RUN python stude/manage.py custom_migrate # Generate DRF Spectacular Documentation RUN python stude/manage.py spectacular --color --file stude/schema.yml +# Copy the cronjob file +COPY cronjob /etc/cron.d/cronjob + +# Give execution rights on the cron job +RUN chmod 0644 /etc/cron.d/cronjob + +# Apply cron job +RUN crontab /etc/cron.d/cronjob + +# Create the log file to be able to run tail +RUN touch /var/log/cron.log + +# Set editor as VIM +RUN export EDITOR=vim + +# Run the command on container startup +CMD cron + # Expose port 8000 for the web server EXPOSE 8000 diff --git a/cronjob b/cronjob new file mode 100644 index 0000000..54e436e --- /dev/null +++ b/cronjob @@ -0,0 +1,2 @@ +*/30 * * * * python /code/stude/manage.py clean_old_entries +# An empty line is required at the end of this file for a valid cron file.