-
Notifications
You must be signed in to change notification settings - Fork 11
/
entrypoint.sh
executable file
·126 lines (111 loc) · 2.13 KB
/
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
#!/bin/bash
set -e
set -o nounset
postgres_ready() {
python << END
import sys
from psycopg2 import connect
from psycopg2.errors import OperationalError
try:
connect(
dbname="${POSTGRES_DB}",
user="${POSTGRES_USER}",
password="${POSTGRES_PASSWORD}",
)
except OperationalError:
sys.exit(-1)
END
}
redis_ready() {
python << END
import sys
from redis import Redis
from redis import RedisError
try:
redis = Redis.from_url("${CELERY_BROKER_URL}", db=0)
redis.ping()
except RedisError:
sys.exit(-1)
END
}
wait_other_containers() {
until postgres_ready; do
>&2 echo "Waiting for PostgreSQL to become available..."
sleep 5
done
>&2 echo "PostgreSQL is available"
until redis_ready; do
>&2 echo "Waiting for Redis to become available..."
sleep 5
done
>&2 echo "Redis is available"
}
django_operations() {
python3 manage.py collectstatic --noinput
python3 manage.py migrate
}
cd /app
case $1 in
"bash")
bash;;
"makemigrations")
python3 manage.py makemigrations;;
"beat")
wait_other_containers ;\
django_operations ;\
celery \
--app meetupselector \
beat \
--loglevel INFO \
--scheduler django_celery_beat.schedulers:DatabaseScheduler
;;
"worker")
wait_other_containers ;\
django_operations ;\
celery \
--app meetupselector \
worker \
--loglevel INFO
;;
"server")
wait_other_containers ;\
django_operations ;\
if [ "$DJANGO_DEBUG" = "true" ]; then
gunicorn \
--reload \
--bind 0.0.0.0:8000 \
--workers 2 \
--worker-class eventlet \
--log-level DEBUG \
--access-logfile "-" \
--error-logfile "-" \
meetupselector.wsgi
else
python manage.py runserver 0.0.0.0:8000
fi
;;
"createsuperuser")
wait_other_containers ;\
django_operations ;\
python manage.py createsuperuser
;;
"shell")
wait_other_containers ;\
django_operations ;\
python manage.py shell
;;
"test")
wait_other_containers ;\
django_operations ;\
pytest
;;
"lint")
isort --check-only meetupselector tests
black --check meetupselector tests
flake8 meetupselector tests
mypy meetupselector
;;
"*")
exec "$@"
;;
esac