From 1a3a306db545ed42014b592e162d0079cbb2b60d Mon Sep 17 00:00:00 2001 From: b1ek Date: Sat, 5 Oct 2024 13:18:21 +1000 Subject: [PATCH] init: cron job --- .gitignore | 3 +++ docker-compose.yml | 3 ++- docker/php-fpm/Dockerfile | 9 ++++++++- docker/php-fpm/crontab.txt | 1 + docker/php-fpm/supervisord.conf | 17 +++++++++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 docker/php-fpm/crontab.txt create mode 100644 docker/php-fpm/supervisord.conf diff --git a/.gitignore b/.gitignore index acf20d8..9731f80 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,6 @@ ###< symfony/framework-bundle ### /.idea/ + +/supervisord.log +/supervisord.pid diff --git a/docker-compose.yml b/docker-compose.yml index 6aaa157..7111dbd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,7 +33,8 @@ services: container_name: php-fpm volumes: - ./:/app - - ./docker/php-fpm/php.ini:/usr/local/etc/php/php.ini + - ./docker/php-fpm/php.ini:/usr/local/etc/php/php.ini:ro + - ./docker/php-fpm/supervisord.conf:/etc/supervisord.conf:ro links: - mysql diff --git a/docker/php-fpm/Dockerfile b/docker/php-fpm/Dockerfile index 6325363..a8defa2 100644 --- a/docker/php-fpm/Dockerfile +++ b/docker/php-fpm/Dockerfile @@ -1,4 +1,11 @@ -FROM php:8.3-fpm +FROM php:8.3-fpm-alpine3.20 WORKDIR /app +RUN apk add supervisor + RUN docker-php-ext-install pdo pdo_mysql + +COPY crontab.txt /etc/cron.d/update-users +RUN cat /etc/cron.d/update-users >> /etc/crontabs/root + +CMD [ "/usr/bin/supervisord", "-c", "/etc/supervisord.conf" ] diff --git a/docker/php-fpm/crontab.txt b/docker/php-fpm/crontab.txt new file mode 100644 index 0000000..879e74b --- /dev/null +++ b/docker/php-fpm/crontab.txt @@ -0,0 +1 @@ +*/15 * * * * /app/bin/console app:update-all-users-cron diff --git a/docker/php-fpm/supervisord.conf b/docker/php-fpm/supervisord.conf new file mode 100644 index 0000000..ae3fd4d --- /dev/null +++ b/docker/php-fpm/supervisord.conf @@ -0,0 +1,17 @@ +[supervisord] +nodaemon=true + +[program:cron] +command=/usr/bin/env sh -c "crond -f" +stdout_logfile=/var/log/cron +stderr_logfile=/var/log/cron.stderr +stdout_logfile_maxbytes=0 +stderr_logfile_maxbytes=0 +autorestart=true + +[program:php-fpm] +command=docker-php-entrypoint php-fpm +stdout_logfile=/dev/stdout +stderr_logfile=/dev/stderr +stdout_logfile_maxbytes=0 +stderr_logfile_maxbytes=0