Files
investbrain/docker/entrypoint.sh
T

50 lines
1.5 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 21:53:55 -06:00
echo -e "\n====================== Running entrypoint script... ====================== "
2024-09-04 17:48:40 -05:00
2025-01-25 21:53:55 -06:00
if [ ! -f ".env" ]; then
echo " > Ope, gotta create an .env file!"
2025-01-25 21:43:58 -06:00
2025-01-25 21:53:55 -06:00
[ -d ".env" ] && rm -rf .env
2025-01-25 18:35:18 -06:00
2024-09-05 21:34:09 -05:00
cp .env.example .env
2024-09-04 17:48:40 -05:00
fi
2025-01-25 21:53:55 -06:00
echo -e "\n====================== Validating environment... ====================== "
if [ $(stat -c "%U" .) != "www-data" ]; then
echo " > Setting correct permissions for application..."
2025-01-25 21:34:18 -06:00
chown -R www-data:www-data .
fi
2025-01-25 21:53:55 -06:00
if ( ! grep -q "^APP_KEY=" ".env" || grep -q "^APP_KEY=$" ".env"); then
echo " > Ah, APP_KEY is missing in .env file. Generating a new key!"
2024-09-05 21:49:06 -05:00
2025-01-25 21:53:55 -06:00
su - www-data -c "/usr/local/bin/php artisan key:generate --force"
2024-09-05 21:49:06 -05:00
fi
2025-01-25 21:53:55 -06:00
if [ ! -L "public/storage" ]; then
echo " > Creating symbolic link for app public storage..."
2024-09-09 17:21:08 -05:00
2025-01-25 21:53:55 -06:00
su - www-data -c "/usr/local/bin/php 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-25 21:53:55 -06:00
su - www-data -c "/usr/local/bin/php artisan migrate --force"
2024-12-16 21:54:59 -06:00
}
RETRIES=30
DELAY=5
until run_migrations; do
RETRIES=$((RETRIES-1))
if [ $RETRIES -le 0 ]; then
2025-01-25 21:53:55 -06:00
echo " > Database is not ready after multiple attempts. Exiting..."
2024-12-16 21:54:59 -06:00
exit 1
fi
2025-01-25 21:53:55 -06:00
echo " > Waiting for database to be ready... retrying in $DELAY seconds."
2024-12-16 21:54:59 -06:00
sleep $DELAY
done
2024-09-04 17:48:40 -05:00
2025-01-25 21:53:55 -06:00
echo -e "\n====================== Spinning up Supervisor daemon... ====================== "
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf