forked from elnappo/project-novis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·73 lines (69 loc) · 2.33 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
# Based on https://github.com/lukin0110/docker-django-boilerplate/blob/master/deployment/docker-entrypoint.sh
set -o errexit # abort script at first error
set -o pipefail # return the exit status of the last command in the pipe
[[ -z "$DATABASE_URL" ]] && echo "ERROR: DATABASE_URL must be set!" && exit 1;
# Define help message
show_help() {
echo """
Usage: docker run <imagename> COMMAND
Commands
bash : Start a bash shell
python : Start a Python shell
shell : Start a Django Python shell
test : Run tests
migrate : Run database migrations
createsuperuser : Create Django superuser
manage : Run manage.py task
dev : Start a normal Django development server
gunicorn : Run Gunicorn server
help : Show this message
"""
}
# Run
case "$1" in
bash)
exec /bin/bash "${@:2}"
;;
python)
exec python "${@:2}"
;;
shell)
exec python manage.py shell
;;
test)
export COVERAGE_FILE=/tmp/.coverage
exec pytest -p no:cacheprovider --junitxml=/tmp/report.xml
;;
migrate)
echo "Apply database migrations"
exec python manage.py migrate --noinput
;;
createsuperuser)
[[ -z "$DJANGO_SUPERUSER_EMAIL" ]] && echo "ERROR: Need to set DJANGO_SUPERUSER_EMAIL" && exit 1;
[[ -z "$DJANGO_SUPERUSER_PASSWORD" ]] && echo "ERROR: Need to set DJANGO_SUPERUSER_PASSWORD" && exit 1;
echo "Create Django superuser ${DJANGO_SUPERUSER_EMAIL}"
exec python manage.py shell -c "from django.contrib.auth import get_user_model; get_user_model().objects.create_superuser(\"$DJANGO_SUPERUSER_EMAIL\", \"$DJANGO_SUPERUSER_PASSWORD\")"
;;
manage)
echo "Running Django management command ${@:2}"
exec python manage.py "${@:2}"
;;
dev)
echo "Starting Django development server on 0.0.0.0:8000"
exec python manage.py runserver 0.0.0.0:8000
;;
gunicorn)
echo "Starting Django application via Gunicorn"
# Disable access log?
exec gunicorn -b :8000 --worker-class gevent --worker-connections 20 --timeout 10 --graceful-timeout 30 --access-logfile - project_novis.wsgi
;;
help)
show_help
;;
*)
echo "Unknown command ${@:1}"
show_help
exit 1
;;
esac