-
Notifications
You must be signed in to change notification settings - Fork 1
/
stack-prod.yml
197 lines (165 loc) · 6.71 KB
/
stack-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
version: '3.8'
services:
# Wordpress
srv:
image: <%= $(bin/get image --tag) %>
deploy:
mode: global
# On a single-node swarm, allow this service on the manager node
# On a multi-node swarm, only allow this service to worker nodes
<% if [ "$(bin/get nodes|wc -w)" != "1" ]; then %>
placement:
constraints: [node.role == worker]
<% fi %>
resources:
limits:
cpus: '1.5'
memory: 800M
update_config:
order: start-first
failure_action: rollback
parallelism: 1
delay: 5s
rollback_config:
order: start-first
failure_action: pause
parallelism: 1
labels:
traefik.enable: "true"
traefik.docker.network: "proxy"
<% ROUTER="$(bin/get app)" -%>
<% SERVICE="$(bin/get app)" -%>
<% MIDDLE="$(bin/get app)-basicauth" %>
<% CSP="$(bin/get app)-csp" %>
# Password-protected staging production host
traefik.http.routers.<%= $ROUTER -%>.entrypoints: "websecure"
traefik.http.routers.<%= $ROUTER -%>.rule: "Host(`<%= $(bin/get host) -%>`)"
traefik.http.routers.<%= $ROUTER -%>.tls.certresolver: "resolver-dns"
traefik.http.routers.<%= $ROUTER -%>.tls.domains[0].main: "<%= $(bin/get swarm) %>"
traefik.http.routers.<%= $ROUTER -%>.tls.domains[0].sans: "*.<%= $(bin/get swarm) %>"
traefik.http.routers.<%= $ROUTER -%>.middlewares: "<%= $MIDDLE %>@docker"
traefik.http.routers.<%= $ROUTER -%>.middlewares: "<%= $MIDDLE %>@docker,<%= $CSP %>@docker"
traefik.http.services.<%= $SERVICE -%>.loadbalancer.server.port: "443"
traefik.http.services.<%= $SERVICE -%>.loadbalancer.server.scheme: "https"
# traefik.http.services.<%= $SERVICE -%>.loadbalancer.sticky.cookie: "true"
# traefik.http.services.<%= $SERVICE -%>.loadbalancer.sticky.cookie.name: "<%= $SERVICE -%>_sticky"
traefik.http.middlewares.<%= $MIDDLE -%>.basicauth.users: "<%= $(bin/get basic_auth $(bin/get host_user) $(bin/get host_password)) %>"
traefik.http.middlewares.<%= $MIDDLE -%>.basicauth.realm: "<%= $(bin/get app) %>"
traefik.http.middlewares.<%= $CSP -%>.headers.customResponseHeaders.Content-Security-Policy: "frame-ancestors 'self'"
# Set these when ready to launch
# MAIN_DOMAIN="example.com"
# SANS_DOMAIN="www.example.com"
<% MAIN_DOMAIN="" -%>
<% SANS_DOMAIN="" -%>
<% if [ ! -z "$MAIN_DOMAIN" ]; then -%>
<% ROUTER="$(echo $MAIN_DOMAIN | tr . -)" -%>
<% MIDDLE="$(echo $MAIN_DOMAIN | tr . -)-redirect" %>
# Public domain (with www redirection) for <%= $MAIN_DOMAIN %>
traefik.http.routers.<%= $ROUTER -%>.entrypoints: "websecure"
traefik.http.routers.<%= $ROUTER -%>.rule: "Host(<%= $(bin/get csv $MAIN_DOMAIN $SANS_DOMAIN) %>)"
traefik.http.routers.<%= $ROUTER -%>.tls.certresolver: "resolver-tls"
traefik.http.routers.<%= $ROUTER -%>.tls.domains[0].main: "<%= $MAIN_DOMAIN %>"
traefik.http.routers.<%= $ROUTER -%>.tls.domains[0].sans: "<%= $SANS_DOMAIN %>"
traefik.http.routers.<%= $ROUTER -%>.middlewares: "<%= $MIDDLE %>@docker"
traefik.http.routers.<%= $ROUTER -%>.service: "<%= $SERVICE %>"
traefik.http.middlewares.<%= $MIDDLE -%>.redirectregex.regex: "^https://<%= $SANS_DOMAIN %>/(.*)"
traefik.http.middlewares.<%= $MIDDLE -%>.redirectregex.replacement: "https://<%= $MAIN_DOMAIN %>/$${1}"
traefik.http.middlewares.<%= $MIDDLE -%>.redirectregex.permanent: "true"
# Domain redirections
# for DOMAIN in "oldsite.com" "retiredsite.com"; do
<% for DOMAIN in ""; do -%>
<% if [ ! -z "$DOMAIN" ]; then -%>
<% ROUTER="$(echo $MAIN_DOMAIN.$DOMAIN | tr . -)" -%>
<% MIDDLE="$(echo $MAIN_DOMAIN.$DOMAIN | tr . -)-redirect" %>
# Redirect <%= $DOMAIN %> to <%= $MAIN_DOMAIN %>
traefik.http.routers.<%= $ROUTER -%>.entrypoints: "websecure"
traefik.http.routers.<%= $ROUTER -%>.rule: "Host(`<%= $DOMAIN -%>`,`www.<%= $DOMAIN -%>`)"
traefik.http.routers.<%= $ROUTER -%>.tls.certresolver: "resolver-tls"
traefik.http.routers.<%= $ROUTER -%>.tls.domains[0].main: "<%= $DOMAIN -%>"
traefik.http.routers.<%= $ROUTER -%>.tls.domains[0].sans: "www.<%= $DOMAIN -%>"
traefik.http.routers.<%= $ROUTER -%>.middlewares: "<%= $MIDDLE %>@docker"
traefik.http.routers.<%= $ROUTER -%>.service: "<%= $SERVICE %>"
traefik.http.middlewares.<%= $MIDDLE -%>.redirectregex.regex: "^https://(<%= $DOMAIN %>|www.<%= $DOMAIN %>)/(.*)"
traefik.http.middlewares.<%= $MIDDLE -%>.redirectregex.replacement: "https://<%= $MAIN_DOMAIN %>/$${2}"
traefik.http.middlewares.<%= $MIDDLE -%>.redirectregex.permanent: "true"
<% fi %>
<% done %>
<% fi %>
environment:
WP_ENV: "production"
HOST: "<%= $(bin/get host) %>"
DB_HOST: "db:3306"
DB_NAME: "<%= $(bin/get db_name) %>"
DB_USER: "<%= $(bin/get db_user) %>"
DB_PASSWORD: "<%= $(bin/get db_password) %>"
SMTP_HOST: "<%= $(bin/get SMTP_HOST) %>"
SMTP_PORT: "<%= $(bin/get SMTP_PORT) %>"
SMTP_USER: "<%= $(bin/get SMTP_USER) %>"
SMTP_PASSWORD: "<%= $(bin/get SMTP_PASSWORD) %>"
volumes:
- <%= $(bin/get uploads) %>:/srv/web/content/uploads
- cache:/srv/web/content/cache
- settings:/srv/web/content/settings
- <%= $(bin/get dump) %>:/srv/dump.sql
networks:
- backend
- proxy
- db
# Cron
cron:
image: nonfiction/wordpress-cron:v3
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
resources:
limits:
cpus: '0.5'
memory: 50M
environment:
HOST: "<%= $(bin/get host) %>"
HOST_USER: "<%= $(bin/get host_user) %>"
HOST_PASSWORD: "<%= $(bin/get host_password) %>"
DB_HOST: "db"
DB_PORT: "3306"
DB_USER: "<%= $(bin/get db_user) %>"
DB_PASSWORD: "<%= $(bin/get db_password) %>"
DB_NAME: "<%= $(bin/get db_name) %>"
volumes:
- <%= $(bin/get dump) %>:/cron/dump.sql
networks:
- proxy
- db
# Object Cache
redis:
image: redis:alpine
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.role == manager]
resources:
limits:
cpus: '0.50'
memory: 100M
command: >
redis-server
--databases 1
--maxmemory 50mb
--maxmemory-policy allkeys-lru
networks:
- backend
networks:
backend:
proxy:
name: proxy
driver: overlay
external: true
db:
name: db
driver: overlay
external: true
volumes:
cache:
settings: