-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker-compose-all.yml
385 lines (349 loc) · 14 KB
/
docker-compose-all.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
version: '3.6'
services:
pg:
image: postgres:$POSTGRES_VERSION
environment:
- 'POSTGRES_DB=$POSTGRES_DB'
- 'POSTGRES_USER=$POSTGRES_USER'
- 'POSTGRES_PASSWORD=$POSTGRES_PASSWORD'
volumes:
- 'pg-data-volume:/var/lib/postgresql/data'
- './docker/pg/create-users.sql:/docker-entrypoint-initdb.d/create-users.sql'
command: -c log_min_messages=FATAL
rabbitmq:
image: rabbitmq:$RABBITMQ_VERSION
hostname: rabbitmq
volumes:
- './docker/rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf'
- './docker/rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins'
- 'rabbitmq-data-volume:/var/lib/rabbitmq/mnesia/rabbit@rabbitmq'
environment:
- 'RABBITMQ_LOGS=-'
ports:
- $RABBITMQ_MANAGEMENT_LOCAL_PORT:15672
# This acts as HTTP reverse proxy for all the other containers.
nginx:
image: nginx:1.19.4
volumes:
- './docker/nginx/nginx.conf:/etc/nginx/nginx.conf'
- './docker/nginx/templates:/etc/nginx/templates'
- './docker/nginx/static/:/usr/share/nginx/html'
- './docker/nginx/ssl/cert.pem:/etc/nginx/ssl/cert.pem'
- './docker/nginx/ssl/key.pem:/etc/nginx/ssl/key.pem'
ports:
- $PUBLIC_PORT:$PUBLIC_PORT
environment:
- 'PORT=$PUBLIC_PORT'
- 'DEBTORS_HYDRA_URL=http://debtors-hydra:4444'
- 'DEBTORS_LOGIN_URL=http://debtors-login:8080'
- 'DEBTORS_SERVER_URL=http://debtors-apiproxy:8080'
- 'DEBTORS_SWAGGER_UI_URL=http://debtors-swagger-ui:8080'
- 'DEBTORS_WEBAPP_URL=http://debtors-webapp:80'
- 'NGINX_ENTRYPOINT_QUIET_LOGS=1'
depends_on:
- debtors-hydra
- debtors-login
- debtors-apiproxy
- debtors-swagger-ui
- debtors-webapp
# This container acts as a reverse proxy. It extracts the the debtor ID
# from the the incoming HTTP request, calculates a sharding key, and then,
# based on the sharding key, decides to which server to forward the
# incoming request. In this simple example, `debtors-server` is the only
# shard.
debtors-apiproxy:
image: ghcr.io/swaptacular/swpt_apiproxy:latest
volumes:
- './docker/apiproxy/debtors.conf:/etc/apiproxy.conf'
environment:
- 'MIN_DEBTOR_ID=$MIN_DEBTOR_ID'
- 'MAX_DEBTOR_ID=$MAX_DEBTOR_ID'
- 'APIPROXY_PORT=8080'
- 'APIPROXY_CONFIG_FILE=/etc/apiproxy.conf'
restart: always
debtors-server:
build:
context: .
dockerfile: Dockerfile
target: app-image
environment:
- 'MIN_DEBTOR_ID=$MIN_DEBTOR_ID'
- 'MAX_DEBTOR_ID=$MAX_DEBTOR_ID'
- 'OAUTH2_INTROSPECT_URL=http://debtors-hydra:4445/oauth2/introspect'
- 'OAUTH2_SUPERUSER_USERNAME=debtors-superuser'
- 'OAUTH2_SUPERVISOR_USERNAME=debtors-supervisor'
- 'WEBSERVER_PROCESSES=1'
- 'WEBSERVER_THREADS=3'
- 'WEBSERVER_PORT=8080'
- 'POSTGRES_URL=postgresql+psycopg://swpt_debtors:swpt_debtors@pg:5432/${POSTGRES_DB}'
- 'PROTOCOL_BROKER_URL=amqp://guest:guest@rabbitmq:5672'
- 'PROTOCOL_BROKER_QUEUE=swpt_debtors'
- 'PROTOCOL_BROKER_QUEUE_ROUTING_KEY=#'
- 'PROTOCOL_BROKER_PROCESSES=1'
- 'PROTOCOL_BROKER_THREADS=3'
- 'PROTOCOL_BROKER_PREFETCH_COUNT=10'
- 'FLUSH_PROCESSES=1'
- 'FLUSH_PERIOD=1.5'
- 'DELETE_PARENT_SHARD_RECORDS=false'
- 'APP_LOG_LEVEL=warning'
- 'APP_LOG_FORMAT=json'
- 'SUBSTITUTE_LOCALHOST_IN_VARS=PROTOCOL_BROKER_URL'
depends_on:
- pg
- rabbitmq
- debtors-hydra
# The purpose of this container is to create the database schema for
# the `debtors-server` container, and all the necessary RabbitMQ
# objects (queues, exchanges, etc.). It has to be run only once, but
# running it multiple times should not do any harm. Set
# `SETUP_RABBITMQ_BINDINGS` to anything other than "yes", if you do
# not want RabbitMQ exchanges and bindings to be (re)configured.
debtors-server-config:
build:
context: .
dockerfile: Dockerfile
target: app-image
environment:
- 'MIN_DEBTOR_ID=$MIN_DEBTOR_ID'
- 'MAX_DEBTOR_ID=$MAX_DEBTOR_ID'
- 'POSTGRES_URL=postgresql+psycopg://swpt_debtors:swpt_debtors@pg:5432/${POSTGRES_DB}'
- 'PROTOCOL_BROKER_URL=amqp://guest:guest@rabbitmq:5672'
- 'PROTOCOL_BROKER_QUEUE=swpt_debtors'
- 'PROTOCOL_BROKER_QUEUE_ROUTING_KEY=#'
- 'APP_LOG_LEVEL=warning'
- 'APP_LOG_FORMAT=json'
- 'SETUP_RABBITMQ_BINDINGS=yes'
- 'SUBSTITUTE_LOCALHOST_IN_VARS=PROTOCOL_BROKER_URL'
command: configure
depends_on:
- pg
- rabbitmq
# From the `swagger-ui-image`, runs a Swagger UI cleint for the
# "Simple Issuing Web API".
debtors-swagger-ui:
build:
context: .
dockerfile: Dockerfile
target: swagger-ui-image
environment:
- 'BASE_URL=/debtors-swagger-ui'
- 'API_ROOT=https://$PUBLIC_HOST/'
- 'OAUTH2_AUTHORIZATION_URL=https://$PUBLIC_HOST/debtors-hydra/oauth2/auth'
- 'OAUTH2_TOKEN_URL=https://$PUBLIC_HOST/debtors-hydra/oauth2/token'
- 'OAUTH2_REFRESH_URL=https://$PUBLIC_HOST/debtors-hydra/oauth2/token'
- 'OAUTH2_REDIRECT_URL=https://$PUBLIC_HOST/debtors-swagger-ui/oauth2-redirect.html'
# Serves the debtors UI webapp (useful for testing).
debtors-webapp:
image: ghcr.io/swaptacular/swpt_debtors_ui:$SWPT_DEBTORS_UI_VERSION
environment:
- 'SERVER_API_ENTRYPOINT=https://$PUBLIC_HOST/debtors/.debtor'
- 'SERVER_API_TIMEOUT=8000'
- 'AUTHORIZATION_URL=https://$PUBLIC_HOST/debtors-hydra/oauth2/auth'
- 'TOKEN_URL=https://$PUBLIC_HOST/debtors-hydra/oauth2/token'
- 'CLIENT_ID=debtors-webapp'
- 'REDIRECT_URL=https://$PUBLIC_HOST/debtors-webapp/'
- 'TRANSFER_DELETION_DELAY_SECONDS=1296000'
- 'DEFAULT_PEG_ABBR=USD'
- 'DEFAULT_PEG_COIN=https://host.docker.internal:44302/USD#swpt:666'
# This container runs the Web UI for user registrations, login, and
# OAuth2 authorization consent. Note that in production it is
# recommended to also run one "login" container with the `flush`
# command.
debtors-login:
image: ghcr.io/swaptacular/swpt_login:$SWPT_LOGIN_VERSION
environment:
- 'HYDRA_ADMIN_URL=http://debtors-hydra:4445/'
- 'SUBJECT_PREFIX=debtors:'
- 'WEBSERVER_PORT=8080'
- 'WEBSERVER_PROCESSES=1'
- 'WEBSERVER_THREADS=3'
- 'SQLALCHEMY_DATABASE_URI=postgresql://swpt_debtors_login:swpt_debtors_login@pg/${POSTGRES_DB}'
- 'REDIS_URL=redis://redis:6379/1?health_check_interval=30'
- 'SITE_TITLE=Swaptacular'
- 'ABOUT_URL=https://swaptacular.github.io/overview'
- 'MAIL_SERVER=mail'
- 'MAIL_PORT=1025'
- 'MAIL_DEFAULT_SENDER=Swaptacular <no-reply@example.com>'
- 'RECAPTCHA_PUBLIC_KEY=6Lc902MUAAAAAJL22lcbpY3fvg3j4LSERDDQYe37'
- 'RECAPTCHA_PIVATE_KEY=6Lc902MUAAAAAN--r4vUr8Vr7MU1PF16D9k2Ds9Q'
- 'SUPERVISOR_CLIENT_ID=debtors-supervisor'
- 'SUPERVISOR_CLIENT_SECRET=debtors-supervisor'
- 'API_AUTH2_TOKEN_URL=https://nginx:$PUBLIC_PORT/debtors-hydra/oauth2/token'
- 'API_RESOURCE_SERVER=https://nginx:$PUBLIC_PORT'
- 'API_TIMEOUT_SECONDS=5'
- 'APP_SIGNUP_REDIRECT_URL=https://$PUBLIC_HOST/debtors-webapp/'
- 'APP_LOG_LEVEL=warning'
- 'APP_LOG_FORMAT=json'
depends_on:
- pg
- redis
- mail
- debtors-hydra
# The purpose of this container is to initialize the database of the
# `debtors-login` container, and to create a predefined set of
# OAuth2 clients (like "swagger-ui"). It has to be run only once,
# but running it multiple times should not do any harm.
#
# IMPORTANT NOTE: The method of defining OAuth2 clients which we use
# here will not work with Ory Hydra version 2 or newer. Also, to
# configure the default admin API endpoint in Ory Hydra >= 2, you
# should use the "ORY_SDK_URL" environment variable instead of
# "HYDRA_ADMIN_URL" ('ORY_SDK_URL=http://debtors-hydra:4445/').
debtors-login-config:
image: ghcr.io/swaptacular/swpt_login:$SWPT_LOGIN_VERSION
volumes:
- './docker/hydra:/etc/hydra-config'
environment:
- 'HYDRA_ADMIN_URL=http://debtors-hydra:4445/'
- 'SQLALCHEMY_DATABASE_URI=postgresql://swpt_debtors_login:swpt_debtors_login@pg/${POSTGRES_DB}'
command: >
sh -c '/usr/src/app/entrypoint.sh configure
&& (
hydra clients get debtors-webapp --fake-tls-termination > /dev/null
|| hydra clients import
/etc/hydra-config/debtors-supervisor.json
/etc/hydra-config/debtors-superuser.json
/etc/hydra-config/swagger-ui.json
/etc/hydra-config/debtors-webapp.json
--fake-tls-termination
)'
depends_on:
- pg
- debtors-hydra
restart: on-failure
# This container runs the Ory Hydra open source OAuth 2.0 server
# (https://github.com/ory/hydra), which is used to generate and
# verify access tokens.
#
# IMPORTANT NOTE: Here we use an old version (v1.11.10) of Ory
# Hydra. The reason for this is that from version 2, Ory Hydra does
# not allow users to chose client IDs (they are always automatically
# generated UUIDs). However, for this demo to work without
# complicated parameters tweaking, we need to be able to choose the
# client IDs.
#
# Another important backward incompatible change that Ory Hydra 2
# brings is that it prefixes all admin API endpoints with "/admin/".
#
# Therefore, in the client containers, instead of:
# 'HYDRA_ADMIN_URL=http://debtors-hydra:4445/' and
# 'OAUTH2_INTROSPECT_URL=http://debtors-hydra:4445/oauth2/introspect'
#
# with Ory Hydra >= 2, we would have:
# 'HYDRA_ADMIN_URL=http://debtors-hydra:4445/admin/' and
# 'OAUTH2_INTROSPECT_URL=http://debtors-hydra:4445/admin/oauth2/introspect'
debtors-hydra:
image: oryd/hydra:v1.11.10
environment:
- 'SERVE_PUBLIC_PORT=4444'
- 'SERVE_ADMIN_PORT=4445'
- 'SERVE_TLS_ALLOW_TERMINATION_FROM=0.0.0.0/0'
- 'TTL_ACCESS_TOKEN=24h'
- 'TTL_REFRESH_TOKEN=720h'
- 'SECRETS_SYSTEM=$HYDRA_SYSTEM_SECRET'
- 'URLS_SELF_ISSUER=https://$PUBLIC_HOST/debtors-hydra/'
- 'URLS_LOGIN=https://$PUBLIC_HOST/debtors-login/'
- 'URLS_CONSENT=https://$PUBLIC_HOST/debtors-consent/'
- 'URLS_ERROR=https://github.com/swaptacular/swpt_login'
- 'DSN=postgres://hydra_debtors:hydra_debtors@pg/${POSTGRES_DB}?sslmode=disable&max_conns=2&max_idle_conns=1&max_conn_lifetime=30s'
- 'SQA_OPT_OUT=true'
- 'LOG_LEVEL=warn'
- 'LOG_FORMAT=json'
depends_on:
- pg
restart: on-failure
# The purpose of this container is to initialize the database of the
# `debtors-hydra` container. It has to be run only once, but running
# it multiple times should not do any harm.
debtors-hydra-config:
image: oryd/hydra:v1.11.10
environment:
- 'DSN=postgres://hydra_debtors:hydra_debtors@pg/${POSTGRES_DB}?sslmode=disable&max_conns=2&max_idle_conns=1&max_conn_lifetime=30s'
command:
migrate sql --read-from-env --yes
depends_on:
- pg
restart: on-failure
debtors-stomp-server:
image: ghcr.io/swaptacular/swpt_stomp:$SWPT_STOMP_VERSION
environment:
- 'PROTOCOL_BROKER_URL=amqp://guest:guest@rabbitmq:5672'
- 'SWPT_SERVER_PORT=1234'
- 'SWPT_SERVER_CERT=/etc/swpt/server.crt'
- 'SWPT_SERVER_KEY=/secrets/swpt-server.key'
- 'SWPT_NODEDATA_URL=file:///var/lib/swpt-nodedata'
- 'APP_LOG_LEVEL=info'
- 'APP_LOG_FORMAT=json'
- 'SUBSTITUTE_LOCALHOST_IN_VARS=PROTOCOL_BROKER_URL'
volumes:
- './docker/nodedata/server.crt:/etc/swpt/server.crt'
- './docker/nodedata/server.key:/secrets/swpt-server.key'
- './docker/nodedata:/var/lib/swpt-nodedata'
ports:
- $SWPT_SERVER_LOCAL_PORT:1234
command: swpt-server
depends_on:
- rabbitmq
restart: always
# The purpose of this container is to create and configure the RabbitMQ
# queue, from which the "debtors-peer-1234abcd" container will consume
# messages (to send them to the peer). It has to be run only once, but
# running it multiple times should not do any harm.
debtors-peer-1234abcd-config:
image: ghcr.io/swaptacular/swpt_stomp:$SWPT_STOMP_VERSION
environment:
- 'PROTOCOL_BROKER_URL=amqp://guest:guest@rabbitmq:5672'
- 'SWPT_SERVER_CERT=/etc/swpt/server.crt'
- 'SWPT_SERVER_KEY=/secrets/swpt-server.key'
- 'SWPT_NODEDATA_URL=file:///var/lib/swpt-nodedata'
- 'APP_LOG_LEVEL=info'
- 'APP_LOG_FORMAT=json'
- 'SUBSTITUTE_LOCALHOST_IN_VARS=PROTOCOL_BROKER_URL'
volumes:
- './docker/nodedata/server.crt:/etc/swpt/server.crt'
- './docker/nodedata/server.key:/secrets/swpt-server.key'
- './docker/nodedata:/var/lib/swpt-nodedata'
command: configure-queue 1234abcd da.1234abcd
depends_on:
- rabbitmq
restart: on-failure
# The purpose of this container is to open and maintain a permanent client
# STOMP connection to the "1234abcd" peer, sending outgoing Swaptacular
# Messaging Protocol messages to this peer.
debtors-peer-1234abcd:
image: ghcr.io/swaptacular/swpt_stomp:$SWPT_STOMP_VERSION
environment:
- 'PROTOCOL_BROKER_URL=amqp://guest:guest@rabbitmq:5672'
- 'SWPT_SERVER_CERT=/etc/swpt/server.crt'
- 'SWPT_SERVER_KEY=/secrets/swpt-server.key'
- 'SWPT_NODEDATA_URL=file:///var/lib/swpt-nodedata'
- 'APP_LOG_LEVEL=info'
- 'APP_LOG_FORMAT=json'
- 'SUBSTITUTE_LOCALHOST_IN_VARS=PROTOCOL_BROKER_URL'
volumes:
- './docker/nodedata/server.crt:/etc/swpt/server.crt'
- './docker/nodedata/server.key:/secrets/swpt-server.key'
- './docker/nodedata:/var/lib/swpt-nodedata'
extra_hosts:
- "host.docker.internal:host-gateway"
command: swpt-client 1234abcd da.1234abcd
depends_on:
- rabbitmq
restart: always
# The `debtors-login` container needs access to a Redis server
# instance.
redis:
image: redis:6.0.9
volumes:
- 'redis-data-volume:/data'
# The `debtors-login` container needs access to a mail server
# instance. This runs a dummy mail server which is useful only for
# testing.
mail:
image: mailhog/mailhog:v1.0.1
ports:
- $MAILHOG_LOCAL_PORT:8025
volumes:
pg-data-volume:
rabbitmq-data-volume:
redis-data-volume: