-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdocker-compose.yml
258 lines (243 loc) · 7.44 KB
/
docker-compose.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
x-common-env-vars:
&common-env-vars
DOCKERIZED: "True"
REDIS_HOST: "redis"
POSTGRES_HOST: "postgres"
DJANGO_HOST: "django"
NEXTJS_HOST: "nextjs"
x-backend-deps:
&backend-deps
postgres:
condition: service_healthy
redis:
condition: service_healthy
elasticsearch:
condition: service_healthy
x-default:
&default
deploy:
restart_policy:
condition: "${DOCKER_DEFAULT_RESTART_POLICY:-unless-stopped}"
environment:
<<: *common-env-vars
env_file: .env
x-django-default:
&django-default
<<: *default
image: "ghcr.io/modularhistory/backend:${SHA:-latest}"
depends_on:
<<: *backend-deps
env_file: .env
environment:
<<: *common-env-vars
user: www-data
services:
django:
<<: *django-default
command: gunicorn core.asgi:application --user www-data --bind 0.0.0.0:${DJANGO_PORT} -k uvicorn.workers.UvicornWorker --workers 9 --max-requests 100 --max-requests-jitter 50
entrypoint: /.config/entrypoints/django
healthcheck:
test:
[
"CMD-SHELL",
"curl --fail http://localhost:${DJANGO_PORT}/healthcheck/ || exit 1"
]
timeout: 7s
interval: 30s
retries: 3
start_period: 60s
ports:
- "127.0.0.1:${DJANGO_PORT}:${DJANGO_PORT}"
volumes:
# NOTE: www-data must be granted permission to write to these directories
# both in the container and on the host machine. Permissions to write in
# the container are granted in Dockerfile.backend. Permissions to write on
# the host machine must be granted manually; e.g.,
# sudo chown -R www-data:www-data .backups && sudo chmod g+w -R .backups
- ./_volumes:/_volumes
- ./.config:/.config
- es_certs:${ELASTIC_CERTS_DIR}
celery:
<<: *django-default
command: celery -A core worker --hostname=%h --loglevel=info -E
entrypoint: /.config/entrypoints/celery
environment:
<<: *common-env-vars
IS_CELERY: "True"
healthcheck:
test: celery -A core inspect ping -d celery@$$HOSTNAME
timeout: 30s
interval: 30s
retries: 3
start_period: 20s
volumes:
- ./_volumes:/_volumes
- ./.config:/.config
celery_beat:
<<: *django-default
command: celery -A core beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler --pidfile /tmp/celerybeat.pid
depends_on:
<<: *backend-deps
celery:
condition: service_healthy
healthcheck:
test: [ "CMD-SHELL", "stat -t /tmp/celerybeat.pid || exit 1" ]
timeout: 20s
interval: 30s
retries: 3
start_period: 10s
volumes:
- ./.config:/.config
create_es_certs:
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.1
environment:
ELASTIC_PASSWORD: $ELASTIC_PASSWORD
command: >
bash -c '
if [[ ! -f /certs/bundle.zip ]]; then
bin/elasticsearch-certutil cert --silent --pem --in "${ELASTIC_CERTS_DIR}/instances.yml" -out /certs/bundle.zip;
unzip /certs/bundle.zip -d /certs;
fi;
chown -R 1000:0 /certs
'
user: "0"
working_dir: /usr/share/elasticsearch
volumes:
- es_certs:/certs
- ./.config/elasticsearch:${ELASTIC_CERTS_DIR}
elasticsearch:
<<: *default
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.1
depends_on:
create_es_certs:
condition: service_completed_successfully
environment:
# https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html
- node.name=modularhistory-es
- cluster.name=es-docker-cluster
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms1536m -Xmx1536m"
- xpack.ml.enabled=true
- xpack.security.enabled=true
- xpack.security.http.ssl.enabled=true
- xpack.security.http.ssl.key=${ELASTIC_CERTS_DIR}/modularhistory-es/modularhistory-es.key
- xpack.security.http.ssl.certificate_authorities=${ELASTIC_CERTS_DIR}/ca/ca.crt
- xpack.security.http.ssl.certificate=${ELASTIC_CERTS_DIR}/modularhistory-es/modularhistory-es.crt
- xpack.security.transport.ssl.enabled=true
- xpack.security.transport.ssl.verification_mode=certificate
- xpack.security.transport.ssl.certificate_authorities=${ELASTIC_CERTS_DIR}/ca/ca.crt
- xpack.security.transport.ssl.certificate=${ELASTIC_CERTS_DIR}/modularhistory-es/modularhistory-es.crt
- xpack.security.transport.ssl.key=${ELASTIC_CERTS_DIR}/modularhistory-es/modularhistory-es.key
- xpack.security.http.ssl.client_authentication=optional
expose:
- "9200"
healthcheck:
test: curl --cacert ${ELASTIC_CERTS_DIR}/ca/ca.crt -s https://localhost:9200 >/dev/null; if [[ $$? == 52 ]]; then echo 0; else echo 1; fi
interval: 30s
timeout: 10s
retries: 5
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- es_data:/usr/share/elasticsearch/data
- es_certs:${ELASTIC_CERTS_DIR}
kibana:
<<: *default
image: docker.elastic.co/kibana/kibana:7.8.1
depends_on:
- elasticsearch
environment:
ELASTICSEARCH_URL: http://elasticsearch:9200
ELASTICSEARCH_HOSTS: http://elasticsearch:9200
ELASTICSEARCH_USERNAME: elastic
# ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD
expose:
- "5601"
nextjs:
<<: *default
image: "ghcr.io/modularhistory/frontend:${SHA}"
command: "npm run start"
depends_on:
- django
environment:
PORT: ${NEXTJS_PORT}
NEXTAUTH_URL_INTERNAL: "http://nextjs:${NEXTJS_PORT}"
NODE_ENV: "production"
ports:
- "127.0.0.1:${NEXTJS_PORT}:${NEXTJS_PORT}"
volumes:
- ./_volumes/static:/_volumes/static
- ./_volumes/redirects:/_volumes/redirects
redis:
<<: *default
image: redis
command: redis-server /usr/local/etc/redis/redis.conf
expose:
- "6379"
# TODO: https://stackoverflow.com/questions/47088261/restarting-an-unhealthy-docker-container-based-on-healthcheck
healthcheck:
test: [ "CMD", "redis-cli", "ping" ]
interval: 20s
timeout: 10s
retries: 3
start_period: 20s
volumes:
- "data:/data"
- ./.config/redis:/usr/local/etc/redis
postgres:
<<: *default
image: postgres:14
expose:
- "5432"
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
volumes:
- postgres_data:/var/lib/postgresql/data
- ./_volumes/db/init:/docker-entrypoint-initdb.d
# redisinsight:
# image: redislabs/redisinsight:latest
# profiles: [ "debug" ]
# depends_on:
# - redis
# deploy:
# restart_policy:
# condition: "${DOCKER_DEFAULT_RESTART_POLICY:-unless-stopped}"
# max_attempts: 3
# env_file: .env
# environment:
# REDIS_HOSTS: "local:redis:6379"
# healthcheck:
# test:
# [
# "CMD-SHELL",
# "curl --fail http://localhost:8002/healthcheck/ || exit 1"
# ]
# timeout: 7s
# interval: 15s
# retries: 2
# start_period: 10s
# ports:
# - "127.0.0.1:${DJANGO_PORT}:${DJANGO_PORT}"
# volumes:
# - "redisinsight:/db"
setup:
image: "ghcr.io/modularhistory/backend:${SHA}"
env_file: .env
entrypoint: .config/entrypoints/setup
command: exit 0
working_dir: /media
volumes:
- .:/media
volumes:
data: null
postgres_data: null
es_data: null
es_certs: null
# redisinsight: null