-
Notifications
You must be signed in to change notification settings - Fork 3
/
user-data.yml.erb
366 lines (339 loc) · 11.5 KB
/
user-data.yml.erb
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
#cloud-config
coreos:
update:
group: beta
reboot-strategy: off
etcd2:
discovery:
advertise-client-urls: "http://$private_ipv4:2379"
initial-advertise-peer-urls: "http://$private_ipv4:2380"
listen-client-urls: "http://0.0.0.0:2379"
listen-peer-urls: "http://$private_ipv4:2380"
units:
<% if instance_type == :manager %>
- name: sshd.socket
command: restart
runtime: true
content: |
[Socket]
ListenStream=2222
FreeBind=true
Accept=yes
<% end %>
- name: etcd2.service
command: start
- name: docker.service
drop-ins:
- name: 10-cluster-config.conf
content: |
[Service]
Environment="DOCKER_OPTS=--cluster-store=etcd://0.0.0.0:2379 --cluster-advertise=eth0:2375"
- name: settimezone.service
command: start
content: |
[Unit]
Description=Set the timezone
[Service]
ExecStart=/usr/bin/timedatectl set-timezone <%= ENV["TIMEZONE"] %>
RemainAfterExit=yes
Type=oneshot
- name: docker-tcp.socket
command: start
enable: true
content: |
[Unit]
Description=Docker Socket for the API
[Socket]
ListenStream=2375
Service=docker.service
BindIPv6Only=both
[Install]
WantedBy=sockets.target
- name: install-docker-compose.service
command: start
content: |
[Unit]
Description=Install Docker Compose
[Service]
ExecStartPre=/usr/bin/mkdir -p /opt/bin
ExecStart=/usr/bin/wget https://github.com/docker/compose/releases/download/<%= ENV["DOCKER_COMPOSE_VERSION"] %>/docker-compose-Linux-x86_64 -O /opt/bin/docker-compose
ExecStartPost=/usr/bin/chown root:root /opt/bin/docker-compose
ExecStartPost=/usr/bin/chmod +x /opt/bin/docker-compose
RemainAfterExit=yes
Type=oneshot
- name: docker-cleanup.service
command: start
content: |
[Unit]
Description=Clean up old containers and images
[Service]
ExecStart=/home/core/cleanup.sh
Type=oneshot
- name: docker-cleanup.timer
command: start
content: |
[Unit]
Description=Run clean up script hourly
[Timer]
OnCalendar=hourly
- name: swarm-manager.service
command: start
content: |
[Unit]
Description=swarm-manager Container
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=always
User=core
ExecStartPre=-/usr/bin/docker stop swarm-manager
ExecStartPre=-/usr/bin/docker rm swarm-manager
ExecStartPre=-/usr/bin/docker pull swarm:<%= ENV["DOCKER_SWARM_VERSION"] %>
ExecStart=/usr/bin/docker run \
-p 2377:2377 \
--name=swarm-manager \
swarm:<%= ENV["DOCKER_SWARM_VERSION"] %> \
manage -H :2377 --replication --addr=$private_ipv4:2377 etcd://$private_ipv4:2379/swarm
ExecStop=/usr/bin/docker stop swarm-manager
[Install]
WantedBy=multi-user.target
<% if instance_type == :manager %>
- name: paus-frontend.service
command: start
enable: true
content: |
[Unit]
Description=Paus frontend
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=always
User=core
ExecStartPre=-/usr/bin/docker kill paus-frontend
ExecStartPre=-/usr/bin/docker rm paus-frontend
ExecStartPre=/usr/bin/docker pull quay.io/dtan4/paus-frontend:latest
ExecStart=/usr/bin/docker run \
--name paus-frontend \
-e PAUS_BASE_DOMAIN=<%= ENV["PAUS_BASE_DOMAIN"] %> \
-e PAUS_ETCD_ENDPOINT=http://$private_ipv4:2379 \
-e PAUS_GITHUB_CLIENT_ID=<%= ENV["PAUS_GITHUB_CLIENT_ID"] %> \
-e PAUS_GITHUB_CLIENT_SECRET=<%= ENV["PAUS_GITHUB_CLIENT_SECRET"] %> \
-e PAUS_SECRET_KEY_BASE=<%= ENV["PAUS_SECRET_KEY_BASE"] %> \
-e PAUS_URI_SCHEME=<%= ENV["PAUS_URI_SCHEME"] %> \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /home/core/docker-compose.yml:/app/docker-compose.yml:ro \
quay.io/dtan4/paus-frontend:latest
ExecStop=/usr/bin/docker stop paus-frontend
[Install]
WantedBy=multi-user.target
- name: vulcand.service
command: start
enable: true
content: |
[Unit]
Description=Vulcand
After=paus-frontend.service
Requires=paus-frontend.service
[Service]
TimeoutStartSec=0
Restart=always
User=core
ExecStartPre=-/usr/bin/docker kill vulcand
ExecStartPre=-/usr/bin/docker rm vulcand
ExecStartPre=/usr/bin/docker pull mailgun/vulcand:v0.8.0-beta.3
ExecStart=/usr/bin/docker run \
--name vulcand \
--link paus-frontend:paus-frontend \
-p 80:80 \
-p 443:443 \
-p 8182:8182 \
-p 8181:8181 \
mailgun/vulcand:v0.8.0-beta.3 \
/go/bin/vulcand -apiInterface=0.0.0.0 -interface=0.0.0.0 -etcd=http://$private_ipv4:2379 -port=80 -apiPort=8182
ExecStop=/usr/bin/docker stop vulcand
[Install]
WantedBy=multi-user.target
- name: add-route-to-paus-frontend.service
command: start
content: |
[Unit]
Description=Add route to paus-frontend
After=etcd2.service vulcand.service paus-frontend.service
Requires=etcd2.service vulcand.service paus-frontend.service
[Service]
ExecStart=/home/core/add-route-to-paus-frontend.sh
RemainAfterExit=yes
Type=oneshot
- name: paus-gitreceive.service
command: start
enable: true
content: |
[Unit]
Description=Paus gitreceive
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=always
User=core
ExecStartPre=-/usr/bin/docker kill paus-gitreceive
ExecStartPre=-/usr/bin/docker rm paus-gitreceive
ExecStartPre=/usr/bin/docker pull quay.io/dtan4/paus-gitreceive:latest
ExecStart=/usr/bin/docker run \
--name paus-gitreceive \
-p 22:22 \
-e PAUS_BASE_DOMAIN=<%= ENV["PAUS_BASE_DOMAIN"] %> \
-e PAUS_DOCKER_CONFIG_BASE64=<%= ENV["PAUS_DOCKER_CONFIG_BASE64"] %> \
-e PAUS_DOCKER_HOST=tcp://$private_ipv4:2377 \
-e PAUS_ETCD_ENDPOINT=http://$private_ipv4:2379 \
-e PAUS_MAX_APP_DEPLOY=<%= ENV["PAUS_MAX_APP_DEPLOY"] %> \
-e PAUS_REPOSITORY_DIR=/repos \
-e PAUS_URI_SCHEME=<%= ENV["PAUS_URI_SCHEME"] %> \
-v /home/core/repos:/repos \
-v /home/core/git-ssh:/home/git/.ssh \
quay.io/dtan4/paus-gitreceive:latest
ExecStop=/usr/bin/docker stop paus-gitreceive
[Install]
WantedBy=multi-user.target
- name: hchecks.service
command: start
enable: true
content: |
[Unit]
Description=health-check server
After=paus-gitreceive.service
Requires=paus-gitreceive.service
[Service]
TimeoutStartSec=0
Restart=always
User=core
ExecStartPre=-/usr/bin/docker kill hchecks
ExecStartPre=-/usr/bin/docker rm hchecks
ExecStartPre=/usr/bin/docker pull quay.io/dtan4/hchecks:latest
ExecStart=/usr/bin/docker run \
--name hchecks \
-p 8080:8080 \
quay.io/dtan4/hchecks:latest
ExecStop=/usr/bin/docker stop hchecks
[Install]
WantedBy=multi-user.target
<% else %>
- name: swarm-agent.service
command: start
content: |
[Unit]
Description=swarm-agent Container
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=always
User=core
ExecStartPre=-/usr/bin/docker stop swarm-agent
ExecStartPre=-/usr/bin/docker rm swarm-agent
ExecStartPre=-/usr/bin/docker pull swarm:<%= ENV["DOCKER_SWARM_VERSION"] %>
ExecStart=/usr/bin/docker run \
--name=swarm-agent \
swarm:<%= ENV["DOCKER_SWARM_VERSION"] %> \
join --addr=$private_ipv4:2375 etcd://$private_ipv4:2379/swarm
ExecStop=/usr/bin/docker stop swarm-agent
[Install]
WantedBy=multi-user.target
<% end %>
<% if datadog_enabled %>
- name: dd-agent.service
command: start
content: |
[Unit]
Description=Datadog Agent
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker stop dd-agent
ExecStartPre=-/usr/bin/docker rm dd-agent
ExecStartPre=-/usr/bin/docker pull datadog/docker-dd-agent:latest
ExecStart=/usr/bin/docker run \
--privileged \
--name dd-agent \
-h `hostname` \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /proc/:/host/proc/:ro \
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
-v /opt/dd-agent-conf.d:/conf.d:ro \
-e API_KEY=<%= ENV["DATADOG_API_KEY"] %> \
-e TAGS="paus" \
datadog/docker-dd-agent:latest
ExecStop=/usr/bin/docker stop dd-agent
[Install]
WantedBy=multi-user.target
<% end %>
write_files:
- path: /etc/ssh/sshd_config
permissions: "0600"
owner: root:root
content: |
# Use most defaults for sshd configuration.
UsePrivilegeSeparation sandbox
Subsystem sftp internal-sftp
PermitRootLogin no
PasswordAuthentication no
ChallengeResponseAuthentication no
- path: /etc/ntp.conf
content: |
# Common pool
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server 3.pool.ntp.org
# - Allow only time queries, at a limited rate.
# - Allow all local queries (IPv4, IPv6)
restrict default nomodify nopeer noquery limited kod
restrict 127.0.0.1
restrict [::1]
- path: /home/core/.docker/config.json
permissions: "0644"
owner: core:core
content: |
{
"auths": {
"quay.io": {
"auth": "<%= ENV["DOCKER_QUAY_AUTH"]%>",
"email": ""
}
}
}
- path: /home/core/cleanup.sh
permissions: "0755"
owner: core:core
content: |
#!/bin/bash
docker -H tcp://localhost:2377 rm $(docker -H tcp://localhost:2377 ps -a -q) || true
docker -H tcp://localhost:2377 rmi $(docker -H tcp://localhost:2377 images -f "dangling=true" -q) || true
<% if instance_type == :manager %>
- path: /home/core/add-route-to-paus-frontend.sh
permissions: "0755"
owner: core:core
content: |
#!/bin/bash
etcdctl set /vulcand/backends/paus-frontend/backend '{"Type": "http"}' > /dev/null
etcdctl set /vulcand/backends/paus-frontend/servers/paus-frontend '{"URL": "http://paus-frontend:8080"}' > /dev/null
etcdctl set /vulcand/frontends/paus-frontend/frontend '{"Type": "http", "BackendId": "paus-frontend", "Route": "Host(`<%= ENV["PAUS_BASE_DOMAIN"] %>`) && PathRegexp(`/`)", "Settings": {"TrustForwardHeader": true}}'
- path: /home/core/docker-compose.yml
content: |
gitreceive-upload-key:
image: quay.io/dtan4/paus-gitreceive:latest
volumes_from:
- paus-gitreceive
entrypoint: /usr/local/bin/upload-key
<% end %>
<% if datadog_enabled %>
- path: /opt/dd-agent-conf.d/etcd.yaml
content: |
init_config:
instances:
- url: "http://$private_ipv4:2379"
timeout: 5
<% end %>