Skip to content

Commit 4233993

Browse files
authored
Give granular controls on Laravel automations (#43)
1 parent e1a4a8e commit 4233993

File tree

6 files changed

+95
-68
lines changed

6 files changed

+95
-68
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You must have these installed on your system.
1414
1. All templates are stored in the `/templates` folder
1515
1. I have a Git "Pre-Commit" hook that runs `build.sh`
1616
1. `build.sh` copies the templates and applies the templates with [yasha](https://github.com/kblomqvist/yasha)
17-
1. All generated files are then stored in the `/php` folder
17+
1. All generated files are then stored in the `/generated-dockerfiles` folder
1818
1. Github Actions will read the generated files and build images from the generated files
1919

2020
# Running things locally

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,19 @@ We have a ton of helpful scripts and security settings configured for managing L
114114
### Automated tasks executed on every container start up
115115
We automatically look at your Laravel `.env` file and determine if theses tasks should be run.
116116

117-
If your `APP_ENV != local`(any environment other than local development), we will automatically run these repetitive tasks for you every time the container spins up:
117+
If your `APP_ENV != local`(any environment other than local development), we :
118118

119119
**Database Migrations:**
120120
```sh
121121
php /var/www/html/artisan migrate --force
122122
```
123+
You must enable this manually by setting `AUTORUN_LARAVEL_MIGRATION=true` on your container.
124+
123125
**Storage Linking:**
124126
```sh
125127
php /var/www/html/artisan storage:link
126128
```
127-
129+
This will run automatically for environments that are not `local`.
128130

129131
### Running a Laravel Task Scheduler
130132
We need to run the [schedule:work](https://laravel.com/docs/8.x/scheduling#running-the-scheduler-locally) command from Laravel. Although the docs say "Running the scheduler locally", this is what we want in production. It will run the scheduler in the foreground and execute it every minute. You can configure your Laravel app for the exact time that a command should run through a [scheduled task](https://laravel.com/docs/8.x/scheduling#scheduling-artisan-commands).
@@ -241,7 +243,8 @@ PHP\_PM\_START\_SERVERS|The number of child processes created on startup. Used o
241243
PHP\_POOL\_NAME|Set the name of your PHP-FPM pool (helpful when running multiple sites on a single server).|fpm,<br />fpm-nginx,<br />fpm-apache|"www"
242244
PHP\_POST\_MAX\_SIZE|Sets max size of post data allowed. (<a href="https://www.php.net/manual/en/ini.core.php#ini.post-max-size">Official docs</a>)|fpm,<br />fpm-nginx,<br />fpm-apache|"100M"
243245
PHP\_UPLOAD\_MAX\_FILE\_SIZE|The maximum size of an uploaded file. (<a href="https://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize">Official docs</a>)|fpm,<br />fpm-nginx,<br />fpm-apache|"100M"
244-
RUN\_LARAVEL\_AUTOMATIONS|Automatically run the Laravel Automations (for non-local Laravel installs only)|fpm,<br />fpm-nginx,<br />fpm-apache|"true"
246+
AUTORUN\_LARAVEL\_STORAGE\_LINK|For non-local Laravel installs only: Automatically run "php artisan storage:link" on container start|fpm,<br />fpm-nginx,<br />fpm-apache|"true"
247+
AUTORUN\_LARAVEL\_MIGRATION|For non-local Laravel installs only: Automatically run "php artisan migrate --force" on container start|fpm,<br />fpm-nginx,<br />fpm-apache|"false"
245248
MSMTP\_RELAY\_SERVER\_HOSTNAME|Server that should relay emails for MSMTP. (<a href="https://marlam.de/msmtp/msmtp.html">Official docs</a>)|fpm-nginx,<br />fpm-apache|"mailhog"<br /><br />🚨 IMPORTANT: Change this value if you want emails to work. (we set it to <a href="https://github.com/mailhog/MailHog">Mailhog</a> so our staging sites do not send emails out)
246249
MSMTP\_RELAY\_SERVER\_PORT|Port the SMTP server is listening on. (<a href="https://marlam.de/msmtp/msmtp.html">Official docs</a>)|fpm-nginx,<br />fpm-apache|"1025" (default port for Mailhog)
247250
DEBUG\_OUTPUT|Set this variable to `true` if you want to put PHP and your web server in debug mode.|fpm-nginx,<br />fpm-apache|(undefined, false)

generated-dockerfiles/7.4/fpm/etc/cont-init.d/50-laravel-automations

+22-16
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,39 @@ if [ -f $WEBUSER_HOME/artisan ]; then
1111
APP_ENV_SETTING=$(cat $WEBUSER_HOME/.env | grep APP_ENV | cut -f2 -d"=")
1212

1313
# If Laravel is not running in development or CI, then automate some production tasks
14-
if [ "$APP_ENV_SETTING" != "local" ] && [ ! -z $APP_ENV_SETTING ] && [ ${CI_ENV:="false"} != "true" ] && [ ${RUN_LARAVEL_AUTOMATIONS:="true"} == "true" ]; then
15-
16-
# ############################################################################
17-
# # Cache management - commented out for now because of a bug with Laravel caching & API Rate limiting
18-
# ############################################################################
19-
# echo "♻️ Refreshing cache..."
20-
# # Clear cache
21-
# su - webuser -c "php $WEBUSER_HOME/artisan cache:clear"
22-
23-
# # Set cache
24-
# su - webuser -c "php $WEBUSER_HOME/artisan route:cache"
25-
# su - webuser -c "php $WEBUSER_HOME/artisan view:cache"
14+
if [ "$APP_ENV_SETTING" != "local" ] && [ ! -z $APP_ENV_SETTING ] && [ ${CI_ENV:="false"} != "true" ]; then
15+
echo "🏃‍♂️ Checking for Laravel automations..."
2616

2717
############################################################################
2818
# Automated database migrations
2919
############################################################################
30-
if grep -q DB_DATABASE $WEBUSER_HOME/.env; then
20+
if [ "grep -q DB_DATABASE $WEBUSER_HOME/.env" ] && [ ${AUTORUN_LARAVEL_MIGRATION:="false"} == "true" ]; then
3121
echo "🚀 Running migrations..."
3222
su - webuser -c "php $WEBUSER_HOME/artisan migrate --force"
3323
fi
3424

3525
############################################################################
3626
# Automated storage linking
3727
############################################################################
38-
echo "🔐 Linking the storage..."
39-
su - webuser -c "php $WEBUSER_HOME/artisan storage:link"
28+
if [ ${AUTORUN_LARAVEL_STORAGE_LINK:="true"} == "true" ]; then
29+
echo "🔐 Linking the storage..."
30+
su - webuser -c "php $WEBUSER_HOME/artisan storage:link"
31+
fi
32+
33+
############################################################################
34+
# Cache management - commented out for now because of a bug with Laravel caching & API Rate limiting
35+
############################################################################
36+
# if [ ${AUTORUN_LARAVEL_REFRESH_CACHE:="true"} == "true" ]; then
37+
# echo "♻️ Refreshing cache..."
38+
# # Clear cache
39+
# su - webuser -c "php $WEBUSER_HOME/artisan cache:clear"
40+
41+
# # Set cache
42+
# su - webuser -c "php $WEBUSER_HOME/artisan route:cache"
43+
# su - webuser -c "php $WEBUSER_HOME/artisan view:cache"
44+
# fi
45+
4046
else
41-
echo "👉 Skipping Laravel production commands because the env is set to 'local', running in CI, or explicitly disabled..."
47+
echo "👉 Skipping Laravel automations because the env is set to 'local' or running in CI..."
4248
fi
4349
fi

generated-dockerfiles/8.0/fpm/etc/cont-init.d/50-laravel-automations

+22-16
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,39 @@ if [ -f $WEBUSER_HOME/artisan ]; then
1111
APP_ENV_SETTING=$(cat $WEBUSER_HOME/.env | grep APP_ENV | cut -f2 -d"=")
1212

1313
# If Laravel is not running in development or CI, then automate some production tasks
14-
if [ "$APP_ENV_SETTING" != "local" ] && [ ! -z $APP_ENV_SETTING ] && [ ${CI_ENV:="false"} != "true" ] && [ ${RUN_LARAVEL_AUTOMATIONS:="true"} == "true" ]; then
15-
16-
# ############################################################################
17-
# # Cache management - commented out for now because of a bug with Laravel caching & API Rate limiting
18-
# ############################################################################
19-
# echo "♻️ Refreshing cache..."
20-
# # Clear cache
21-
# su - webuser -c "php $WEBUSER_HOME/artisan cache:clear"
22-
23-
# # Set cache
24-
# su - webuser -c "php $WEBUSER_HOME/artisan route:cache"
25-
# su - webuser -c "php $WEBUSER_HOME/artisan view:cache"
14+
if [ "$APP_ENV_SETTING" != "local" ] && [ ! -z $APP_ENV_SETTING ] && [ ${CI_ENV:="false"} != "true" ]; then
15+
echo "🏃‍♂️ Checking for Laravel automations..."
2616

2717
############################################################################
2818
# Automated database migrations
2919
############################################################################
30-
if grep -q DB_DATABASE $WEBUSER_HOME/.env; then
20+
if [ "grep -q DB_DATABASE $WEBUSER_HOME/.env" ] && [ ${AUTORUN_LARAVEL_MIGRATION:="false"} == "true" ]; then
3121
echo "🚀 Running migrations..."
3222
su - webuser -c "php $WEBUSER_HOME/artisan migrate --force"
3323
fi
3424

3525
############################################################################
3626
# Automated storage linking
3727
############################################################################
38-
echo "🔐 Linking the storage..."
39-
su - webuser -c "php $WEBUSER_HOME/artisan storage:link"
28+
if [ ${AUTORUN_LARAVEL_STORAGE_LINK:="true"} == "true" ]; then
29+
echo "🔐 Linking the storage..."
30+
su - webuser -c "php $WEBUSER_HOME/artisan storage:link"
31+
fi
32+
33+
############################################################################
34+
# Cache management - commented out for now because of a bug with Laravel caching & API Rate limiting
35+
############################################################################
36+
# if [ ${AUTORUN_LARAVEL_REFRESH_CACHE:="true"} == "true" ]; then
37+
# echo "♻️ Refreshing cache..."
38+
# # Clear cache
39+
# su - webuser -c "php $WEBUSER_HOME/artisan cache:clear"
40+
41+
# # Set cache
42+
# su - webuser -c "php $WEBUSER_HOME/artisan route:cache"
43+
# su - webuser -c "php $WEBUSER_HOME/artisan view:cache"
44+
# fi
45+
4046
else
41-
echo "👉 Skipping Laravel production commands because the env is set to 'local', running in CI, or explicitly disabled..."
47+
echo "👉 Skipping Laravel automations because the env is set to 'local' or running in CI..."
4248
fi
4349
fi

generated-dockerfiles/8.1/fpm/etc/cont-init.d/50-laravel-automations

+22-16
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,39 @@ if [ -f $WEBUSER_HOME/artisan ]; then
1111
APP_ENV_SETTING=$(cat $WEBUSER_HOME/.env | grep APP_ENV | cut -f2 -d"=")
1212

1313
# If Laravel is not running in development or CI, then automate some production tasks
14-
if [ "$APP_ENV_SETTING" != "local" ] && [ ! -z $APP_ENV_SETTING ] && [ ${CI_ENV:="false"} != "true" ] && [ ${RUN_LARAVEL_AUTOMATIONS:="true"} == "true" ]; then
15-
16-
# ############################################################################
17-
# # Cache management - commented out for now because of a bug with Laravel caching & API Rate limiting
18-
# ############################################################################
19-
# echo "♻️ Refreshing cache..."
20-
# # Clear cache
21-
# su - webuser -c "php $WEBUSER_HOME/artisan cache:clear"
22-
23-
# # Set cache
24-
# su - webuser -c "php $WEBUSER_HOME/artisan route:cache"
25-
# su - webuser -c "php $WEBUSER_HOME/artisan view:cache"
14+
if [ "$APP_ENV_SETTING" != "local" ] && [ ! -z $APP_ENV_SETTING ] && [ ${CI_ENV:="false"} != "true" ]; then
15+
echo "🏃‍♂️ Checking for Laravel automations..."
2616

2717
############################################################################
2818
# Automated database migrations
2919
############################################################################
30-
if grep -q DB_DATABASE $WEBUSER_HOME/.env; then
20+
if [ "grep -q DB_DATABASE $WEBUSER_HOME/.env" ] && [ ${AUTORUN_LARAVEL_MIGRATION:="false"} == "true" ]; then
3121
echo "🚀 Running migrations..."
3222
su - webuser -c "php $WEBUSER_HOME/artisan migrate --force"
3323
fi
3424

3525
############################################################################
3626
# Automated storage linking
3727
############################################################################
38-
echo "🔐 Linking the storage..."
39-
su - webuser -c "php $WEBUSER_HOME/artisan storage:link"
28+
if [ ${AUTORUN_LARAVEL_STORAGE_LINK:="true"} == "true" ]; then
29+
echo "🔐 Linking the storage..."
30+
su - webuser -c "php $WEBUSER_HOME/artisan storage:link"
31+
fi
32+
33+
############################################################################
34+
# Cache management - commented out for now because of a bug with Laravel caching & API Rate limiting
35+
############################################################################
36+
# if [ ${AUTORUN_LARAVEL_REFRESH_CACHE:="true"} == "true" ]; then
37+
# echo "♻️ Refreshing cache..."
38+
# # Clear cache
39+
# su - webuser -c "php $WEBUSER_HOME/artisan cache:clear"
40+
41+
# # Set cache
42+
# su - webuser -c "php $WEBUSER_HOME/artisan route:cache"
43+
# su - webuser -c "php $WEBUSER_HOME/artisan view:cache"
44+
# fi
45+
4046
else
41-
echo "👉 Skipping Laravel production commands because the env is set to 'local', running in CI, or explicitly disabled..."
47+
echo "👉 Skipping Laravel automations because the env is set to 'local' or running in CI..."
4248
fi
4349
fi

templates/fpm/etc/cont-init.d/50-laravel-automations

+22-16
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,39 @@ if [ -f $WEBUSER_HOME/artisan ]; then
1111
APP_ENV_SETTING=$(cat $WEBUSER_HOME/.env | grep APP_ENV | cut -f2 -d"=")
1212

1313
# If Laravel is not running in development or CI, then automate some production tasks
14-
if [ "$APP_ENV_SETTING" != "local" ] && [ ! -z $APP_ENV_SETTING ] && [ ${CI_ENV:="false"} != "true" ] && [ ${RUN_LARAVEL_AUTOMATIONS:="true"} == "true" ]; then
15-
16-
# ############################################################################
17-
# # Cache management - commented out for now because of a bug with Laravel caching & API Rate limiting
18-
# ############################################################################
19-
# echo "♻️ Refreshing cache..."
20-
# # Clear cache
21-
# su - webuser -c "php $WEBUSER_HOME/artisan cache:clear"
22-
23-
# # Set cache
24-
# su - webuser -c "php $WEBUSER_HOME/artisan route:cache"
25-
# su - webuser -c "php $WEBUSER_HOME/artisan view:cache"
14+
if [ "$APP_ENV_SETTING" != "local" ] && [ ! -z $APP_ENV_SETTING ] && [ ${CI_ENV:="false"} != "true" ]; then
15+
echo "🏃‍♂️ Checking for Laravel automations..."
2616

2717
############################################################################
2818
# Automated database migrations
2919
############################################################################
30-
if grep -q DB_DATABASE $WEBUSER_HOME/.env; then
20+
if [ "grep -q DB_DATABASE $WEBUSER_HOME/.env" ] && [ ${AUTORUN_LARAVEL_MIGRATION:="false"} == "true" ]; then
3121
echo "🚀 Running migrations..."
3222
su - webuser -c "php $WEBUSER_HOME/artisan migrate --force"
3323
fi
3424

3525
############################################################################
3626
# Automated storage linking
3727
############################################################################
38-
echo "🔐 Linking the storage..."
39-
su - webuser -c "php $WEBUSER_HOME/artisan storage:link"
28+
if [ ${AUTORUN_LARAVEL_STORAGE_LINK:="true"} == "true" ]; then
29+
echo "🔐 Linking the storage..."
30+
su - webuser -c "php $WEBUSER_HOME/artisan storage:link"
31+
fi
32+
33+
############################################################################
34+
# Cache management - commented out for now because of a bug with Laravel caching & API Rate limiting
35+
############################################################################
36+
# if [ ${AUTORUN_LARAVEL_REFRESH_CACHE:="true"} == "true" ]; then
37+
# echo "♻️ Refreshing cache..."
38+
# # Clear cache
39+
# su - webuser -c "php $WEBUSER_HOME/artisan cache:clear"
40+
41+
# # Set cache
42+
# su - webuser -c "php $WEBUSER_HOME/artisan route:cache"
43+
# su - webuser -c "php $WEBUSER_HOME/artisan view:cache"
44+
# fi
45+
4046
else
41-
echo "👉 Skipping Laravel production commands because the env is set to 'local', running in CI, or explicitly disabled..."
47+
echo "👉 Skipping Laravel automations because the env is set to 'local' or running in CI..."
4248
fi
4349
fi

0 commit comments

Comments
 (0)