Skip to content

Commit

Permalink
Updated Laravel automations
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydrogers committed Nov 27, 2023
1 parent f257535 commit fcfed51
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ We like to customize our images on a per app basis using environment variables.

**Variable Name**|**Description**|**Used in variation**
:-----:|:-----:|:-----:
`AUTORUN_ENABLED`<br />*Default: "false"*|Enable or disable all autoruns. It's advised to set this to `false` in certain CI environments (especially during a composer install)| all
`AUTORUN_LARAVEL_CONFIG_CACHE`<br />*⚠️ Depends on: `AUTORUN_ENABLED`*<br />*Default: "true"*|Automatically run "php artisan config:cache" on container start| all
`AUTORUN_LARAVEL_EVENT_CACHE`<br />*⚠️ Depends on: `AUTORUN_ENABLED`*<br />*Default: "true"*|Automatically run "php artisan event:cache" on container start| all
`AUTORUN_LARAVEL_MIGRATION`<br />*⚠️ Depends on: `AUTORUN_ENABLED`*<br />*Default: "true"*|Requires Laravel v9.38.0 or higher. Automatically run "php artisan migrate --force --isolated" on container start.| all
`AUTORUN_LARAVEL_ROUTE_CACHE`<br />*⚠️ Depends on: `AUTORUN_ENABLED`*<br />*Default: "true"*|Automatically run "php artisan route:cache" on container start| all
`AUTORUN_LARAVEL_STORAGE_LINK`<br />*⚠️ Depends on: `AUTORUN_ENABLED`*<br />*Default: "true"*|Automatically run "php artisan storage:link" on container start| all
`AUTORUN_LARAVEL_VIEW_CACHE`<br />*⚠️ Depends on: `AUTORUN_ENABLED`*<br />*Default: "true"*|Automatically run "php artisan view:cache" on container start| all
`APP_BASE_DIR`<br />*Default: "/var/www/html"*|Change this only if you mount your application to a different directory within the container.|all
`COMPOSER_ALLOW_SUPERUSER`<br />*Default: "1"*|Disable warning about running as super-user|all
`COMPOSER_HOME`<br />*Default: "/composer"*|The COMPOSER_HOME variable allows you to change the Composer home directory. This is a hidden, global (per-user on the machine) directory that is shared between all projects.|all
Expand Down Expand Up @@ -48,9 +55,6 @@ We like to customize our images on a per app basis using environment variables.
:-----:|:-----:|:-----:
`PUID`<br />*Default: 9999*|User ID the webserver and PHP should run as.|all
`PGID`<br />*Default: 9999*|Group ID the webserver and PHP should run as.|all
`AUTORUN_ENABLED`<br />*Default: "false"*|Enable or disable all autoruns. It's advised to set this to `false` in certain CI environments (especially during a composer install)|fpm,<br />fpm-nginx,<br />fpm-apache
`AUTORUN_LARAVEL_STORAGE_LINK`<br />*Default: "true"*|Automatically run "php artisan storage:link" on container start|fpm,<br />fpm-nginx,<br />fpm-apache
`AUTORUN_LARAVEL_MIGRATION`<br />*Default: "false"*|Requires Laravel v9.38.0 or higher. Automatically run "php artisan migrate --force --isolated" on container start.|fpm,<br />fpm-nginx,<br />fpm-apache
`MSMTP_RELAY_SERVER_HOSTNAME`<br />*Default: "mailhog"<br /><br />🚨 IMPORTANT: Change this value if you want emails to work. (we set it to <a target="_blank" href="https://github.com/mailhog/MailHog">Mailhog</a> so our staging sites do not send emails out)*|Server that should relay emails for MSMTP. (<a href="https://marlam.de/msmtp/msmtp.html">Official docs</a>)|fpm-nginx,<br />fpm-apache
`MSMTP_RELAY_SERVER_PORT`<br />*Default: "1025" (default port for Mailhog)*|Port the SMTP server is listening on. (<a href="https://marlam.de/msmtp/msmtp.html">Official docs</a>)|fpm-nginx,<br />fpm-apache
`DEBUG_OUTPUT`<br />*Default: (undefined, false)*|Set this variable to `true` if you want to put PHP and your web server in debug mode.|fpm-nginx,<br />fpm-apache
Expand Down
90 changes: 60 additions & 30 deletions src/common/etc/entrypoint.d/50-laravel-automations.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,63 @@ fi
# Exit on error
set -e

echo "Laravel automations"

# # Check to see if an Artisan file exists and assume it means Laravel is configured.
# if [ -f $WEB_APP_DIRECTORY/artisan ] && [ ${AUTORUN_ENABLED:="true"} == "true" ]; then
# echo "Checking for Laravel automations..."

# ############################################################################
# # Automated database migrations
# ############################################################################
# if [ ${AUTORUN_LARAVEL_MIGRATION:="false"} == "true" ]; then
# echo "🚀 Running migrations..."
# php $WEB_APP_DIRECTORY/artisan migrate --force --isolated
# fi

# ############################################################################
# # Automated storage linking
# ############################################################################
# if [ ${AUTORUN_LARAVEL_STORAGE_LINK:="true"} == "true" ]; then
# if [ -d $WEB_APP_DIRECTORY/public/storage ]; then
# echo "✅ Storage already linked..."
# else
# echo "🔐 Linking the storage..."
# php $WEB_APP_DIRECTORY/artisan storage:link
# fi
# fi
# else
# echo "👉 Skipping Laravel automations because we could not detect a Laravel install or it was specifically disabled..."
# fi

# exit 0
# Check to see if an Artisan file exists and assume it means Laravel is configured.
if [ -f $APP_BASE_DIR/artisan ] && [ ${AUTORUN_ENABLED:="true"} == "true" ]; then
echo "Checking for Laravel automations..."

############################################################################
# artisan config:cache
############################################################################
if [ ${AUTORUN_LARAVEL_CONFIG_CACHE:="true"} == "true" ]; then
echo "🚀 Caching Laravel config..."
php $APP_BASE_DIR/artisan config:cache
fi

############################################################################
# artisan route:cache
############################################################################
if [ ${AUTORUN_LARAVEL_ROUTE_CACHE:="true"} == "true" ]; then
echo "🚀 Caching Laravel routes..."
php $APP_BASE_DIR/artisan route:cache
fi

############################################################################
# artisan view:cache
############################################################################
if [ ${AUTORUN_LARAVEL_VIEW_CACHE:="true"} == "true" ]; then
echo "🚀 Caching Laravel views..."
php $APP_BASE_DIR/artisan view:cache
fi

############################################################################
# artisan event:cache
###########################################################################
if [ ${AUTORUN_LARAVEL_EVENT_CACHE:="true"} == "true" ]; then
echo "🚀 Caching Laravel events..."
php $APP_BASE_DIR/artisan event:cache
fi

############################################################################
# artisan migrate
############################################################################
if [ ${AUTORUN_LARAVEL_MIGRATION:="false"} == "true" ]; then
echo "🚀 Running migrations..."
php $APP_BASE_DIR/artisan migrate --force --isolated
fi

############################################################################
# Automated storage linking
############################################################################
if [ ${AUTORUN_LARAVEL_STORAGE_LINK:="true"} == "true" ]; then
if [ -d $APP_BASE_DIR/public/storage ]; then
echo "✅ Storage already linked..."
else
echo "🔐 Linking the storage..."
php $APP_BASE_DIR/artisan storage:link
fi
fi
else
echo "👉 Skipping Laravel automations because we could not detect a Laravel install or it was specifically disabled..."
fi

exit 0

0 comments on commit fcfed51

Please sign in to comment.