-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
116 lines (99 loc) · 2.72 KB
/
entrypoint.sh
File metadata and controls
116 lines (99 loc) · 2.72 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
set -e
: "${CONTAINER_MODE:=app}"
: "${CONTAINER_PORT:=8000}"
: "${CONTAINER_WORKER_DELAY:=10}"
: "${CONTAINER_WORKER_SLEEP:=5}"
: "${CONTAINER_WORKER_TIMEOUT:=300}"
: "${CONTAINER_WORKER_TRIES:=3}"
: "${CONTAINER_SCHEDULER_INTERVAL:=60}"
: "${APP_ENV:=production}"
ARTISAN="php -d variables_order=EGPCS artisan"
_migrate() {
local count=0
local timeout=20
while [ $count -lt "${timeout}" ]; do
php -f common/test_db_connection.php
status=$?
if [ $status -eq 0 ]; then
echo "✅ Database connection successful."
break
fi
echo "⏱ Waiting on database connection, retrying... $((timeout - count)) seconds left"
count=$((count + 1))
sleep 1
done
if [ $count -eq "${timeout}" ]; then
echo "⛔ Database connection failed after multiple attempts."
exit 1
fi
echo "🚀 Running migrations..."
${ARTISAN} migrate --force
}
_setup() {
if [ -n "${CONTAINER_MANUAL_SETUP}" ]; then
echo "⏭: Skipping setup..."
return
fi
_migrate
if [ -d "/laravel/app/public/storage" ]; then
echo "✅ Storage already linked..."
else
echo "🔐 Linking the storage..."
${ARTISAN} storage:link
fi
${ARTISAN} key:generate
${ARTISAN} cache:clear
${ARTISAN} config:cache
${ARTISAN} event:cache
${ARTISAN} route:cache
${ARTISAN} view:cache
npm run build
}
_run() {
case "${CONTAINER_MODE}" in
app)
echo "🚀 Running octane..."
# ${ARTISAN} schedule:work &
# ${ARTISAN} octane:frankenphp --host=0.0.0.0 --port="${CONTAINER_PORT}" &
# ${ARTISAN} queue:
${ARTISAN} queue:work -vv \
--no-interaction \
--tries="${CONTAINER_WORKER_TRIES}" \
--sleep="${CONTAINER_WORKER_SLEEP}" \
--timeout="${CONTAINER_WORKER_TIMEOUT}" \
--delay="${CONTAINER_WORKER_DELAY}" &
${ARTISAN} schedule:work &
${ARTISAN} octane:frankenphp --host=0.0.0.0 --port="${CONTAINER_PORT}"
;;
# ${ARTISAN} serve --host=0.0.0.0 --port="${CONTAINER_PORT}"
# ;;
worker)
echo "⏳ Running the queue..."
exec "${ARTISAN}" queue:work
-vv \
--no-interaction \
--tries="${CONTAINER_WORKER_TRIES}" \
--sleep="${CONTAINER_WORKER_SLEEP}" \
--timeout="${CONTAINER_WORKER_TIMEOUT}" \
--delay="${CONTAINER_WORKER_DELAY}"
;;
horizon)
echo "Running horizon..."
exec "${ARTISAN}" horizon
;;
scheduler)
while true; do
echo "📆 Running scheduled tasks."
"${ARTISAN}" schedule:run --verbose --no-interaction &
sleep "${CONTAINER_SCHEDULER_INTERVAL}s"
done
;;
*)
echo "⛔ Could not match the container mode [${CONTAINER_MODE}]"
exit 1
;;
esac
}
_setup
_run