|
8 | 8 | : "${CONTAINER_WORKER_SLEEP:=5}"
|
9 | 9 | : "${CONTAINER_WORKER_TIMEOUT:=300}"
|
10 | 10 | : "${CONTAINER_WORKER_TRIES:=3}"
|
| 11 | + |
| 12 | +: "${TEST_DB_CONNECTION:=true}" |
| 13 | +: "${TEST_CACHE_CONNECTION:=true}" |
| 14 | +: "${TEST_CONNECTION_TIMEOUT:=20}" |
| 15 | + |
11 | 16 | : "${APP_ENV:=production}"
|
| 17 | +: "${APP_DEBUG:=false}" |
12 | 18 |
|
13 | 19 | ARTISAN="php -d variables_order=EGPCS /laravel/artisan"
|
14 | 20 |
|
15 |
| -_migrate() { |
| 21 | +_test_connection() { |
16 | 22 | 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 |
| 23 | + local type="${1}" |
21 | 24 |
|
| 25 | + while [ "$count" -lt "$TEST_CONNECTION_TIMEOUT" ]; do |
| 26 | + php -f "/common/test_${type}_connection.php" > /dev/null 2>&1 |
22 | 27 | status=$?
|
23 | 28 |
|
24 | 29 | if [ "$status" -eq 0 ]; then
|
25 |
| - echo "✅ Database connection successful." |
26 |
| - break |
| 30 | + echo "✅ ${type^} connection successful." |
| 31 | + return 0 |
27 | 32 | fi
|
28 | 33 |
|
29 |
| - echo "⏱ Waiting on database connection, retrying... $((timeout - count)) seconds left" |
| 34 | + echo "⏱ Waiting on $type connection, retrying... $((TEST_CONNECTION_TIMEOUT - count)) seconds left" |
30 | 35 | count=$((count + 1))
|
31 | 36 | sleep 1
|
32 | 37 | done
|
33 | 38 |
|
34 |
| - if [ "$count" -eq "$timeout" ]; then |
35 |
| - echo "⛔ Database connection failed after multiple attempts." |
36 |
| - exit 1 |
| 39 | + echo "⛔ ${type^} connection failed after multiple attempts." |
| 40 | + exit 1 |
| 41 | +} |
| 42 | + |
| 43 | +_test_connections() { |
| 44 | + if [ "$TEST_DB_CONNECTION" != "true" ]; then |
| 45 | + echo "⏭ Skipping database connection test..." |
| 46 | + else |
| 47 | + _test_connection "db" |
37 | 48 | fi
|
38 | 49 |
|
| 50 | + if [ "$TEST_CACHE_CONNECTION" != "true" ]; then |
| 51 | + echo "⏭ Skipping cache connection test..." |
| 52 | + else |
| 53 | + _test_connection "cache" |
| 54 | + fi |
| 55 | +} |
| 56 | + |
| 57 | +_migrate() { |
39 | 58 | echo "🚀 Running migrations..."
|
40 | 59 | ${ARTISAN} migrate --force --isolated
|
41 | 60 | }
|
42 | 61 |
|
43 | 62 | _setup() {
|
44 | 63 | if [ -n "$CONTAINER_MANUAL_SETUP" ]; then
|
45 | 64 | echo "⏭: Skipping setup..."
|
46 |
| - |
47 | 65 | return
|
48 | 66 | fi
|
49 | 67 |
|
| 68 | + _test_connections |
50 | 69 | _migrate
|
51 | 70 |
|
52 | 71 | if [ -d "/laravel/app/public/storage" ]; then
|
|
0 commit comments