-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdocker-entrypoint.sh
145 lines (114 loc) · 4.04 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# wait for a given host:port to become available
#
# $1 host
# $2 port
function dockerwait {
while ! exec 6<>/dev/tcp/$1/$2; do
echo "$(date) - waiting to connect $1 $2"
sleep 5
done
echo "$(date) - connected to $1 $2"
exec 6>&-
exec 6<&-
}
# wait for services to become available
# this prevents race conditions using docker-compose
function wait_for_services {
if [[ "$WAIT_FOR_DB" ]] ; then
dockerwait $DBSERVER $DBPORT
fi
if [[ "$WAIT_FOR_CACHE" ]] ; then
dockerwait $CACHESERVER $CACHEPORT
fi
if [[ "$WAIT_FOR_WEB" ]] ; then
dockerwait $WEBSERVER $WEBPORT
fi
}
function defaults {
: ${DBSERVER:="db"}
: ${DBPORT:="5432"}
: ${WEBSERVER="web"}
: ${WEBPORT="8000"}
: ${CACHESERVER="cache"}
: ${CACHEPORT="11211"}
: ${DBUSER="webapp"}
: ${DBNAME="${DBUSER}"}
: ${DBPASS="${DBUSER}"}
export DBSERVER DBPORT DBUSER DBNAME DBPASS
}
function django_defaults {
: ${DEPLOYMENT="dev"}
: ${PRODUCTION=0}
: ${DEBUG=1}
: ${MEMCACHE="${CACHESERVER}:${CACHEPORT}"}
: ${WRITABLE_DIRECTORY="/data/scratch"}
: ${STATIC_ROOT="/data/static"}
: ${MEDIA_ROOT="/data/static/media"}
: ${LOG_DIRECTORY="/data/log"}
: ${DJANGO_SETTINGS_MODULE="django.settings"}
echo "DEPLOYMENT is ${DEPLOYMENT}"
echo "PRODUCTION is ${PRODUCTION}"
echo "DEBUG is ${DEBUG}"
echo "MEMCACHE is ${MEMCACHE}"
echo "WRITABLE_DIRECTORY is ${WRITABLE_DIRECTORY}"
echo "STATIC_ROOT is ${STATIC_ROOT}"
echo "MEDIA_ROOT is ${MEDIA_ROOT}"
echo "LOG_DIRECTORY is ${LOG_DIRECTORY}"
echo "DJANGO_SETTINGS_MODULE is ${DJANGO_SETTINGS_MODULE}"
export DEPLOYMENT PRODUCTION DEBUG DBSERVER MEMCACHE WRITABLE_DIRECTORY STATIC_ROOT MEDIA_ROOT LOG_DIRECTORY DJANGO_SETTINGS_MODULE
}
echo "HOME is ${HOME}"
echo "WHOAMI is `whoami`"
defaults
django_defaults
wait_for_services
# uwsgi entrypoint
if [ "$1" = 'uwsgi' ]; then
echo "[Run] Starting uwsgi"
: ${UWSGI_OPTS="/app/uwsgi/docker.ini"}
echo "UWSGI_OPTS is ${UWSGI_OPTS}"
django-admin.py collectstatic --noinput --settings=${DJANGO_SETTINGS_MODULE} 2>&1 | tee /data/uwsgi-collectstatic.log
django-admin.py syncdb --noinput --settings=${DJANGO_SETTINGS_MODULE} 2>&1 | tee /data/uwsgi-syncdb.log
django-admin.py migrate --noinput --settings=${DJANGO_SETTINGS_MODULE} 2>&1 | tee /data/uwsgi-migrate.log
uwsgi ${UWSGI_OPTS} 2>&1 | tee /data/uwsgi.log
exit $?
fi
# runserver entrypoint
if [ "$1" = 'runserver' ]; then
echo "[Run] Starting runserver"
: ${RUNSERVER_OPTS="runserver_plus 0.0.0.0:${WEBPORT} --settings=${DJANGO_SETTINGS_MODULE}"}
echo "RUNSERVER_OPTS is ${RUNSERVER_OPTS}"
django-admin.py syncdb --noinput --settings=${DJANGO_SETTINGS_MODULE} 2>&1 | tee /data/runserver-syncdb.log
django-admin.py migrate --noinput --settings=${DJANGO_SETTINGS_MODULE} 2>&1 | tee /data/runserver-migrate.log
django-admin.py collectstatic --noinput --settings=${DJANGO_SETTINGS_MODULE} 2>&1 | tee /data/runserver-collectstatic.log
django-admin.py ${RUNSERVER_OPTS} 2>&1 | tee /data/runserver.log
exit $?
fi
# runtests entrypoint
if [ "$1" = 'runtests' ]; then
echo "[Run] Starting tests"
: ${TEST_CASES="/app/mastrms/mastrms"}
django-admin.py test ${TEST_CASES} 2>&1 | tee /data/runtests.log
exit $?
fi
# lettuce entrypoint
if [ "$1" = 'lettuce' ]; then
echo "[Run] Starting lettuce"
# Hack to make sure the selenium stack is running before we hit it
sleep 10
django-admin.py run_lettuce --with-xunit --xunit-file=/data/tests.xml 2>&1 | tee /data/lettuce.log
exit $?
fi
# selenium entrypoint
if [ "$1" = 'selenium' ]; then
echo "[Run] Starting selenium"
# Hack to make sure the selenium stack is running before we hit it
sleep 10
: ${TEST_CASES="/app/mastrms/mastrms"}
django-admin.py test ${TEST_CASES} --pattern=selenium_*.py 2>&1 | tee /data/selenium.log
exit $?
fi
echo "[RUN]: Builtin command not provided [lettuce|selenium|runtests|runserver|uwsgi]"
echo "[RUN]: $@"
exec "$@"