From 5bd99b47b60981560e7b07b28d75de44b7cb00b9 Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Mon, 24 Jul 2023 17:34:38 +0200 Subject: [PATCH] Merge entrypoints --- .docker/horizon-entrypoint | 13 ------------- .docker/php-entrypoint | 30 ------------------------------ .docker/php.Dockerfile | 4 ++-- .docker/php/entrypoint | 35 +++++++++++++++++++++++++++++++++++ .dockerignore | 1 + .gitignore | 1 + docker-compose.yml | 3 ++- 7 files changed, 41 insertions(+), 46 deletions(-) delete mode 100755 .docker/horizon-entrypoint delete mode 100755 .docker/php-entrypoint create mode 100755 .docker/php/entrypoint diff --git a/.docker/horizon-entrypoint b/.docker/horizon-entrypoint deleted file mode 100755 index 4237b9d0..00000000 --- a/.docker/horizon-entrypoint +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -e - -# ------------------------- check for database access ------------------------- -function wait_for_db { - while true; do - echo "waiting for Database init" - php -r 'new PDO("mysql:host='$DB_HOST';dbname='$DB_DATABASE'", "'$DB_USERNAME'", "'$DB_PASSWORD'");' > /dev/null && return 0 - done -} - -su www-data -c 'php artisan horizon' -s /bin/sh diff --git a/.docker/php-entrypoint b/.docker/php-entrypoint deleted file mode 100755 index 8237941e..00000000 --- a/.docker/php-entrypoint +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -set -e - -# --------------------------- ensure appkey is set ---------------------------- -if [ $APP_KEY = "YOUR_APP_KEY" ]; then - echo "----------------------- Keinen APP KEY gefunden. Key wird generiert: $(php artisan key:generate --show) ----------------------- Füge diesen Key als APP_KEY ein ---------------------" - exit 1 -fi - -# ------------------------- check for database access ------------------------- -function wait_for_db { - while true; do - echo "waiting for Database init" - php -r 'new PDO("mysql:host='$DB_HOST';dbname='$DB_DATABASE'", "'$DB_USERNAME'", "'$DB_PASSWORD'");' > /dev/null && return 0 - sleep 1 - done -} - -wait_for_db - -php -r '$connection = new PDO("mysql:host='$DB_HOST';dbname='$DB_DATABASE'", "'$DB_USERNAME'", "'$DB_PASSWORD'"); $connection->query("DESCRIBE migrations");' > /dev/null || php artisan migrate --seed --force -php artisan migrate --force - -mkdir /app/packages/laravel-nami/.cookies || true -mkdir /app/storage/app || true -chown -R www-data:www-data /app/packages/laravel-nami/.cookies -chown -R www-data:www-data /app/storage/app - -php-fpm -F -R -O diff --git a/.docker/php.Dockerfile b/.docker/php.Dockerfile index 3d97dbbd..da28e88b 100644 --- a/.docker/php.Dockerfile +++ b/.docker/php.Dockerfile @@ -18,14 +18,14 @@ RUN pecl install redis && docker-php-ext-enable redis COPY --chown=www-data:www-data . /app COPY --chown=www-data:www-data --from=node /app/public /app/public COPY --chown=www-data:www-data --from=composer /app/vendor /app/vendor +RUN usermod -s /bin/bash www-data USER www-data RUN php artisan telescope:publish RUN php artisan horizon:publish USER root -COPY ./.docker/php-entrypoint /bin/php-entrypoint -COPY ./.docker/horizon-entrypoint /bin/horizon-entrypoint +COPY ./.docker/php /bin VOLUME ["/app/packages/laravel-nami/.cookies", "/app/storage/app"] diff --git a/.docker/php/entrypoint b/.docker/php/entrypoint new file mode 100755 index 00000000..e5cddce1 --- /dev/null +++ b/.docker/php/entrypoint @@ -0,0 +1,35 @@ +#!/bin/bash + +set -e + +function wait_for_db { + while true; do + echo "waiting for Database init" + php -r 'new PDO("mysql:host='$DB_HOST';dbname='$DB_DATABASE'", "'$DB_USERNAME'", "'$DB_PASSWORD'");' > /dev/null && return 0 + sleep 1 + done +} + +mkdir /app/packages/laravel-nami/.cookies || true +mkdir /app/storage/app || true +chown -R www-data:www-data /app/packages/laravel-nami/.cookies +chown -R www-data:www-data /app/storage/app + +if [ $1 == "horizon" ]; then + wait_for_db + su www-data -c 'php artisan horizon' +fi + +if [ $1 == "app" ]; then + # --------------------------- ensure appkey is set ---------------------------- + if [ $APP_KEY = "YOUR_APP_KEY" ]; then + echo "----------------------- Keinen APP KEY gefunden. Key wird generiert: $(su www-data -c 'php artisan key:generate --show') ----------------------- Füge diesen Key als APP_KEY ein ---------------------" + exit 1 + fi + wait_for_db + php -r '$connection = new PDO("mysql:host='$DB_HOST';dbname='$DB_DATABASE'", "'$DB_USERNAME'", "'$DB_PASSWORD'"); $connection->query("DESCRIBE migrations");' > /dev/null || php artisan migrate --seed --force + su www-data -c 'php artisan migrate --force' + php-fpm -F -R -O +fi + + diff --git a/.dockerignore b/.dockerignore index 9163726b..ddeed279 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,3 +8,4 @@ bootstrap/cache/packages.php bootstrap/cache/routes.php packages/laravel-nami/.cookies app/storage/app +cookies diff --git a/.gitignore b/.gitignore index 70375717..21344789 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ resources/img/sprite.svg /.php-cs-fixer.cache /data .app.env +cookies diff --git a/docker-compose.yml b/docker-compose.yml index c745f5dc..dcd65717 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,7 @@ services: dockerfile: ./.docker/php.Dockerfile depends_on: - db + command: /bin/entrypoint app env_file: - .app.env environment: @@ -38,7 +39,7 @@ services: depends_on: - db - php - command: /bin/horizon-entrypoint + command: /bin/entrypoint horizon env_file: - .app.env environment: