1
0
Fork 0

build: add mappings sync cron

This commit is contained in:
thibaud-leclere 2026-05-05 11:23:28 +02:00
parent e53b4ca85a
commit 5b86d89be2
4 changed files with 26 additions and 0 deletions

View file

@ -10,6 +10,7 @@ Exemple : un mapping `mcp/graylog/install.sh` peut servir le fichier `install.sh
- `/` redirige vers lURL configurée dans `/admin/settings`, ou vers `/admin` si aucune URL nest configurée. - `/` redirige vers lURL configurée dans `/admin/settings`, ou vers `/admin` si aucune URL nest 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. - 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. - 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 limage relance `app:mappings:sync` toutes les 5 minutes.
- Les chemins publics hors `/admin` servent uniquement les scripts déjà synchronisés. - Les chemins publics hors `/admin` servent uniquement les scripts déjà synchronisés.
- Un token daccès optionnel peut être renseigné pour les dépôts privés en HTTPS. Il est utilisé via `GIT_ASKPASS` pendant la synchronisation. - Un token daccè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-data` : base SQLite `/app/var/data/app.db`
- `app-cache` : dépôts clonés et scripts servis depuis `/app/var/bootstrap-cache` - `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 limage `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 : Créer ou mettre à jour un compte admin :
```bash ```bash

4
crontab Normal file
View file

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

View file

@ -14,8 +14,10 @@ RUN composer install --no-dev --prefer-dist --no-interaction --no-progress --no-
COPY . . COPY . .
COPY docker/php/php.ini /usr/local/etc/php/conf.d/app.ini COPY docker/php/php.ini /usr/local/etc/php/conf.d/app.ini
COPY docker/entrypoint.sh /usr/local/bin/app-entrypoint COPY docker/entrypoint.sh /usr/local/bin/app-entrypoint
COPY crontab /etc/crontabs/root
RUN chmod +x /usr/local/bin/app-entrypoint \ RUN chmod +x /usr/local/bin/app-entrypoint \
&& chmod 0600 /etc/crontabs/root \
&& mkdir -p var/data var/bootstrap-cache \ && mkdir -p var/data var/bootstrap-cache \
&& composer dump-autoload --classmap-authoritative --no-dev \ && composer dump-autoload --classmap-authoritative --no-dev \
&& composer run-script --no-dev post-install-cmd \ && composer run-script --no-dev post-install-cmd \

View file

@ -5,7 +5,24 @@ mkdir -p /app/var/data /app/var/bootstrap-cache
chown -R www-data:www-data /app/var chown -R www-data:www-data /app/var
if [ "${APP_ENV:-prod}" != "test" ]; then 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 php /app/bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration
fi 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 "$@" exec "$@"