/
50-laravel-automations
49 lines (41 loc) · 2.32 KB
/
50-laravel-automations
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/with-contenv bash
# Exit on error
set -e
# Check to see if an Artisan file exists and assume means Laravel is configured.
if [ -f $WEBUSER_HOME/artisan ]; then
############################################################################
# Environment detection
############################################################################
APP_ENV_SETTING=$(cat $WEBUSER_HOME/.env | grep APP_ENV | cut -f2 -d"=")
# If Laravel is not running in development or CI, then automate some production tasks
if [ "$APP_ENV_SETTING" != "local" ] && [ ! -z $APP_ENV_SETTING ] && [ ${CI_ENV:="false"} != "true" ]; then
echo "🏃♂️ Checking for Laravel automations..."
############################################################################
# Automated database migrations
############################################################################
if [ "grep -q DB_DATABASE $WEBUSER_HOME/.env" ] && [ ${AUTORUN_LARAVEL_MIGRATION:="false"} == "true" ]; then
echo "🚀 Running migrations..."
su - webuser -c "php $WEBUSER_HOME/artisan migrate --force"
fi
############################################################################
# Automated storage linking
############################################################################
if [ ${AUTORUN_LARAVEL_STORAGE_LINK:="true"} == "true" ]; then
echo "🔐 Linking the storage..."
su - webuser -c "php $WEBUSER_HOME/artisan storage:link"
fi
############################################################################
# Cache management - commented out for now because of a bug with Laravel caching & API Rate limiting
############################################################################
# if [ ${AUTORUN_LARAVEL_REFRESH_CACHE:="true"} == "true" ]; then
# echo "♻️ Refreshing cache..."
# # Clear cache
# su - webuser -c "php $WEBUSER_HOME/artisan cache:clear"
# # Set cache
# su - webuser -c "php $WEBUSER_HOME/artisan route:cache"
# su - webuser -c "php $WEBUSER_HOME/artisan view:cache"
# fi
else
echo "👉 Skipping Laravel automations because the env is set to 'local' or running in CI..."
fi
fi