-
Notifications
You must be signed in to change notification settings - Fork 3
/
docker-entrypoint.sh
executable file
·50 lines (40 loc) · 1.08 KB
/
docker-entrypoint.sh
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
#!/bin/bash
# $0 is a script name, $1, $2, $3 etc are passed arguments
# $1 is our command
# Credits: https://rock-it.pl/how-to-write-excellent-dockerfiles/
CMD=$1
wait_for_db () {
# Wait until postgres is ready
until nc -z $DATABASE_HOST 5432; do
echo "$(date) - waiting for postgres... ($DATABASE_HOST:5432)"
sleep 3
done
}
setup_django () {
echo Running migrations
django-admin migrate --noinput
django-admin createsuperuser --no-input --username admin --email [email protected]
echo Create cache table
django-admin createcachetable
}
case "$CMD" in
"runserver" )
wait_for_db
setup_django
exec django-admin runserver 0.0.0.0:8080
;;
"typecheck" )
echo Running typecheck
exec mypy .
;;
"test" )
wait_for_db
echo Running tests
exec pytest --ds=pipit.settings.test
;;
* )
# Run custom command. Thanks to this line we can still use
# "docker run our_container /bin/bash" and it will work
exec $CMD ${@:2}
;;
esac