-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
104 lines (83 loc) · 2.59 KB
/
entrypoint.sh
File metadata and controls
104 lines (83 loc) · 2.59 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
#!/bin/bash
create_superuser="
import django
django.setup()
from django.contrib.auth.models import User
try:
User.objects.create_superuser('$DJANGO_SUPERUSER_NAME', '$DJANGO_SUPERUSER_MAIL', '$DJANGO_SUPERUSER_PASS')
except Exception:
pass
"
create_superuser() {
if [ -z "$DJANGO_SUPERUSER_NAME" ] || [ -z "$DJANGO_SUPERUSER_MAIL" ] || [ -z "$DJANGO_SUPERUSER_PASS" ]; then
echo "Environment variables for database not set, not creating superuser."
else
echo "Creating superuser"
python -c "$create_superuser"
fi
}
wait_for_db() {
if [ -z "$DJANGO_DB_HOST" ] || [ -z "$DJANGO_DB_PORT" ]; then
echo "No django database host or port, not waiting for db."
else
echo "Waiting for database"
dockerize -wait tcp://"$DJANGO_DB_HOST":"$DJANGO_DB_PORT" -timeout 30s
fi
}
if [ "$1" == "runserver" ]; then
# No reason to wait for a DB
# wait_for_db
echo "Running migrations"
# Apply database migrations
python manage.py migrate
# Collect static files
echo "Running collectstatic"
python manage.py collectstatic --noinput
# echo "Start crons"
# Run the command on container startup
#create_superuser
#exec python manage.py "$@"
#exec "$@"
newrelic-admin run-program gunicorn --bind 0.0.0.0:8000 --access-logfile - halalivery.wsgi:application
fi
if [ "$1" == "resetdb" ]; then
# No reason to wait for a DB
# wait_for_db
#python manage.py reset_db --router=default --noinput
python manage.py reset_db --noinput
echo "Running migrations"
# Apply database migrations
python manage.py migrate
# Collect static files
echo "Running collectstatic"
python manage.py collectstatic --noinput
newrelic-admin run-program gunicorn --bind 0.0.0.0:8000 --access-logfile - halalivery.wsgi:application
fi
if [ "$1" == "nomigrate" ]; then
wait_for_db
echo "Running collectstatic"
python manage.py collectstatic --noinput
create_superuser
exec python manage.py runserver "${@:2}"
fi
if [ "$1" == "migrate" ]; then
wait_for_db
echo "Running migrations"
# Apply database migrations
python manage.py "$@"
fi
if [ "$1" == "makemigrations" ];then
wait_for_db
exec python manage.py "$@"
fi
if [ "$1" == "loadtestdata" ];then
wait_for_db
exec python manage.py "$@"
fi
if [ "$1" == "celery" ];then
celery -A halalivery worker --app=halalivery.celeryconf:app --loglevel=info
fi
if [ "$1" == "celerybeat" ];then
celery -A halalivery beat --loglevel=info --scheduler django_celery_beat.schedulers:DatabaseScheduler --quiet
fi
exec "$@"