-
Notifications
You must be signed in to change notification settings - Fork 1
/
compose.prod.yml
234 lines (222 loc) · 9.47 KB
/
compose.prod.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
# Production template
# Replace “my-registry/roadiz_skeleton” with your own project registry URL
name: ${APP_NAMESPACE}
services:
db:
image: my-registry/roadiz_skeleton/mariadb:latest
restart: always
cap_add:
- SYS_NICE # CAP_SYS_NICE
networks:
default:
volumes:
- db_data:/var/lib/mysql
environment:
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
MARIADB_DATABASE: ${MARIADB_DATABASE}
MARIADB_USER: ${MARIADB_USER}
MARIADB_PASSWORD: ${MARIADB_PASSWORD}
# Use Redis for Cache, Messaging and Sessions
redis:
image: redis:7-alpine
restart: always
volumes:
- redis:/data
networks:
- default
varnish:
image: my-registry/roadiz_skeleton/varnish:latest
restart: always
tmpfs: /var/lib/varnish/varnishd:exec
# https://github.com/varnish/docker-varnish/issues/53
user: root
depends_on:
- nginx
links:
- nginx:nginx
- app:app
- cron:cron
- worker:worker
environment:
VARNISH_SIZE: ${VARNISH_SIZE}
networks:
- frontproxynet
- default
labels:
- "traefik.enable=true"
- "com.centurylinklabs.watchtower.enable=true"
- "com.centurylinklabs.watchtower.depends-on=/skeleton-nginx-1,/skeleton-worker-1,/skeleton-cron-1"
# Traefik v2 -----------------------------------------------------
- "traefik.http.services.${APP_NAMESPACE}.loadbalancer.server.scheme=http"
- "traefik.http.services.${APP_NAMESPACE}.loadbalancer.server.port=80"
- "traefik.http.services.${APP_NAMESPACE}.loadbalancer.passhostheader=true"
# Enable healthcheck to prevent routing traffic to not-ready service
# - "traefik.http.services.${APP_NAMESPACE}.loadbalancer.healthcheck.path=/health-check"
# - "traefik.http.services.${APP_NAMESPACE}.loadbalancer.healthcheck.interval=10s"
# - "traefik.http.services.${APP_NAMESPACE}.loadbalancer.healthcheck.timeout=3s"
# - "traefik.http.services.${APP_NAMESPACE}.loadbalancer.healthcheck.headers.x-health-check=${APP_HEALTH_CHECK_TOKEN}"
# Listen HTTP
- "traefik.http.routers.${APP_NAMESPACE}.entrypoints=http"
# Always use higher priority for your API app with PathPrefix rule
- "traefik.http.routers.${APP_NAMESPACE}.priority=11"
# Combine Host and PathPrefix to allow API and Frontend to share same domain name
- "traefik.http.routers.${APP_NAMESPACE}.rule=Host(${HOSTNAME}) && PathPrefix(${PATH_PREFIX})"
- "traefik.http.routers.${APP_NAMESPACE}.service=${APP_NAMESPACE}"
# Listen HTTPS
- "traefik.http.routers.${APP_NAMESPACE}_secure.entrypoints=https"
- "traefik.http.routers.${APP_NAMESPACE}_secure.tls=true"
# Always use higher priority for your API app with PathPrefix rule
- "traefik.http.routers.${APP_NAMESPACE}_secure.priority=11"
- "traefik.http.routers.${APP_NAMESPACE}_secure.tls.certresolver=letsencrypt"
# Combine Host and PathPrefix to allow API and Frontend to share same domain name
- "traefik.http.routers.${APP_NAMESPACE}_secure.rule=Host(${HOSTNAME}) && PathPrefix(${PATH_PREFIX})"
- "traefik.http.routers.${APP_NAMESPACE}_secure.service=${APP_NAMESPACE}"
#
# Apply middlewares
#
- "traefik.http.routers.${APP_NAMESPACE}_secure.middlewares=${APP_NAMESPACE}Redirectregex,${APP_NAMESPACE}Sts"
- "traefik.http.routers.${APP_NAMESPACE}.middlewares=${APP_NAMESPACE}Redirectregex,${APP_NAMESPACE}Redirectscheme"
# Add domain redirection (${APP_NAMESPACE} non-www to www redir)
- "traefik.http.middlewares.${APP_NAMESPACE}Redirectregex.redirectregex.regex=${REDIRECT_REGEX}"
- "traefik.http.middlewares.${APP_NAMESPACE}Redirectregex.redirectregex.replacement=${REDIRECT_REPLACEMENT}"
- "traefik.http.middlewares.${APP_NAMESPACE}Redirectregex.redirectregex.permanent=true"
# Add SSL redirection
- "traefik.http.middlewares.${APP_NAMESPACE}Redirectscheme.redirectscheme.scheme=https"
- "traefik.http.middlewares.${APP_NAMESPACE}Redirectscheme.redirectscheme.permanent=true"
# HSTS headers
- "traefik.http.middlewares.${APP_NAMESPACE}Sts.headers.stsincludesubdomains=false"
- "traefik.http.middlewares.${APP_NAMESPACE}Sts.headers.stspreload=true"
- "traefik.http.middlewares.${APP_NAMESPACE}Sts.headers.stsseconds=31536000"
- "traefik.http.middlewares.${APP_NAMESPACE}Sts.headers.isdevelopment=false"
nginx:
image: my-registry/roadiz_skeleton/nginx:latest
restart: always
depends_on:
- app
# Nginx does not resolve `app` hostname correctly
links:
- app:app
networks:
- default
volumes:
#- ./robots.txt:/app/public/robots.txt:ro
- app_file_data:/app/public/files:ro
- app_assets_data:/app/public/assets:ro
labels:
- "com.centurylinklabs.watchtower.enable=true"
- "com.centurylinklabs.watchtower.depends-on=/skeleton-app-1"
app: &app_template
image: my-registry/roadiz_skeleton:latest
restart: always
depends_on:
- db
- redis
#- solr
volumes:
- app_file_data:/app/public/files
- app_assets_data:/app/public/assets
- app_private_file_data:/app/var/files
- app_secret_data:/app/config/secrets
- app_jwt_data:/app/config/jwt
## Use docker-compose env file as .env.local in container or use env vars
- ./.env:/app/.env.local:ro
networks:
- default
environment:
# Can only override env in docker environment
# because these are hardcoded in Docker image definition
APP_ENV: prod
APP_RUNTIME_ENV: prod
APP_DEBUG: 0
labels:
- "com.centurylinklabs.watchtower.enable=true"
- "com.centurylinklabs.watchtower.depends-on=/skeleton-redis-1"
worker:
<<: *app_template
deploy:
# Do not use more than 1 replica if you're using Varnish and need to purge/ban cache
# from your workers. Varnish ACL hostnames won't be resolved correctly.
replicas: 1
entrypoint: [ "php", "/app/bin/console", "messenger:consume", "async", "--time-limit=1800" ]
cron:
<<: *app_template
entrypoint: 'docker-cron-entrypoint'
user: root
#solr:
# image: my-registry/roadiz_skeleton/solr:latest
# volumes:
# - "solr_data:/var/solr"
# command:
# - solr-precreate
# - ${SOLR_CORE_NAME}
# restart: always
# networks:
# - default
# RESTIC incremental backup services
restic:
# Keep the same hostname for all Restic services
hostname: restic-api-backup
image: restic/restic:latest
networks:
- default
environment:
AWS_ACCESS_KEY_ID: ${S3_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY: ${S3_SECRET_KEY}
S3_STORAGE_CLASS: ${S3_STORAGE_CLASS}
RESTIC_REPOSITORY: ${RESTIC_REPOSITORY}
RESTIC_PASSWORD: ${RESTIC_PASSWORD}
volumes:
# If no restore needed, this volume should remain read-only
- app_file_data:/srv/public/files:ro
- app_assets_data:/srv/public/assets:ro
- app_private_file_data:/srv/var/files:ro
- restic_cache:/root/.cache/restic
backup_files:
# Keep the same hostname for all Restic services
extends:
service: restic
command: 'backup -o s3.storage-class=${S3_STORAGE_CLASS} --tag files /srv'
backup_mysql:
# Keep the same hostname for all Restic services
hostname: restic-api-backup
image: ambroisemaupate/restic-database
environment:
AWS_ACCESS_KEY_ID: ${S3_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY: ${S3_SECRET_KEY}
S3_STORAGE_CLASS: ${S3_STORAGE_CLASS}
RESTIC_REPOSITORY: ${RESTIC_REPOSITORY}
RESTIC_PASSWORD: ${RESTIC_PASSWORD}
# MySQL credentials
MYSQL_HOST: db
MYSQL_DATABASE: ${MARIADB_DATABASE}
MYSQL_PASSWORD: ${MARIADB_PASSWORD}
MYSQL_USER: ${MARIADB_USER}
MYSQL_DUMP_FILENAME: ${MYSQL_DUMP_FILENAME}
volumes:
- restic_cache:/root/.cache/restic
depends_on:
- db
command: 'backup -o s3.storage-class=${S3_STORAGE_CLASS} --tag db ${MYSQL_DUMP_FILENAME}'
forget:
extends:
service: restic
# Forget all snapshots older than 7 days and keep 12 monthly snapshots
command: 'forget -o s3.storage-class=${S3_STORAGE_CLASS} --keep-daily 7 --keep-monthly 12 --prune'
volumes:
app_file_data:
app_assets_data:
app_private_file_data:
app_secret_data:
app_jwt_data:
redis:
restic_cache:
db_data:
#solr_data:
networks:
frontproxynet:
external: true
default:
ipam:
driver: default
config:
- subnet: ${DEFAULT_GATEWAY}/24