88: " ${CONTAINER_WORKER_SLEEP:= 5} "
99: " ${CONTAINER_WORKER_TIMEOUT:= 300} "
1010: " ${CONTAINER_WORKER_TRIES:= 3} "
11- : " ${CONTAINER_SCHEDULER_INTERVAL:= 60} "
1211: " ${APP_ENV:= production} "
1312
14- ARTISAN=" php -d variables_order=EGPCS /app/artisan"
13+ ARTISAN=" php -d variables_order=EGPCS /laravel/artisan"
14+
15+ _migrate () {
16+ local count=0
17+ local timeout=20
18+
19+ while [ $count -lt " ${timeout} " ]; do
20+ php -f /common/test_db_connection.php > /dev/null 2>&1
21+
22+ status=$?
23+
24+ if [ $status -eq 0 ]; then
25+ echo " ✅ Database connection successful."
26+ break
27+ fi
28+
29+ echo " ⏱ Waiting on database connection, retrying... $(( timeout - count)) seconds left"
30+ count=$(( count + 1 ))
31+ sleep 1
32+ done
33+
34+ if [ $count -eq " ${timeout} " ]; then
35+ echo " ⛔ Database connection failed after multiple attempts."
36+ exit 1
37+ fi
38+
39+ echo " 🚀 Running migrations..."
40+ ${ARTISAN} migrate --force --isolated
41+ }
1542
1643_setup () {
1744 if [ -n " ${CONTAINER_MANUAL_SETUP} " ]; then
18- echo DEBUG : Skipping setup...
45+ echo " ⏭ : Skipping setup..."
1946
2047 return
2148 fi
2249
23- echo DEBUG: Preparing application...
50+ _migrate
2451
25- ${ARTISAN} storage:link || true
26-
27- ${ARTISAN} optimize || true
28- ${ARTISAN} config:cache || true
29- ${ARTISAN} route:cache || true
30- ${ARTISAN} view:cache || true
31- ${ARTISAN} events:cache || true
52+ if [ -d " /laravel/app/public/storage" ]; then
53+ echo " ✅ Storage already linked..."
54+ else
55+ echo " 🔐 Linking the storage..."
56+ ${ARTISAN} storage:link
57+ fi
3258
33- ${ARTISAN} migrate --force || true
59+ ${ARTISAN} config:cache
60+ ${ARTISAN} events:cache
61+ ${ARTISAN} route:cache
62+ ${ARTISAN} view:cache
3463}
3564
3665_run () {
3766 case " ${CONTAINER_MODE} " in
3867 app)
39- echo INFO: Running octane...
68+ echo " 🚀 Running octane..."
4069 exec " ${ARTISAN} " octane:frankenphp --host=0.0.0.0 --port=" ${CONTAINER_PORT} "
4170 ;;
4271 worker)
43- echo INFO: Running the queue...
72+ echo " ⏳ Running the queue..."
4473 exec " ${ARTISAN} " queue:work -vv \
4574 --no-interaction \
4675 --tries=" ${CONTAINER_WORKER_TRIES} " \
@@ -49,18 +78,15 @@ _run() {
4978 --delay=" ${CONTAINER_WORKER_DELAY} "
5079 ;;
5180 horizon)
52- echo INFO: Running horizon...
81+ echo " Running horizon..."
5382 exec " ${ARTISAN} " horizon
5483 ;;
5584 scheduler)
56- while true ; do
57- echo " INFO: Running scheduled tasks."
58- " ${ARTISAN} " schedule:run --verbose --no-interaction &
59- sleep " ${CONTAINER_SCHEDULER_INTERVAL} s"
60- done
85+ echo " 📆 Running scheduled tasks..."
86+ exec " ${ARTISAN} " schedule:work --verbose --no-interaction
6187 ;;
6288 * )
63- echo " Could not match the container mode [${CONTAINER_MODE} ]"
89+ echo " ⛔ Could not match the container mode [${CONTAINER_MODE} ]"
6490 exit 1
6591 ;;
6692 esac
0 commit comments