-
Notifications
You must be signed in to change notification settings - Fork 16
/
docker-compose.yml
280 lines (254 loc) · 7.99 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
networks:
frontend:
name: frontend
external: false
backend:
name: backend
external: false
backend-test:
name: backend-test
external: false
# Base configuration for services that use the local smr image
x-smr-base: &smr-base
build:
context: .
args:
- NO_DEV
image: local/smr
pull_policy: never
environment: &smr-base-env
MYSQL_HOST:
MYSQL_USER:
MYSQL_DATABASE:
MYSQL_PASSWORD_FILE: /run/secrets/mysql-password
secrets:
- source: mysql-password
mode: 0444
# Web configuration for `smr` (production) and `smr-dev` (testing).
x-smr-web: &smr-web
<<: *smr-base
container_name: ${SMR_HOST}
networks:
- frontend
- backend
labels:
- "traefik.enable=true"
- "traefik.http.routers.${SMR_HOST}.rule=${SMR_RULE:-PathPrefix(`/`)}"
depends_on:
- mysql
- smtp
environment:
<<: *smr-base-env
XDEBUG_MODE:
DISABLE_PHPDI_COMPILATION:
# Allow the process to be interruptible with SIGINT.
# For tests, this may corrupt the test database and require a reset.
# CLI programs may not be cleaned up properly if interrupted.
# (see https://github.com/docker-library/php/issues/505)
init: true
# Base configuration for the SMR command line tools
x-smr-cli: &smr-cli
<<: *smr-base
networks:
- backend
depends_on:
- mysql
- smtp
volumes:
- ./config:/smr/config:ro
# Mount the source code instead of copying it.
- ./src:/smr/src:ro
# Base configuration for SMR testing tools
x-smr-test: &smr-test
<<: *smr-base
environment:
<<: *smr-base-env
XDEBUG_MODE: "off"
volumes:
- ./config/config.specific.sample.php:/smr/config/config.specific.php:ro
- ./phpunit.xml:/smr/phpunit.xml:ro
- ./phpstan.neon.dist:/smr/phpstan.neon.dist:ro
- ./phpcs.xml:/smr/phpcs.xml:ro
- ./rector.php:/smr/rector.php:ro
# Mount the source code instead of copying it.
- ./src:/smr/src:rw
- ./test:/smr/test:rw
x-mysql-common: &mysql-common
image: mysql:8.1
container_name: ${MYSQL_HOST}
environment:
- MYSQL_USER
- MYSQL_DATABASE
- MYSQL_PASSWORD_FILE=/run/secrets/mysql-password
- MYSQL_ROOT_PASSWORD_FILE=/run/secrets/mysql-root-password
secrets:
- mysql-password
- mysql-root-password
command: [ "mysqld",
"--character-set-server=utf8",
"--collation-server=utf8_general_ci" ]
healthcheck:
test: mysql -uroot -p$$(cat $$MYSQL_ROOT_PASSWORD_FILE) -e 'SHOW DATABASES'
interval: 5s
timeout: 20s
services:
smr:
<<: *smr-web
volumes:
- ./vol_upload:/smr/src/htdocs/upload:rw
- ./config:/smr/config:ro
smr-dev:
<<: *smr-web
volumes:
- ./vol_upload:/smr/src/htdocs/upload:rw
- ./config:/smr/config:ro
# Mount the source code instead of copying it.
- ./src:/smr/src:ro
# Directory for Xdebug profiler output
- ./vol_xdebug:/tmp/xdebug:rw
smtp:
image: mwader/postfix-relay
networks:
- backend
environment:
- POSTFIX_myhostname=hostname.local
- OPENDKIM_DOMAINS=smrealms.de=key1
volumes:
- ./opendkim:/etc/opendkim/keys/smrealms.de:rw
flyway: &flyway-common
image: flyway/flyway:10.14.0-alpine
# Allow retries in case the mysql service is still spinning up
command: migrate
environment:
FLYWAY_CONNECT_RETRIES: 20
FLYWAY_PASSWORD: ${MYSQL_PASSWORD}
FLYWAY_URL: "jdbc:mysql://${MYSQL_HOST}/${MYSQL_DATABASE}?allowPublicKeyRetrieval=true&useSSL=false"
FLYWAY_USER: ${MYSQL_USER}
networks:
- backend
depends_on:
- mysql
volumes:
- ./db/patches:/flyway/sql:ro
flyway-test:
<<: *flyway-common
networks:
- backend-test
depends_on:
- mysql-test
mysql:
<<: *mysql-common
networks:
- backend
volumes:
- ./vol_db:/var/lib/mysql:rw
# MySQL container with no volumes mounted for testing
mysql-test:
<<: *mysql-common
networks:
- backend-test
phpunit:
<<: *smr-test
entrypoint: vendor/bin/phpunit
networks:
- backend-test
environment:
<<: *smr-base-env
XDEBUG_MODE: coverage
depends_on:
mysql-test:
condition: service_healthy
phpstan:
<<: *smr-test
entrypoint: vendor/bin/phpstan --memory-limit=4G --ansi analyse -v
phpcs:
<<: *smr-test
entrypoint: vendor/bin/phpcs --report-code --report-source
phpcbf:
<<: *smr-test
entrypoint: vendor/bin/phpcbf
rector:
<<: *smr-test
entrypoint: vendor/bin/rector process
pma:
image: phpmyadmin/phpmyadmin
networks:
- frontend
- backend
environment:
PMA_HOST: ${MYSQL_HOST}
PMA_ABSOLUTE_URI: /pma/
labels:
- "traefik.enable=true"
- "traefik.http.routers.pma-${MYSQL_HOST}.rule=${SMR_RULE:-PathPrefix(`/`)} && PathPrefix(`/pma`)"
- "traefik.http.routers.pma-${MYSQL_HOST}.middlewares=slash-then-strip@file"
depends_on:
- mysql
discord:
command: php src/tools/discord/bot.php
<<: *smr-cli
irc:
command: php src/tools/irc/irc.php
<<: *smr-cli
npc:
command: php src/tools/npc/npc.php
<<: *smr-cli
traefik:
image: traefik:3.2
networks:
- frontend
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik:/etc/traefik:ro
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.rule=PathPrefix(`/api`) || PathPrefix(`/dashboard`)"
- "traefik.http.routers.traefik.service=api@internal"
- "traefik.http.routers.traefik.middlewares=add-slash@file"
ports:
- "80:80"
- "443:443"
# Generate rich API documentation of the SMR source code.
api-docs:
build:
context: .
dockerfile: ./api-docs/Dockerfile
networks:
- frontend
labels:
- "traefik.enable=true"
- "traefik.http.routers.api-docs.rule=PathPrefix(`/docs`)"
- "traefik.http.routers.api-docs.middlewares=slash-then-strip@file"
# Web interface for managing Docker services
portainer:
image: portainer/portainer-ce
networks:
- frontend
labels:
- "traefik.enable=true"
- "traefik.http.routers.portainer.rule=PathPrefix(`/docker`)"
- "traefik.http.routers.portainer.middlewares=slash-then-strip@file"
- "traefik.http.services.portainer.loadbalancer.server.port=9000"
command: -H unix:///var/run/docker.sock
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./vol_portainer:/data:rw
# Web interface to display Xdebug profiler results
webgrind:
image: jokkedk/webgrind
networks:
- frontend
labels:
- "traefik.enable=true"
- "traefik.http.routers.webgrind.rule=PathPrefix(`/webgrind`)"
- "traefik.http.routers.webgrind.middlewares=slash-then-strip@file"
volumes:
# Webgrind looks for Xdebug profiler files in /tmp by default
- ./vol_xdebug:/tmp:rw
# Files mapped under /host will be available for code lookup
- ./src:/host/smr/src:ro
secrets:
mysql-password:
environment: "MYSQL_PASSWORD"
mysql-root-password:
environment: "MYSQL_ROOT_PASSWORD"