-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathentrypoint
74 lines (59 loc) · 1.63 KB
/
entrypoint
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
#!/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
wait_for_db
echo "Running migrations"
# Apply database migrations
python manage.py migrate
# Collect static files
echo "Running collectstatic"
python manage.py collectstatic --noinput
create_superuser
exec python manage.py "$@"
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
exec "$@"