diff --git a/README.md b/README.md index 8b3d753..b1419c0 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Exemple : un mapping `mcp/graylog/install.sh` peut servir le fichier `install.sh - `/` redirige vers l’URL configurée dans `/admin/settings`, ou vers `/admin` si aucune URL n’est configurée. - Un mapping lie un chemin public `.sh` à une URL Git, une référence Git et un chemin de fichier dans le dépôt. - Le bouton `Synchroniser` clone ou met à jour le dépôt, extrait la référence demandée et copie le fichier dans le cache. +- En production, un cron embarqué dans l’image relance `app:mappings:sync` toutes les 5 minutes. - Les chemins publics hors `/admin` servent uniquement les scripts déjà synchronisés. - Un token d’accès optionnel peut être renseigné pour les dépôts privés en HTTPS. Il est utilisé via `GIT_ASKPASS` pendant la synchronisation. @@ -40,6 +41,8 @@ Les migrations SQLite sont exécutées au démarrage du conteneur `app`. Les vol - `app-data` : base SQLite `/app/var/data/app.db` - `app-cache` : dépôts clonés et scripts servis depuis `/app/var/bootstrap-cache` +Le fichier `crontab` à la racine du projet est copié dans l’image `app`. Le cron démarre uniquement quand `APP_ENV=prod` et que le conteneur lance `php-fpm`. + Créer ou mettre à jour un compte admin : ```bash diff --git a/crontab b/crontab new file mode 100644 index 0000000..5b12f78 --- /dev/null +++ b/crontab @@ -0,0 +1,4 @@ +SHELL=/bin/sh +PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +*/5 * * * * . /app/var/cron-env && su -m www-data -s /bin/sh -c 'cd /app && php bin/console app:mappings:sync' >> /proc/1/fd/1 2>> /proc/1/fd/2 diff --git a/docker/Dockerfile b/docker/Dockerfile index 7dc8ee7..57d4057 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -14,8 +14,10 @@ RUN composer install --no-dev --prefer-dist --no-interaction --no-progress --no- COPY . . COPY docker/php/php.ini /usr/local/etc/php/conf.d/app.ini COPY docker/entrypoint.sh /usr/local/bin/app-entrypoint +COPY crontab /etc/crontabs/root RUN chmod +x /usr/local/bin/app-entrypoint \ + && chmod 0600 /etc/crontabs/root \ && mkdir -p var/data var/bootstrap-cache \ && composer dump-autoload --classmap-authoritative --no-dev \ && composer run-script --no-dev post-install-cmd \ diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index a052aa3..ecba473 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -5,7 +5,24 @@ mkdir -p /app/var/data /app/var/bootstrap-cache chown -R www-data:www-data /app/var if [ "${APP_ENV:-prod}" != "test" ]; then + php /app/bin/console cache:clear --no-warmup --no-interaction php /app/bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration fi +if [ "${APP_ENV:-prod}" = "prod" ] && [ "${1:-}" = "php-fpm" ]; then + php -r ' +$names = ["APP_ENV", "APP_DEBUG", "APP_SECRET", "DATABASE_URL", "APP_CACHE_DIR", "DEFAULT_URI"]; +foreach ($names as $name) { + $value = getenv($name); + if ($value !== false) { + echo "export ".$name."=".escapeshellarg($value).PHP_EOL; + } +} +' > /app/var/cron-env + chown www-data:www-data /app/var/cron-env + chmod 0600 /app/var/cron-env + + crond -l 8 -L /proc/1/fd/1 +fi + exec "$@"