From 32e59e289b1f16f5783dc22fe73f6a2669a1a9ff Mon Sep 17 00:00:00 2001 From: Benjamin Brummer Date: Fri, 26 Sep 2025 15:17:44 +0200 Subject: [PATCH 1/3] Add healthcheck as condition for app --- debian/docker-compose.yml | 3 ++- docker/app/public/.keep | 1 - docker/app/storage/.keep | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 docker/app/public/.keep delete mode 100644 docker/app/storage/.keep diff --git a/debian/docker-compose.yml b/debian/docker-compose.yml index ce9ad7d..ec2429f 100644 --- a/debian/docker-compose.yml +++ b/debian/docker-compose.yml @@ -40,7 +40,8 @@ services: networks: - app-network depends_on: - - app + app: + condition: service_healthy logging: *default-logging mysql: diff --git a/docker/app/public/.keep b/docker/app/public/.keep deleted file mode 100644 index 8b13789..0000000 --- a/docker/app/public/.keep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/docker/app/storage/.keep b/docker/app/storage/.keep deleted file mode 100644 index 8b13789..0000000 --- a/docker/app/storage/.keep +++ /dev/null @@ -1 +0,0 @@ - From 7bd0a562604dbb76e97d7d913b2d5d813f1f7dc0 Mon Sep 17 00:00:00 2001 From: Benjamin Brummer Date: Sun, 28 Sep 2025 09:15:17 +0200 Subject: [PATCH 2/3] Increase start-period, as initialization and migrations can take some time --- debian/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/Dockerfile b/debian/Dockerfile index 4dce691..e4595bd 100644 --- a/debian/Dockerfile +++ b/debian/Dockerfile @@ -82,7 +82,7 @@ COPY --from=prepare-app /tmp/public /tmp/public COPY --chmod=0755 scripts/init.sh /usr/local/bin/init.sh # Health check -HEALTHCHECK --start-period=10s \ +HEALTHCHECK --start-period=100s \ CMD REMOTE_ADDR=127.0.0.1 REQUEST_URI=/health REQUEST_METHOD=GET SCRIPT_FILENAME=/var/www/html/public/index.php cgi-fcgi -bind -connect 127.0.0.1:9000 | grep '{"status":"ok","message":"API is healthy"}' ENTRYPOINT ["/usr/local/bin/init.sh"] From 91a2a106e085ba309aab8db70173a780f77f5fd1 Mon Sep 17 00:00:00 2001 From: Benjamin Brummer Date: Sun, 28 Sep 2025 09:15:52 +0200 Subject: [PATCH 3/3] Optimize artisan commands --- debian/scripts/init.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/debian/scripts/init.sh b/debian/scripts/init.sh index 1f688e2..79824de 100755 --- a/debian/scripts/init.sh +++ b/debian/scripts/init.sh @@ -41,24 +41,26 @@ if [ "$*" = 'supervisord -c /etc/supervisor/supervisord.conf' ]; then # Clear and cache config in production if [ "$APP_ENV" = "production" ]; then - runuser -u www-data -- php artisan optimize runuser -u www-data -- php artisan package:discover - runuser -u www-data -- php artisan migrate --force + runuser -u www-data -- php artisan migrate --force + runuser -u www-data -- php artisan cache:clear # Clear after the migration + runuser -u www-data -- php artisan ninja:design-update + runuser -u www-data -- php artisan optimize # If first IN run, it needs to be initialized - if [ "$(php -d opcache.preload='' artisan tinker --execute='echo Schema::hasTable("accounts") && !App\Models\Account::all()->first();')" = "1" ]; then + if [ "$(runuser -u www-data -- php artisan tinker --execute='echo Schema::hasTable("accounts") && !App\Models\Account::all()->first();')" = "1" ]; then echo "Running initialization..." - - php artisan db:seed --force + + runuser -u www-data -- php artisan db:seed --force if [ -n "${IN_USER_EMAIL}" ] && [ -n "${IN_PASSWORD}" ]; then - php artisan ninja:create-account --email "${IN_USER_EMAIL}" --password "${IN_PASSWORD}" + runuser -u www-data -- php artisan ninja:create-account --email "${IN_USER_EMAIL}" --password "${IN_PASSWORD}" else echo "Initialization failed - Set IN_USER_EMAIL and IN_PASSWORD in .env" exit 1 fi - fi + fi echo "Production setup completed" fi