-
-
Notifications
You must be signed in to change notification settings - Fork 237
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
255 lines (235 loc) · 8.37 KB
/
docker-compose.yml
File metadata and controls
255 lines (235 loc) · 8.37 KB
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
services:
api: &main_app
build:
context: .
dockerfile: ./Dockerfile
target: prod
image: {{cookiecutter.project_name}}:{{"${" }}{{cookiecutter.project_name | upper }}_VERSION:-latest{{"}"}}
restart: always
env_file:
- path: .env
required: false
{%- if cookiecutter.traefik_labels == "True" %}
labels:
# Enables traefik for this container.
- traefik.enable=true
- traefik.http.routers.{{cookiecutter.project_name}}.rule=Host(`{{ "${" }}{{cookiecutter.project_name | upper}}_TRAEFIK_HOST:-{{cookiecutter.project_name}}.localhost{{ "}" }}`)
- traefik.http.routers.{{cookiecutter.project_name}}.entrypoints=http
- traefik.http.routers.{{cookiecutter.project_name}}.service={{cookiecutter.project_name}}
- traefik.http.services.{{cookiecutter.project_name}}.loadbalancer.server.port={{ "${" }}{{cookiecutter.project_name | upper}}_PORT:-8000{{ "}" }}
networks:
- default
- traefik-shared
{%- endif %}
{%- if ((cookiecutter.db_info.name != "none" and cookiecutter.db_info.name != "sqlite") or
(cookiecutter.enable_redis == "True") or
(cookiecutter.enable_rmq == "True") or
(cookiecutter.enable_kafka == "True")) %}
depends_on:
{%- if cookiecutter.db_info.name != "none" %}
{%- if cookiecutter.db_info.name != "sqlite" %}
db:
condition: service_healthy
{%- endif %}
{%- endif %}
{%- if cookiecutter.enable_redis == "True" %}
redis:
condition: service_healthy
{%- endif %}
{%- if cookiecutter.enable_rmq == "True" %}
rmq:
condition: service_healthy
{%- endif %}
{%- if cookiecutter.enable_kafka == "True" %}
kafka:
condition: service_healthy
{%- endif %}
{%- if cookiecutter.enable_migrations == 'True' and cookiecutter.orm != 'psycopg' %}
migrator:
condition: service_completed_successfully
{%- endif %}
{%- endif %}
environment:
{{cookiecutter.project_name | upper }}_HOST: 0.0.0.0
{%- if cookiecutter.db_info.name != "none" %}
{%- if cookiecutter.db_info.name == "sqlite" %}
{{cookiecutter.project_name | upper }}_DB_FILE: /db_data/db.sqlite3
{%- else %}
{{cookiecutter.project_name | upper}}_DB_HOST: {{cookiecutter.project_name}}-db
{{cookiecutter.project_name | upper}}_DB_PORT: {{cookiecutter.db_info.port}}
{{cookiecutter.project_name | upper}}_DB_USER: {{cookiecutter.project_name}}
{{cookiecutter.project_name | upper}}_DB_PASS: {{cookiecutter.project_name}}
{%- if cookiecutter.db_info.name == "mongodb" %}
{{cookiecutter.project_name | upper}}_DB_BASE: admin
{%- else %}
{{cookiecutter.project_name | upper}}_DB_BASE: {{cookiecutter.project_name}}
{%- endif %}
{%- endif %}
{%- endif %}
{%- if cookiecutter.enable_rmq == 'True' %}
{{cookiecutter.project_name | upper }}_RABBIT_HOST: {{cookiecutter.project_name}}-rmq
{%- endif %}
{%- if cookiecutter.enable_redis == 'True' %}
{{cookiecutter.project_name | upper }}_REDIS_HOST: {{cookiecutter.project_name}}-redis
{%- endif %}
{%- if cookiecutter.enable_kafka == "True" %}
TESTKAFKA_KAFKA_BOOTSTRAP_SERVERS: '["{{cookiecutter.project_name}}-kafka:9092"]'
{%- endif %}
{%- if cookiecutter.db_info.name == "sqlite" %}
volumes:
- {{cookiecutter.project_name}}-db-data:/db_data/
{%- endif %}
command:
- python
- -m
- {{cookiecutter.project_name}}
{%- if cookiecutter.enable_taskiq == "True" %}
taskiq-worker:
<<: *main_app
labels: []
command:
- taskiq
- worker
- {{cookiecutter.project_name}}.tkq:broker
{%- endif %}
{%- if cookiecutter.db_info.name == "postgresql" %}
db:
image: {{cookiecutter.db_info.image}}
hostname: {{cookiecutter.project_name}}-db
environment:
POSTGRES_PASSWORD: "{{cookiecutter.project_name}}"
POSTGRES_USER: "{{cookiecutter.project_name}}"
POSTGRES_DB: "{{cookiecutter.project_name}}"
volumes:
- {{cookiecutter.project_name}}-db-data:/var/lib/postgresql
restart: always
healthcheck:
test: pg_isready -U {{cookiecutter.project_name}}
interval: 2s
timeout: 3s
retries: 40
{%- endif %}
{%- if cookiecutter.db_info.name == "mongodb"%}
db:
image: {{cookiecutter.db_info.image}}
hostname: {{cookiecutter.project_name}}-db
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: "{{cookiecutter.project_name}}"
MONGO_INITDB_ROOT_PASSWORD: "{{cookiecutter.project_name}}"
command: "mongod"
volumes:
- {{cookiecutter.project_name}}-db-data:/data/db
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet
interval: 10s
timeout: 5s
retries: 40
{%- endif %}
{%- if cookiecutter.db_info.name == "mysql" %}
db:
image: {{cookiecutter.db_info.image}}
hostname: {{cookiecutter.project_name}}-db
restart: always
environment:
MYSQL_USER: "{{cookiecutter.project_name}}"
MYSQL_PASSWORD: "{{cookiecutter.project_name}}"
MYSQL_DATABASE: "{{cookiecutter.project_name}}"
MYSQL_ROOT_PASSWORD: "{{cookiecutter.project_name}}"
MYSQL_HOST: "0.0.0.0"
healthcheck:
test:
- CMD
- mysqladmin
- ping
- --user={{cookiecutter.project_name}}
- --password={{cookiecutter.project_name}}
interval: 10s
timeout: 5s
retries: 40
volumes:
- "{{cookiecutter.project_name}}-db-data:/var/lib/mysql"
{%- endif %}
{%- if cookiecutter.enable_migrations == 'True' and cookiecutter.orm != 'psycopg' %}
migrator:
<<: *main_app
restart: "no"
{%- if cookiecutter.orm in ['sqlalchemy', 'ormar'] %}
command: alembic upgrade head
{%- elif cookiecutter.orm == 'tortoise' %}
command: aerich upgrade
{%- elif cookiecutter.orm == 'piccolo' %}
command: piccolo migrations forwards all
{%- elif cookiecutter.orm == 'beanie' %}
command: beanie migrate -db admin -uri mongodb://{{cookiecutter.project_name}}:{{cookiecutter.project_name}}@{{cookiecutter.project_name}}-db:27017/ -p {{cookiecutter.project_name}}/db/migrations/
{%- endif %}
{%- if cookiecutter.db_info.name != "sqlite" %}
depends_on:
db:
condition: service_healthy
{%- else %}
depends_on: {}
{%- endif %}
{%- endif %}
{%- if cookiecutter.enable_redis == "True" %}
redis:
image: redis:8.4.0
hostname: "{{cookiecutter.project_name}}-redis"
restart: always
environment:
ALLOW_EMPTY_PASSWORD: "yes"
healthcheck:
test: redis-cli ping
interval: 1s
timeout: 3s
retries: 50
{%- endif %}
{%- if cookiecutter.enable_rmq == "True" %}
rmq:
image: rabbitmq:4.2.1-management-alpine
hostname: "{{cookiecutter.project_name}}-rmq"
restart: always
environment:
RABBITMQ_DEFAULT_USER: "guest"
RABBITMQ_DEFAULT_PASS: "guest"
RABBITMQ_DEFAULT_VHOST: "/"
healthcheck:
test: rabbitmq-diagnostics check_running -q
interval: 3s
timeout: 3s
retries: 50
{%- endif %}
{%- if cookiecutter.enable_kafka == "True" %}
kafka:
image: apache/kafka:4.1.1
hostname: "{{cookiecutter.project_name}}-kafka"
environment:
KAFKA_NODE_ID: "0"
KAFKA_PROCESS_ROLES: "controller,broker"
KAFKA_LISTENERS: "PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094"
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka:9092,EXTERNAL://localhost:9094"
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: "CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT"
KAFKA_CONTROLLER_QUORUM_VOTERS: "0@{{cookiecutter.project_name}}-kafka:9093"
KAFKA_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1"
# Uncomment it to connect from localhost.
# ports:
# - 9094:9094
healthcheck:
test: /opt/kafka/bin/kafka-topics.sh --list --bootstrap-server localhost:9092
interval: 1s
timeout: 3s
retries: 30
{%- endif %}
{% if cookiecutter.db_info.name != 'none' %}
volumes:
{{cookiecutter.project_name}}-db-data:
name: {{cookiecutter.project_name}}-db-data
{%- endif %}
{%- if cookiecutter.traefik_labels == "True" %}
networks:
# Network for traefik.
traefik-shared:
name: traefik-shared
{%- endif %}