jackbrycesmith / laravel-caprover-template

Template to deploy a Laravel app in docker for CapRover
MIT License
127 stars 44 forks source link

Crontab issue #10

Open hotrush opened 4 years ago

hotrush commented 4 years ago

I can see this during image build

Step 5/39 : RUN (crontab -l ; echo "* * * * * /usr/local/bin/php /srv/app/artisan schedule:run >> /dev/null 2>&1") | crontab
 ---> Running in 224010ada790
no crontab for root
dragonfire1119 commented 4 years ago

@hotrush I had the same problem had to alter the code a bit.

# Add crontab file in the cron directory
ADD ./.deploy/config/schedule/crontab /etc/cron.d/cron

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/cron

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

# Run the command on container startup
CMD printenv > /etc/environment && echo "cron starting..." && (cron) && : > /var/log/cron.log && tail -f /var/log/cron.log
darr1s commented 4 years ago

@dragonfire1119 mind sharing where do you place these lines?

dragonfire1119 commented 4 years ago

@darrist Placed it right under

# RUN (crontab -l ; echo "* * * * * /usr/local/bin/php /srv/app/artisan schedule:run >> /dev/null 2>&1") | crontab
darr1s commented 4 years ago

I have this:

RUN apt-get update && apt-get install -y build-essential cron curl locales zip unzip git

# Setup cron job
# RUN (crontab -l ; echo "* * * * * /usr/local/bin/php /srv/app/artisan schedule:run >> /dev/null 2>&1") | crontab

# Add crontab file in the cron directory
ADD ./.deploy/config/schedule/crontab /etc/cron.d/cron

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/cron

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

# Run the command on container startup
CMD printenv > /etc/environment && echo "cron starting..." && (cron) && : > /var/log/cron.log && tail -f /var/log/cron.log

# Install supervisord
COPY --from=ochinchina/supervisord:latest /usr/local/bin/supervisord /usr/local/bin/supervisord

.deploy/config/scheduler/crontab:

* * * * * /usr/local/bin/php /srv/app/artisan schedule:run >> /dev/null 2>&1

Will report back if its working. Thanks!

darr1s commented 4 years ago

Cron doesn't seem to be running.

hotrush commented 4 years ago

Haven't tested it yet, but i tried another approach from here https://github.com/thelebster/docker-cron/blob/master/ubuntu/Dockerfile And it doesn't work too... So painful to make it works

jackbrycesmith commented 3 years ago

Would recommend trying out all the latest changes on the master branch following the move to the alpine image & running all services as a non-root user in https://github.com/jackbrycesmith/laravel-caprover-template/pull/5.