Files
investbrain/docker/entrypoint.sh
T

57 lines
1.8 KiB
Bash
Raw Normal View History

2024-09-04 17:48:40 -05:00
#!/bin/bash
2024-09-05 21:34:09 -05:00
cd /var/www/app
2025-01-25 22:54:10 -06:00
echo -e "\n====================== Validating environment... ====================== "
2025-01-25 22:33:27 -06:00
if [[ -z "$APP_KEY" ]]; then
2025-01-26 21:42:39 -06:00
echo -e "\n > Oops! The required APP_KEY configuration is missing in your environment! "
echo -e "\n > Generating a key (see below) but this will NOT be persisted between container restarts. "
2025-01-26 21:56:41 -06:00
echo -e "\n > You should set this APP_KEY in your .env file! "
2025-01-25 22:19:54 -06:00
draw_box() {
local text="$1"
local length=${#text}
local border=$(printf '%*s' "$((length + 4))" | tr ' ' '*')
2025-01-26 21:56:41 -06:00
echo -e "\n\n$border"
2025-01-25 22:19:54 -06:00
echo "* $text *"
2025-01-26 21:45:38 -06:00
echo "$border"
2025-01-25 22:19:54 -06:00
}
2025-01-26 11:36:42 -06:00
export APP_KEY=base64:$(openssl rand -base64 32)
2025-01-26 11:20:52 -06:00
draw_box $APP_KEY
2024-09-05 21:49:06 -05:00
fi
2025-01-26 11:28:20 -06:00
for dir in storage/framework/cache storage/framework/sessions storage/framework/views; do
if [ ! -d "$dir" ]; then
2025-01-26 21:56:41 -06:00
echo -e "\n > $dir is missing. Creating scaffold for storage directory... "
2025-01-26 11:28:20 -06:00
mkdir -p storage/framework/{cache,sessions,views}
chmod -R 775 storage
chown -R www-data:www-data storage
fi
done
2025-01-25 21:53:55 -06:00
if [ ! -L "public/storage" ]; then
2025-01-26 21:56:41 -06:00
echo -e "\n > Creating symbolic link for app public storage... "
2024-09-09 17:21:08 -05:00
2025-01-26 21:24:59 -06:00
/usr/local/bin/php /var/www/app/artisan storage:link
2024-09-09 17:21:08 -05:00
fi
2025-01-25 21:53:55 -06:00
echo -e "\n====================== Running migrations... ====================== "
2024-12-16 21:54:59 -06:00
run_migrations() {
2025-01-26 21:24:59 -06:00
/usr/local/bin/php /var/www/app/artisan migrate --force
2024-12-16 21:54:59 -06:00
}
2025-01-26 21:30:12 -06:00
RETRIES=10
2024-12-16 21:54:59 -06:00
DELAY=5
until run_migrations; do
2025-01-26 21:33:49 -06:00
RETRIES=$((RETRIES-1))
if [ $RETRIES -le 0 ]; then
2025-01-26 21:56:41 -06:00
echo -e "\n > Database is not ready after $RETRIES attempts. Exiting... "
2025-01-26 21:33:49 -06:00
exit 1
2024-12-16 21:54:59 -06:00
fi
2025-01-26 21:56:41 -06:00
echo -e "\n > Waiting for database to be ready... retrying in $DELAY seconds. "
2025-01-26 21:33:49 -06:00
sleep $DELAY
2024-12-16 21:54:59 -06:00
done
2024-09-04 17:48:40 -05:00
2025-01-26 21:46:59 -06:00
echo -e "\n====================== Spinning up Supervisor daemon... ====================== \n"
2025-01-25 21:53:55 -06:00
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf