From 5943f0df5a67af96949937abf651de0998f7c0c0 Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 29 Jan 2020 15:37:53 +1100 Subject: [PATCH] Cache config in role containers if container contains the app and change mountpoint detection routine --- init | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/init b/init index fb335d9..5f68d30 100755 --- a/init +++ b/init @@ -6,6 +6,14 @@ env=${APP_ENV:-live} php=${PHP_DIR:-/var/www/html} composer=${COMPOSER_DIR:-/var/www/.composer} +function mp() { + set +e + mountpoint -q $1 + local mp=$? + set -e + return ${mp} +} + # General Setup if [ -x /usr/sbin/sshd -a "${SSH_START}" = "TRUE" ]; then [ ! -d /var/run/sshd ] && mkdir /var/run/sshd @@ -19,10 +27,8 @@ if [ "${role}" = "app" -a -e artisan ]; then exec /bin/bash fi - set +e - mountpoint -q ${php} + mp ${php} mp=$? - set -e # Only adjust perms if this is an external mountpoint if [ ${mp} -eq 0 -o -n "${FORCE_PERMS}" ] ; then @@ -47,10 +53,8 @@ if [ "${role}" = "app" -a -e artisan ]; then NODEV="--no-dev" fi - set +e - mountpoint -q ${composer} + mp ${php} mp=$? - set -e if [ ${mp} -eq 0 -o -n "${FORCE_PERMS}" ] ; then [ -n "${FORCE_PERMS}" -o "${env}" != "dev" -a -z "${SKIP_PERM}" ] && chown -R www-data:www-data ${composer} @@ -62,13 +66,13 @@ if [ "${role}" = "app" -a -e artisan ]; then [ -n "${FORCE_PERMS}" -o "${env}" != "dev" -a -z "${SKIP_PERM}" ] && [ ${mp} -eq 0 ] && chmod g-w ${php} fi + echo "* Caching configuration..." + su www-data -s /bin/sh -c "(php artisan config:cache && php artisan route:cache && php artisan view:cache)" + if [ -r .migrate ]; then echo "* Running migration..." su www-data -s /bin/sh -c "php artisan migrate" && rm -f .migrate fi - - echo "* Caching configuration..." - su www-data -s /bin/sh -c "(php artisan config:cache && php artisan route:cache && php artisan view:cache)" fi exec /usr/local/bin/docker-php-entrypoint "$@" @@ -79,6 +83,12 @@ elif [ "$role" = "queue" -a -e artisan ]; then exec /bin/bash fi + # We only check for non mount points, in case this container has the app inside + if ! mp ${php}; then + echo "* Caching configuration..." + su www-data -s /bin/sh -c "(php artisan config:cache && php artisan route:cache && php artisan view:cache)" + fi + echo "* Running the queue..." # We'll delay starting in case the app is caching sleep 15 @@ -95,6 +105,12 @@ elif [ "$role" = "scheduler" -a -e artisan ]; then exec /bin/bash fi + # We only check for non mount points, in case this container has the app inside + if ! mp ${php}; then + echo "* Caching configuration..." + su www-data -s /bin/sh -c "(php artisan config:cache && php artisan route:cache && php artisan view:cache)" + fi + echo "* Running the scheduler..." # We'll delay starting in case the app is caching sleep 15