-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-compose.yaml
More file actions
240 lines (225 loc) · 7.83 KB
/
docker-compose.yaml
File metadata and controls
240 lines (225 loc) · 7.83 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
name: ${COMPOSE_PROJECT_NAME?error}
x-server: &base_server_setup
build:
context: ./backend/
tags:
- mapswipe/mapswipe-backend:${BACKEND_DOCKER_TAG:-latest}
# Used for python debugging.
stdin_open: true
tty: true
restart: unless-stopped
environment: &base_server_environments
APP_RELEASE: ${BACKEND_COMMIT_HASH}
DEBUG: ${BACKEND_DEBUG:-false}
ENABLE_DEBUG_TOOLBAR: ${BACKEND_ENABLE_DEBUG_TOOLBAR:-false}
APP_ENVIRONMENT: ${MAPSWIPE_ENVIRONMENT:-PROD}
ENABLE_STRAWBERRY_GRAPHIQL: ${BACKEND_ENABLE_STRAWBERRY_GRAPHIQL:-false}
# Postgres
POSTGRES_HOST: ${POSTGRES_HOST:-postgres}
POSTGRES_PORT: ${POSTGRES_PORT:-5432}
POSTGRES_DB: ${POSTGRES_DB:-mapswipe}
POSTGRES_USER: ${POSTGRES_USER?error}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD?error}
# Redis (Dragonfly)
CELERY_REDIS_URL: ${BACKEND_CELERY_REDIS_URL:-redis://dragonfly:6379/0}
CACHE_REDIS_URL: ${BACKEND_CACHE_REDIS_URL:-redis://dragonfly:6379/1}
TEST_CACHE_REDIS_URL: ${BACKEND_TEST_CACHE_REDIS_URL:-redis://dragonfly:6379/11}
# Email (TODO: Dummy config)
EMAIL_HOST: ${BACKEND_EMAIL_HOST:-dummy}
EMAIL_PORT: ${BACKEND_EMAIL_PORT:-1025}
EMAIL_USE_TLS: ${BACKEND_EMAIL_USE_TLS:-false}
EMAIL_HOST_USER: ${BACKEND_EMAIL_HOST_USER:-dummy}
EMAIL_HOST_PASSWORD: ${BACKEND_EMAIL_HOST_PASSWORD:-dummy}
DEFAULT_FROM_EMAIL: ${BACKEND_DEFAULT_FROM_EMAIL:-Mapswipe Dev <dev@mapswipe.org>}
# Firebase
FIREBASE_EMULATOR_USE: false
# Storage
MEDIA_ROOT: "/data/media"
STATIC_ROOT: "/data/static"
INTERNAL_ROOT: "/data/internal"
MEDIA_URL: "media/"
STATIC_URL: "static/"
env_file:
- ./env/backend.env
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- ./data/backend/static:/data/static
- ./data/backend/media:/data/media
- ./data/backend/internal:/data/internal
- ipython_data_local:/root/.ipython/profile_default # persist ipython data, including ipython history
depends_on:
- postgres
- dragonfly
profiles:
- core
x-worker: &base_worker_setup
<<: *base_server_setup
environment:
<<: *base_server_environments
APP_TYPE: "WORKER-BEAT"
services:
ofelia:
image: mcuadros/ofelia:0.3.17
command: daemon --docker -f label=com.docker.compose.project=${COMPOSE_PROJECT_NAME?error}
restart: unless-stopped
volumes:
- ./data/ofelia/:/logs
- /var/run/docker.sock:/var/run/docker.sock:ro
labels:
# File log
ofelia.save-folder: /logs
ofelia.save-only-on-error: 0
# Slack
ofelia.slack-webhook: ${OFELIA_SLACK_WEBHOOK?error}
ofelia.slack-only-on-error: 1
# Folder Cleanup
# Disk check (Every hour)
ofelia.job-local.cleanup.schedule: "@hourly"
ofelia.job-local.cleanup.command: sh -c "_ENV=${OFELIA_PROJECT_NAME?error} find /logs/ -type f -mtime +7 -delete -print"
profiles:
- core
# Backend
postgres:
build:
context: ./postgres/
dockerfile: Dockerfile
target: postgis
restart: unless-stopped
ports:
- 127.0.0.1:${POSTGRES_DB_LOCAL_EXPOSE_PORT:-5432}:5432
environment:
# NOTE: This config is only used for db first startup only
POSTGRES_DB: ${POSTGRES_DB:-mapswipe}
POSTGRES_USER: ${POSTGRES_USER?error}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD?error}
# pgBackRest
PGBACKREST_REPO1_TYPE: gcs
PGBACKREST_REPO1_GCS_KEY: /run/secrets/pgbackrest_gc_service_account_key
PGBACKREST_REPO1_GCS_BUCKET: ${PGBACKREST_REPO1_GCS_BUCKET?error}
PGBACKREST_REPO1_PATH: ${PGBACKREST_REPO1_PATH?error}
command: postgres -c archive_mode=on -c archive_command="pgbackrest --stanza=main archive-push %p"
volumes:
- ./data/postgres:/var/lib/postgresql/data
# pgBackrest
- ./data/pgbackrest/log/:/var/log/pgbackrest/
- ./postgres/pgbackrest/pgbackrest.conf:/etc/pgbackrest/pgbackrest.conf:ro
post_start:
- command: /pgbackrest-setup.sh
user: root
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
interval: 10s
timeout: 5s
retries: 5
labels:
# NOTE: the cron format starts with seconds, instead of minutes. https://pkg.go.dev/github.com/robfig/cron?utm_source=godoc
ofelia.enabled: "true"
# XXX: Make sure to align this with the retention policies ./postgres/pgbackrest/pgbackrest.conf
# Full backup every month (At 10:00 on day-of-month 1)
ofelia.job-exec.full.schedule: "0 0 10 1 * *"
ofelia.job-exec.full.command: sh -c "_ENV=${OFELIA_PROJECT_NAME?error} pgbackrest --stanza=main backup --type=full"
ofelia.job-exec.full.user: "postgres"
ofelia.job-exec.full.no-overlap: 1
# Differential backup every week (At 02:30 on Monday)
ofelia.job-exec.diff.schedule: "0 30 2 * * 1"
ofelia.job-exec.diff.command: sh -c "_ENV=${OFELIA_PROJECT_NAME?error} pgbackrest --stanza=main backup --type=diff"
ofelia.job-exec.diff.user: "postgres"
ofelia.job-exec.diff.no-overlap: 1
# Expire every day (At 01:30)
ofelia.job-exec.expire.schedule: "0 30 01 * * *"
ofelia.job-exec.expire.command: sh -c "_ENV=${OFELIA_PROJECT_NAME?error} pgbackrest --stanza=main expire"
ofelia.job-exec.expire.user: "postgres"
ofelia.job-exec.expire.no-overlap: 1
secrets:
- pgbackrest_gc_service_account_key
profiles:
- core
# Redis alternative
dragonfly:
image: docker.dragonflydb.io/dragonflydb/dragonfly:v1.33.1
restart: unless-stopped
ulimits:
memlock: -1
volumes:
- dragonflydata:/data
profiles:
- core
web:
<<: *base_server_setup
environment:
<<: *base_server_environments
APP_TYPE: "WEB"
command: bash -c "/code/misc/prod/run_web.sh"
worker-beat:
<<: *base_worker_setup
command: bash -c "/code/misc/prod/run_worker_beat.sh"
worker:
<<: *base_worker_setup
command: bash -c "/code/misc/prod/run_worker.sh"
# Manager Dashboard
manager-dashboard:
build:
context: manager-dashboard/
target: builder
tty: true
environment:
APP_ENVIRONMENT: ${MAPSWIPE_ENVIRONMENT:-PROD}
APP_COMMIT_HASH: ${MANAGER_DASHBOARD_COMMIT_HASH}
command: sh -c 'pnpm generate:type && pnpm build'
volumes:
- ./data/web-builds/manager-dashboard:/code/build
env_file:
- ./env/manager-dashboard.env
profiles:
- web-builds
# Community Dashboard
community-dashboard:
build:
context: community-dashboard/
target: builder
tty: true
environment:
APP_ENVIRONMENT: ${MAPSWIPE_ENVIRONMENT:-PROD}
APP_COMMIT_HASH: ${COMMUNITY_DASHBOARD_COMMIT_HASH}
command: sh -c 'pnpm generate:type && pnpm build'
volumes:
- ./data/web-builds/community-dashboard:/code/build
env_file:
- ./env/community-dashboard.env
profiles:
- web-builds
# TODO: firebase deploy
caddy:
image: caddy:2.10.2
restart: unless-stopped
volumes:
# Caddy config
- ./caddy/Caddyfile:/etc/caddy/Caddyfile:ro
- ./data/caddy/data/:/data
- ./data/caddy/config/:/config
# Static files
# -- Backend
- ./data/backend/static:/assets/backend/static:ro
- ./data/backend/media:/assets/backend/media:ro
# -- Dashboards
- ./data/web-builds/manager-dashboard:/assets/manager-dashboard:ro
- ./data/web-builds/community-dashboard:/assets/community-dashboard:ro
environment:
CADDY_EMAIL: ${CADDY_EMAIL?error}
CADDY_HOST_BACKEND: ${CADDY_HOST_BACKEND?error}
CADDY_HOST_MANAGER_DASHBOARD: ${CADDY_HOST_MANAGER_DASHBOARD?error}
CADDY_HOST_COMMUNITY_DASHBOARD: ${CADDY_HOST_COMMUNITY_DASHBOARD?error}
ports:
- 80:80
- 443:443
depends_on:
- web
profiles:
- core
volumes:
dragonflydata:
ipython_data_local:
secrets:
pgbackrest_gc_service_account_key:
file: secrets/pgbackrest_gc_service_account_key.json