forked from invoiceninja/dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·100 lines (89 loc) · 3.87 KB
/
Copy pathentrypoint.sh
File metadata and controls
executable file
·100 lines (89 loc) · 3.87 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
#!/bin/bash -eu
# --- ROLE: aio (Runs as root) ---
if [ "${LARAVEL_ROLE}" = 'aio' ]; then
# Clear and cache config in production
if [ "$*" = 'supervisord -c /etc/supervisor/supervisord.conf' ]; then
if [ "$APP_ENV" = "production" ]; then
echo "Running production setup..."
runuser -u ninja -- php artisan migrate --force
runuser -u ninja -- php artisan cache:clear
runuser -u ninja -- php artisan ninja:design-update
runuser -u ninja -- php artisan optimize
# Check if initialization is needed
if [ "$(runuser -u ninja -- php artisan tinker --execute='echo Schema::hasTable("accounts") && !App\Models\Account::all()->first();')" = "1" ]; then
echo "Running initialization..."
runuser -u ninja -- php artisan db:seed --force
if [ -n "${IN_USER_EMAIL}" ] && [ -n "${IN_PASSWORD}" ]; then
runuser -u ninja -- php artisan ninja:create-account --email "${IN_USER_EMAIL}" --password "${IN_PASSWORD}"
else
echo "Initialization failed - Set IN_USER_EMAIL and IN_PASSWORD in .env"
exit 1
fi
fi
fi
fi
echo "Handing off to supervisord..."
# Fall through to exec "$@" at the bottom
# --- ROLES: app, worker, scheduler (Run as ninja) ---
else
if [ "--help" = "$1" ]; then
echo [FLAGS]
echo The CMD defined can be extended with flags for artisan commands
echo
echo Available flags can be queried:
echo docker run --rm benbrummer/invoiceninja:5-app php artisan help octane:frankenphp
echo docker run --rm benbrummer/invoiceninja:5-worker php artisan help queue:work
echo docker run --rm benbrummer/invoiceninja:5-scheduler php artisan help schedule:work
echo
echo Example:
echo docker run benbrummer/invoiceninja:5-worker --verbose --sleep=3 --tries=3 --max-time=3600
echo
echo [Deployment]
echo Compose is recommended
echo
echo Example compose files:
echo https://github.com/benbrummer/dockerfiles/tree/main/compose
echo
exit 0
fi
case "${LARAVEL_ROLE}" in
app)
# Check if we should prepend the octane command
if [ $# -eq 0 ] || [[ "$1" == -* ]] || [ "$*" = "php artisan octane:frankenphp" ]; then
if [ "$APP_ENV" = "production" ]; then
echo "Running production setup..."
php artisan migrate --force
php artisan cache:clear
php artisan ninja:design-update
php artisan optimize
if [ "$(php artisan tinker --execute='echo Schema::hasTable("accounts") && !App\Models\Account::all()->first();')" = "1" ]; then
echo "Running initialization..."
php artisan db:seed --force
if [ -n "${IN_USER_EMAIL:-}" ] && [ -n "${IN_PASSWORD:-}" ]; then
php artisan ninja:create-account --email "${IN_USER_EMAIL}" --password "${IN_PASSWORD}"
fi
fi
fi
# CRITICAL FIX: Prepend the base command if only flags were passed
if [ $# -eq 0 ] || [[ "$1" == -* ]]; then
set -- php artisan octane:frankenphp "$@"
fi
fi
;;
scheduler)
[ "$APP_ENV" = "production" ] && php artisan optimize
echo "Starting scheduler ..."
if [ $# -eq 0 ] || [[ "$1" == -* ]]; then
set -- php artisan queue:work --no-interaction "$@"
fi
;;
worker)
[ "$APP_ENV" = "production" ] && php artisan optimize
echo "Starting worker..."
if [ $# -eq 0 ] || [[ "$1" == -* ]]; then
set -- php artisan queue:work --no-interaction "$@"
fi
;;
esac
fi
exec "$@"