-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathdocker-compose.yml
More file actions
372 lines (357 loc) · 9.08 KB
/
Copy pathdocker-compose.yml
File metadata and controls
372 lines (357 loc) · 9.08 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
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
volumes:
assets:
config:
database:
storage:
logs:
profile-stats:
prometheus:
test-cache:
test-coverage:
uds-nginx-web:
# Ensure that no service is both connected to a non-internal network and attempts to resolve other containers by name. If a container that’s connected to a non-internal network attempts to resolve a container that’s down, it will fall back to external DNS, which is itself unwanted but could lead to worse results if resolving externally somehow succeeds: there’s no mTLS or anything, so at worst, a malicious external network could impersonate `web` to `nginx`, or `postgres`/`memcached` to `web`. This is pretty niche and unlikely, but it reflects a serious design issue.
#
# So:
# - `web` connects to `postgres`, `memcached`, and `web-outgoing` by name, but has only internal networks (and uses `web-outgoing` to make limited HTTP requests)
# - `nginx` and `prometheus` are connected to non-internal networks, but only connect to `web` via a Unix socket in the `uds-nginx-web` volume
networks:
external-web-outgoing:
external-nginx:
external-prometheus:
web-memcached:
internal: true
web-postgres:
internal: true
web-web-outgoing:
internal: true
test-postgres:
internal: true
prometheus-web:
internal: true
services:
nginx:
build: containers/nginx
volumes:
- assets:/weasyl/build:ro
- storage:/weasyl/static:ro
- test-coverage:/weasyl/coverage:ro
- uds-nginx-web:/run/uds-nginx-web
tmpfs:
# owner nginx:root
- '/run/nginx:mode=700,uid=1000'
- '/var/lib/nginx/tmp:mode=700,uid=1000'
networks:
- external-nginx
ports:
- ${WEASYL_BIND:-127.0.0.1}:8080:8080/tcp
read_only: true
web:
image: weasyl
pull_policy: never
build: &weasyl-build
context: .
args:
version: '${WEASYL_VERSION:-}'
environment:
https_proxy: 'socks5h://web-outgoing'
WEASYL_STORAGE_ROOT: 'storage'
WEASYL_RELOAD_ASSETS: 'true'
WEASYL_RELOAD_TEMPLATES: 'true'
WEB_CONCURRENCY: '8'
PYTHONWARNINGS: 'd'
PYTHONUNBUFFERED: '1'
PROMETHEUS_MULTIPROC_DIR: '/weasyl/storage/prometheus'
volumes:
- assets:/weasyl/build:ro
- config:/run/config:ro
- storage:/weasyl/storage/static
- logs:/weasyl/storage/log
- profile-stats:/weasyl/storage/profile-stats
- uds-nginx-web:/weasyl/uds-nginx-web
- type: tmpfs
target: /tmp
tmpfs:
- '/weasyl/storage/prometheus:mode=700,uid=1000'
- '/weasyl/storage/temp:mode=700,uid=1000'
- '/magick-tmp:mode=700,uid=1000'
networks:
- prometheus-web
- web-memcached
- web-postgres
- web-web-outgoing
read_only: false
depends_on:
- postgres
- memcached
- web-outgoing
command:
- .venv/bin/gunicorn
- --bind
- unix:uds-nginx-web/web.sock
develop:
watch:
- action: sync+restart
path: ./weasyl
target: /weasyl/weasyl
ignore:
- templates/
- test/
- action: sync+restart
path: ./libweasyl
target: /weasyl/libweasyl
ignore:
- alembic/
- test/
- action: sync
path: ./weasyl/templates
target: /weasyl/weasyl/templates
web-outgoing:
image: ghcr.io/weasyl/netferret@sha256:67399ee7670d250eb057e3139a98387d1299a7622131d6ba049e98a5edd85fe4
init: true
user: '1000'
command:
# Turnstile
- -a
- challenges.cloudflare.com
# currency conversion in `weasyl.commishinfo`
- -a
- www.ecb.europa.eu
# oEmbed in `weasyl.embed` and their `thumbnail_url`s
- -a
- www.youtube.com
- -a
- i.ytimg.com
- -a
- vimeo.com
- -a
- i.vimeocdn.com
- -a
- soundcloud.com
- -a
- i1.sndcdn.com
- -a
- sketchfab.com
- -a
- media.sketchfab.com
- -a
- bandcamp.com
# crossposting in `weasyl.submission` not included by default
networks:
- external-web-outgoing
- web-web-outgoing
read_only: true
memcached:
image: docker.io/library/memcached:1.6-alpine3.22
command: --memory-limit=64
networks:
- web-memcached
read_only: true
postgres:
build: containers/postgres
environment:
POSTGRES_HOST_AUTH_METHOD: trust
POSTGRES_USER: weasyl
POSTGRES_DB: weasyl
volumes:
- database:/var/lib/postgresql/data
- type: tmpfs
target: /run/postgresql
- type: tmpfs
target: /tmp
networks:
- web-postgres
# TODO: separate postgres service for tests
- test-postgres
read_only: true
mail-logger:
build: containers/postfix-stone
init: true
user: '100'
command:
- sh
- -c
- |
stunnel
smtp-sink -D /mail/%Y-%m-%d unix:/run/user/100/smtp-sink.sock 128
tmpfs:
- '/mail:mode=700,uid=100'
- '/run/user/100:mode=700,uid=100'
networks:
- web-postgres
read_only: true
prometheus:
profiles: [ prometheus ]
build: containers/prometheus
entrypoint: []
command:
- /bin/sh
- -c
# Prometheus doesn’t support scraping Unix sockets:
# https://github.com/prometheus/prometheus/issues/12024
- |
nc -lk -p 8080 ::1 -e nc local:/run/uds-nginx-web/web.sock &
exec /bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/prometheus
volumes:
- prometheus:/prometheus
- uds-nginx-web:/run/uds-nginx-web
networks:
- external-prometheus
- prometheus-web
ports:
- ${WEASYL_BIND:-127.0.0.1}:9090:9090/tcp
read_only: true
configure:
profiles: [ configure ]
image: docker.io/library/alpine:3.22
entrypoint:
- sh
- -c
- cat >| "/run/config/$$1"
- sh
volumes:
- config:/run/config
network_mode: none
read_only: true
build-assets:
profiles: [ build-assets ]
build:
context: .
target: asset-builder
init: true
command:
- sh
- -ec
- |
deno run \
--cached-only \
--frozen \
--allow-env \
--allow-read \
--allow-write \
--allow-run \
build.ts \
--assets=./assets/ \
--output=/weasyl-assets/
volumes:
- assets:/weasyl-assets
network_mode: none
build-assets-watch:
profiles: [ build-assets-watch ]
build:
context: .
target: asset-builder
init: true
command:
- sh
- -ec
- |
deno run \
--cached-only \
--frozen \
--allow-env \
--allow-read \
--allow-write \
--allow-run \
build.ts \
--assets=./assets/ \
--output=/weasyl-assets/ \
--watch
volumes:
- assets:/weasyl-assets
network_mode: none
develop:
watch:
- action: sync
path: ./assets
target: /weasyl-build/assets
migrate:
profiles: [ migrate ]
image: weasyl
pull_policy: never
build: *weasyl-build
command:
- ash
- -c
- |
i=0
while true; do
if test $$i -ge 8; then
exit 1
fi
if test -n "$$(.venv/bin/alembic current 2> /dev/null)"; then
break
fi
i=$$((i + 1))
printf 'checking if postgres is up in %i seconds...\n' $$i
sleep $$i
done
exec .venv/bin/alembic upgrade heads
environment:
# needed for revision f30dc3b5856a
WEASYL_STORAGE_ROOT: '/fakepath'
ALEMBIC_CONFIG: '/run/config/alembic.ini'
volumes:
- config:/run/config:ro
networks:
- web-postgres
read_only: true
depends_on:
- postgres
tty: true
revision:
profiles: [ revision ]
image: weasyl
pull_policy: never
build: *weasyl-build
entrypoint:
- ash
- -euc
- |
rev_id="$$(python3 -c 'import secrets; print(secrets.token_hex(6))')"
.venv/bin/alembic -c /run/config/alembic.ini revision --rev-id "$$rev_id" "$$@" >&2
tar c libweasyl/alembic/versions/"$$rev_id"_*
- ash
volumes:
- config:/run/config:ro
networks:
- web-postgres
depends_on:
- postgres
tty: true
test:
profiles: [ test ]
build:
context: .
target: test
args:
version: '${WEASYL_VERSION:-}'
environment:
WEASYL_TEST_SQLALCHEMY_URL: 'postgresql+psycopg2://weasyl@postgres/weasyl_test'
volumes:
- config:/run/config:ro
- test-cache:/weasyl/.pytest_cache
- test-coverage:/weasyl/coverage
- type: tmpfs
target: /weasyl/testing
- type: tmpfs
target: /tmp
- type: tmpfs
target: /magick-tmp
networks:
- test-postgres
read_only: true
depends_on:
- postgres
tty: true
flake8:
profiles: [ flake8 ]
build:
context: .
target: flake8
init: true
command:
- sleep
- infinity
network_mode: none