-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-compose.prod.yml
227 lines (201 loc) · 6.81 KB
/
docker-compose.prod.yml
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
version: '3.8'
# useful info
# https://github.com/pplonski/simple-tasks
# https://github.com/jhnoor/docker-nginx-django-channels.git
# https://stackoverflow.com/a/45817394/19276507
# https://stackoverflow.com/a/72792416/19276507
# https://pentacent.medium.com/nginx-and-lets-encrypt-with-docker-in-less-than-5-minutes-b4b8a60d3a71
services:
nginx:
container_name: nginx
image: nginx
restart: always
command: [nginx, '-g', 'daemon off;']
# nginx не будет автоматически перезагружатся для обновления сертификата изза закомментированной команды
# закомментирована она потому что блокирует перенос тимплейта nginx в директорию конфига
# https://github.com/nginxinc/docker-nginx/issues/422#issuecomment-644299743
# command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
volumes:
- ./docker/certbot/conf:/etc/letsencrypt
- ./docker/certbot/www:/var/www/certbot
- ./docker/nginx/templates/:/etc/nginx/templates
- static_volume:/app/static
- media_volume:/app/media
environment:
SERVER_HOST: ${SERVER_HOST}
SERVER_IP: ${SERVER_IP}
SERVER_PORT: 80
WSGI_SERVER_HOST: wsgiserver
WSGI_SERVER_PORT: 8000
ASGI_SERVER_HOST: asgiserver
ASGI_SERVER_PORT: 8001
ports:
- 80:80 # HTTP
- 443:443 # HTTPS
depends_on:
- wsgiserver
- asgiserver
networks:
- front
- back
certbot:
container_name: certbot
image: certbot/certbot
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
volumes:
- ./docker/certbot/conf:/etc/letsencrypt
- ./docker/certbot/www:/var/www/certbot
depends_on:
- nginx
postgres:
container_name: postgres
image: postgres
restart: always
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ports:
- 5432:5432
networks:
- back
redis:
container_name: redis
image: redis
restart: unless-stopped
command: redis-server /usr/local/etc/redis/redis.conf
volumes:
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf
ports:
- 6379:6379
networks:
- back
# rabbitmq:
# container_name: rabbitmq
# image: rabbitmq
# restart: unless-stopped
# volumes:
# - rabbitmq_data:/var/lib/rabbitmq
# - rabbitmq_log:/var/log/rabbitmq
# environment:
# RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
# RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
# ports:
# - 5672:5672
# - 15672:15672
# networks:
# - back
wsgiserver:
container_name: wsgiserver
build:
context: ./
# для продакшена можно указать отдельный Dockerfile с расширением prod
# dockerfile: Dockerfile.prod
command: >
sh -c "echo '>>> EXECUTION wsgiserver command' &&
python manage.py collectstatic --noinput &&
python manage.py makemigrations --noinput &&
python manage.py migrate --noinput &&
gunicorn FriskesSite.wsgi:application --bind 0.0.0.0:8000 --timeout 600 --workers 1 --threads 1"
# --log-level=debug --error-logfile=/var/log/gunicorn/error.log --access-logfile=/var/log/gunicorn/access.log"
volumes:
# - /var/log/gunicorn:/var/run/gunicorn
- static_volume:/app/static
- media_volume:/app/media
env_file:
- ./.env
expose:
- 8000
depends_on:
- postgres
- redis
# - rabbitmq
networks:
- front
- back
asgiserver:
container_name: asgiserver
build: ./
command: >
sh -c "echo '>>> EXECUTION asgiserver command' &&
daphne -e ssl:443:privateKey=./docker/certbot/conf/live/${SERVER_HOST}/privkey.pem:certKey=./docker/certbot/conf/live/${SERVER_HOST}/fullchain.pem
FriskesSite.asgi:application -b 0.0.0.0 -p 8001"
# command: daphne FriskesSite.asgi:application -b 0.0.0.0 -p 8001
# --access-log=/var/log/daphne/access.log
# volumes:
# - /var/log/daphne:/var/run/daphne
env_file:
- ./.env
expose:
- 8001
depends_on:
- postgres
- redis
# - rabbitmq
networks:
- front
- back
celery-worker:
container_name: celery-worker
build: ./
entrypoint: ./docker/backend/celery-worker-entrypoint.sh
volumes:
- /var/log/celery:/var/run/celery
environment:
CELERY_APP: ${CELERY_APP}
REDIS_HOST: ${REDIS_HOST}
depends_on:
- postgres
- redis
# - rabbitmq
networks:
- back
celery-beat:
container_name: celery-beat
build: ./
entrypoint: ./docker/backend/celery-beat-entrypoint.sh
volumes:
- /var/log/celery:/var/run/celery
environment:
CELERY_APP: ${CELERY_APP}
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_HOST: ${POSTGRES_HOST}
POSTGRES_PORT: ${POSTGRES_PORT}
depends_on:
- postgres
- redis
# - rabbitmq
networks:
- back
celery-flower:
container_name: celery-flower
build: ./
entrypoint: ./docker/backend/celery-flower-entrypoint.sh
volumes:
- /var/log/celery:/var/run/celery
environment:
CELERY_APP: ${CELERY_APP}
CELERY_FLOWER_URL_PREFIX: ${CELERY_FLOWER_URL_PREFIX}
CELERY_FLOWER_ADDRESS: ${CELERY_FLOWER_ADDRESS}
CELERY_FLOWER_PORT: ${CELERY_FLOWER_PORT}
ports:
- 5555:5555
depends_on:
- postgres
- redis
# - rabbitmq
networks:
- back
volumes:
postgres_data:
# rabbitmq_data:
# rabbitmq_log:
static_volume:
media_volume:
networks:
front:
back: