![]() The biggest hurdle was making the environment variables visible to the cron job. ![]() templates/crontab file from the image repoĬron & tail -f /var/log/cron.log # run cron and append its logs # to the log file from our task Why so complicated? #!/bin/bash env > /tmp/.env # save all the environment variables # into /tmp/.env cat /tmp/.env > /etc/cron.d/my-cron-job # write the environment # variables into the cron job configuration echo -n " $TASK_SCHEDULE " | cat - /tmp/crontab > /etc/cron.d/my-cron-job # write the TASK_SCHEDULE variable # into the cron job configuration # along with the contents # of the /tmp/crontab file # which is nothing more than the #. templates/crontab contains the initial template of our cron job. RUN chmod +x /tmp/setupCron.sh # give execution permissions to the commandĬMD # configure the command to run when the container runs templates/crontab templates/setupCron.sh will be # executed when the container runs # it will be explained in details later # more info => templates/setupCron.sh /tmp/setupCron.sh # to execute our cronjob we must run multiple commands # it is not possible to do it directly from the Dockerfile # the file. RUN touch /var/log/cron.log # the logs from our job # this line creates the log file preemptivelyĬOPY. RUN chmod 0644 /etc/cron.d/my-cron-job # give permissions to the cron job configuration file RUN touch /etc/cron.d/my-cron-job # our cron job configuration will end up in /etc/cron.d/my-cron-job # this line creates the file preemptively templates/crontab will be the base template # for all of our cron jobs # it will be explained in details later on templates/crontab /tmp/crontab # cronjobs are configured as files # with a very specific format # the file. RUN mkdir -p /usr/src/app # our code will be shipped with the new container # into the /usr/src/app directory # this line creates the directory preemptivelyĬOPY. RUN apt-get update & apt-get install -y cron # install cron # more info => # => FROM node:latest # base this image off the official node image # if you need a specific node version # simply change latest for what you want # more info here =>
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |