From 014add7939d3ef6ce31f614db4d217e5822fe70b Mon Sep 17 00:00:00 2001 From: Arthur de Moulins Date: Tue, 17 Oct 2023 10:21:15 +0200 Subject: [PATCH] WIP --- docker-compose.dev.yml | 4 ++++ docker-compose.yml | 5 +++++ expose/api/Dockerfile | 3 +++ expose/api/docker/cron/app-crontab | 1 + .../docker/cron/scripts/matomo-sync-phraseanet.sh | 4 ++++ expose/api/docker/cron/start-cron.sh | 13 +++++++++++++ .../{ => Command}/SyncMatomoPhraseanetCommand.php | 2 +- 7 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 expose/api/docker/cron/app-crontab create mode 100755 expose/api/docker/cron/scripts/matomo-sync-phraseanet.sh create mode 100755 expose/api/docker/cron/start-cron.sh rename expose/api/src/{ => Command}/SyncMatomoPhraseanetCommand.php (98%) diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 136fb6ea8..b312b17e6 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -59,6 +59,10 @@ services: - ./expose/api:/srv/app - ./expose/api/docker/supervisor:/etc/supervisor.d + expose-cron: + volumes: + - ./expose/api:/srv/app + uploader-api-php: environment: - XDEBUG_ENABLED diff --git a/docker-compose.yml b/docker-compose.yml index 14b0a3dec..4ba10a89d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -533,6 +533,11 @@ services: extra_hosts: - zippy-svc.${PHRASEA_DOMAIN}:${PS_GATEWAY_IP} + expose-cron: + extends: + service: expose-worker + command: ['/srv/app/docker/cron/start-cron.sh'] + expose-api-nginx: profiles: - expose diff --git a/expose/api/Dockerfile b/expose/api/Dockerfile index 3e7b992b6..c79648fbe 100644 --- a/expose/api/Dockerfile +++ b/expose/api/Dockerfile @@ -44,4 +44,7 @@ RUN apk add --no-cache \ COPY docker/supervisor/* /etc/supervisor.d/ +RUN touch /var/log/cron.log \ + && chmod 755 /srv/app/docker/cron/scripts/*.sh + CMD ["/bin/sh", "-c", "/usr/bin/supervisord -n"] diff --git a/expose/api/docker/cron/app-crontab b/expose/api/docker/cron/app-crontab new file mode 100644 index 000000000..cc3be83d1 --- /dev/null +++ b/expose/api/docker/cron/app-crontab @@ -0,0 +1 @@ +30 4 * * * /srv/app/docker/cron/scripts/matomo-sync-phraseanet.sh 2>&1 diff --git a/expose/api/docker/cron/scripts/matomo-sync-phraseanet.sh b/expose/api/docker/cron/scripts/matomo-sync-phraseanet.sh new file mode 100755 index 000000000..cd664828b --- /dev/null +++ b/expose/api/docker/cron/scripts/matomo-sync-phraseanet.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cd /srv/app \ + && bin/console app:matomo:sync-phraseanet diff --git a/expose/api/docker/cron/start-cron.sh b/expose/api/docker/cron/start-cron.sh new file mode 100755 index 000000000..70537f695 --- /dev/null +++ b/expose/api/docker/cron/start-cron.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e + +/usr/bin/crontab /srv/app/docker/cron/app-crontab + +printenv | grep -v "no_proxy" >> /etc/environment + +for script in /srv/app/docker/cron/scripts/*.sh; do + "$script" +done + +/usr/sbin/crond -f -l 2 diff --git a/expose/api/src/SyncMatomoPhraseanetCommand.php b/expose/api/src/Command/SyncMatomoPhraseanetCommand.php similarity index 98% rename from expose/api/src/SyncMatomoPhraseanetCommand.php rename to expose/api/src/Command/SyncMatomoPhraseanetCommand.php index 68a8b15f2..359109e28 100644 --- a/expose/api/src/SyncMatomoPhraseanetCommand.php +++ b/expose/api/src/Command/SyncMatomoPhraseanetCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App; +namespace App\Command; use App\Matomo\MatomoClient; use App\Matomo\PhraseanetClient;