From b48c38cee15f41cc98e52d710a141c6b252c7530 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 7 May 2018 13:34:45 +1000 Subject: [PATCH] Enabled multi-use container invocation with roles --- Dockerfile | 6 +++--- start | 31 ++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index daa5685..f144f36 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,9 +12,9 @@ RUN (cd / && patch -p0 ) < /tmp/sshd_config.patch && rm /tmp/sshd_config.patch EXPOSE 9000/tcp 22/tcp +RUN docker-php-ext-install -j$(nproc) pdo_mysql pdo_pgsql +RUN curl https://getcomposer.org/installer|php -- --install-dir=/usr/local/bin --filename=composer + COPY start /usr/local/sbin ENTRYPOINT [ "/usr/local/sbin/start" ] CMD [ "php-fpm" ] - -RUN docker-php-ext-install -j$(nproc) pdo_mysql pdo_pgsql -RUN curl https://getcomposer.org/installer|php -- --install-dir=/usr/local/bin --filename=composer diff --git a/start b/start index 2b2c214..f873117 100755 --- a/start +++ b/start @@ -5,4 +5,33 @@ if [ -x /usr/sbin/sshd -a "${SSH_START}" = "TRUE" ]; then start-stop-daemon --start --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- -p 22 fi -exec /usr/local/bin/docker-php-entrypoint "$@" +set -e + +role=${CONTAINER_ROLE:-app} +env=${APP_ENV:-production} + +if [ "${env}" != "local" -a -r "artisan" ]; then + echo "Caching configuration..." + (cd /var/www/html && php artisan config:cache && php artisan route:cache && php artisan view:cache) +fi + +if [ "${role}" = "app" ]; then + + exec /usr/local/bin/docker-php-entrypoint "$@" + +elif [ "$role" = "queue" ]; then + + echo "Running the queue..." + php /var/www/html/artisan queue:work --verbose --tries=3 --timeout=90 + +elif [ "$role" = "scheduler" ]; then + + while [ true ]; do + php /var/www/html/artisan schedule:run --verbose --no-interaction & + sleep 60 + done + +else + echo "Could not match the container role \"${role}\"" + exit 1 +fi