Added cronjob to Dockerfile

This commit is contained in:
Keannu Bernasol 2023-10-02 01:32:03 +08:00
parent a970c4c925
commit 9515b25a7b
2 changed files with 23 additions and 1 deletions

View file

@ -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

2
cronjob Normal file
View file

@ -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.