-
Notifications
You must be signed in to change notification settings - Fork 4
/
bamboo.json
409 lines (382 loc) · 15.2 KB
/
bamboo.json
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Launches a Marathon LB stack",
"Parameters" : {
"InstanceType" : {
"Description" : "EC2 instance type",
"Type" : "String",
"Default" : "t2.micro",
"AllowedValues" : [
"t2.micro", "t2.small", "t2.medium", "m3.medium", "m3.large", "m3.xlarge", "m3.2xlarge",
"c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge", "c4.8xlarge", "c3.large", "c3.xlarge", "c3.2xlarge", "c3.4xlarge", "c3.8xlarge",
"r3.large", "r3.xlarge", "r3.2xlarge", "r3.4xlarge", "r3.8xlarge",
"i2.xlarge", "i2.2xlarge", "i2.4xlarge", "i2.8xlarge", "hs1.8xlarge",
"g2.2xlarge"
],
"ConstraintDescription" : "must be a valid, HVM-compatible EC2 instance type."
},
"KeyName" : {
"Description" : "Existing EC2 KeyPair to be associated with all cluster instances for SSH access. For default AMIs, log in as the 'ubuntu' user.",
"Type" : "String"
},
"ClusterId" : {
"Description" : "Cluster identifier. Change this if you want to run multiple Bamboo clusters on the same ZK cluster.",
"Type": "String",
"Default": "mesos"
},
"MarathonUrl" : {
"Description" : "Marathon server URL (http[s]://<host>:<port>).",
"Type": "String"
},
"ExhibitorDiscoveryUrl" : {
"Description" : "Exhibitor URL that returns active ZooKeeper nodes ('getCluster') (e.g., http://<exhibitor_node>/exhibitor/v1/cluster/list)",
"Type" : "String"
},
"ZkClientSecurityGroup" : {
"Description" : "Security group ID for ZK clients (should grant access to ZK nodes)",
"Type" : "String"
},
"MarathonServerSecurityGroup" : {
"Description" : "Security group ID for Marathon servers (this will be granted access to Bamboo's callback URL for Marathon events).",
"Type" : "String"
},
"BambooDockerImage" : {
"Description" : "The bamboo Docker image (format: 'registry:port/repository:version')",
"Type" : "String",
"Default" : "mbabineau/bamboo:0.2.9"
},
"InstanceCount" : {
"Description" : "Number of bamboo nodes to launch",
"Type" : "Number",
"Default" : "1"
},
"Subnets" : {
"Description" : "List of VPC subnet IDs for the cluster. Note: must match the passed AvailabilityZones.",
"Type" : "CommaDelimitedList"
},
"VpcId" : {
"Description" : "VPC associated with the provided subnets",
"Type" : "String"
},
"AdminSecurityGroup" : {
"Description" : "Existing security group that should be granted administrative access (e.g., 'sg-123456')",
"Type" : "String"
},
"AvailabilityZones": {
"Description" : "(Optional) If passed, only launch nodes in these AZs (e.g., 'us-east-1a,us-east-1b'). Note: these must match the passed Subnets.",
"Type" : "CommaDelimitedList",
"Default" : ""
}
},
"Conditions" : {
"UseAllAvailabilityZones" : {"Fn::Equals" : [{ "Fn::Join" : ["", {"Ref" : "AvailabilityZones"} ]}, ""]}
},
"Mappings" : {
"RegionMap" : {
"us-east-1" : {
"AMI" : "ami-86fabdee"
},
"us-west-1" : {
"AMI" : "ami-bc4951f9"
},
"us-west-2" : {
"AMI" : "ami-49411979"
},
"eu-west-1" : {
"AMI" : "ami-1566ea62"
},
"ap-southeast-1" : {
"AMI" : "ami-787b512a"
},
"ap-southeast-2" : {
"AMI" : "ami-c35c28f9"
},
"ap-northeast-1" : {
"AMI" : "ami-7a98817b"
},
"sa-east-1" : {
"AMI" : "ami-bd6ad6a0"
}
}
},
"Resources" : {
"IAMUser" : {
"Type" : "AWS::IAM::User",
"Properties" : {
"Policies" : [{
"PolicyName" : "IAMAccess",
"PolicyDocument" : {
"Statement" : [{
"Effect" : "Allow",
"NotAction" : "iam:*",
"Resource" : "*"
}]
}
}]
}
},
"HostKeys" : {
"Type" : "AWS::IAM::AccessKey",
"Properties" : {
"UserName" : { "Ref" : "IAMUser" }
}
},
"ServerGroup" : {
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"UpdatePolicy" : {
"AutoScalingRollingUpdate" : {
"MaxBatchSize" : "1",
"MinInstancesInService" : "1",
"PauseTime" : "PT2M"
}
},
"Properties" : {
"AvailabilityZones" : {
"Fn::If" : [
"UseAllAvailabilityZones",
{ "Fn::GetAZs": "" },
{"Ref" : "AvailabilityZones"}
]
},
"LaunchConfigurationName" : { "Ref" : "LaunchConfig" },
"MinSize" : { "Ref" : "InstanceCount" },
"MaxSize" : 20,
"DesiredCapacity" : { "Ref" : "InstanceCount" },
"LoadBalancerNames" : [ { "Ref" : "ElasticLoadBalancer" } ],
"VPCZoneIdentifier" : { "Ref" : "Subnets" }
}
},
"LaunchConfig" : {
"Type" : "AWS::AutoScaling::LaunchConfiguration",
"Metadata" : {
"AWS::CloudFormation::Init" : {
"config": {
"files" : {
"/usr/local/bin/zk-list-nodes" : {
"content" : { "Fn::Join" : ["", [
"#!/bin/bash -e\n",
"curl -s {{zk_discovery_url}} | python -c '",
"import sys, json;",
"j=json.load(sys.stdin);",
"servers=[\":\".join([s, str(j[\"port\"])]) for s in j[\"servers\"]];",
"print \",\".join(servers)'"
]]},
"context" : {
"zk_discovery_url" : { "Ref" : "ExhibitorDiscoveryUrl" }
},
"mode" : "000755",
"owner" : "root",
"group" : "root"
},
"/usr/local/bin/configure-bamboo" : {
"content" : { "Fn::Join" : ["\n", [
"#!/bin/bash -e",
"echo \"`/usr/local/bin/zk-list-nodes`\" > /etc/sv/bamboo/env/BAMBOO_ZK_HOST",
"echo \"/{{cluster_id}}_bamboo\" > /etc/sv/bamboo/env/BAMBOO_ZK_PATH",
"echo \"http://`ec2metadata --public-hostname`:8000\" > /etc/sv/bamboo/env/BAMBOO_ENDPOINT",
"echo \"{{marathon_url}}\" | sed 's:/$::' > /etc/sv/bamboo/env/MARATHON_ENDPOINT",
""
]]},
"context" : {
"cluster_id": { "Ref": "ClusterId" },
"marathon_url": { "Ref": "MarathonUrl" }
},
"mode" : "000755",
"owner" : "root",
"group" : "root"
},
"/opt/bamboo/haproxy_template.cfg" : {
"content" : { "Fn::Join" : ["\n", [
"global",
" log /dev/log local0",
" log /dev/log local1 notice",
" chroot /var/lib/haproxy",
" stats socket /run/haproxy/admin.sock mode 660 level admin",
" stats timeout 30s",
" user haproxy",
" group haproxy",
" daemon",
"",
" # Default SSL material locations",
" ca-base /etc/ssl/certs",
" crt-base /etc/ssl/private",
"",
" # Default ciphers to use on SSL-enabled listening sockets.",
" # For more information, see ciphers(1SSL).",
" # ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL",
"",
"defaults",
" log global",
" mode http",
" option httplog",
" option dontlognull",
" option redispatch",
" timeout connect 5000",
" timeout client 50000",
" timeout server 50000",
"",
" errorfile 400 /etc/haproxy/errors/400.http",
" errorfile 403 /etc/haproxy/errors/403.http",
" errorfile 408 /etc/haproxy/errors/408.http",
" errorfile 500 /etc/haproxy/errors/500.http",
" errorfile 502 /etc/haproxy/errors/502.http",
" errorfile 503 /etc/haproxy/errors/503.http",
" errorfile 504 /etc/haproxy/errors/504.http",
"",
"listen stats :1936",
" mode http",
" stats enable",
" stats hide-version",
" stats uri /",
" # stats realm HAProxy\\ Stats",
" # stats auth admin:bamboo",
"",
"# Template Customization",
"frontend http-in",
" bind *:80",
" {{ $services := .Services }}",
" {{ range $index, $app := .Apps }} {{ if hasKey $services $app.Id }} {{ $service := getService $services $app.Id }}",
" acl {{ $app.EscapedId }}-aclrule {{ $service.Acl}}",
" use_backend {{ $app.EscapedId }}-cluster if {{ $app.EscapedId }}-aclrule",
" {{ else }}",
"",
" # This is the default proxy criteria",
" acl {{ $app.EscapedId }}-aclrule path_beg -i {{ $app.Id }}",
" use_backend {{ $app.EscapedId }}-cluster if {{ $app.EscapedId }}-aclrule",
" {{ end }} {{ end }}",
"",
"{{ range $index, $app := .Apps }}",
"backend {{ $app.EscapedId }}-cluster",
" {{ if $app.HealthCheckPath }}",
" option httpchk GET {{ $app.HealthCheckPath }}",
" {{ end }}",
" balance leastconn",
" option httpclose",
" option forwardfor",
" {{ range $page, $task := .Tasks }}",
" server {{ $app.EscapedId}}-{{ $task.Host }}-{{ $task.Port }} {{ $task.Host }}:{{ $task.Port }} {{ if $app.HealthCheckPath }} check inter 30000 {{ end }} {{ end }}",
"{{ end }}",
""
]]},
"mode" : "000644",
"owner" : "root",
"group" : "root"
},
"/etc/cron.d/bamboo": {
"content" : { "Fn::Join" : ["\n", [
"# Refresh bamboo config every minute, but don't restart",
"* * * * * root /usr/local/bin/configure-bamboo",
""
]]},
"mode" : "000644",
"owner" : "root",
"group" : "root"
}
}
}
}
},
"Properties" : {
"KeyName" : { "Ref" : "KeyName" },
"ImageId" : { "Fn::FindInMap" : [ "RegionMap", { "Ref" : "AWS::Region" }, "AMI"] },
"SecurityGroups" : [ { "Ref" : "ServerSecurityGroup" }, { "Ref" : "AdminSecurityGroup" }, { "Ref" : "ZkClientSecurityGroup" } ],
"AssociatePublicIpAddress": "true",
"InstanceType" : { "Ref" : "InstanceType" },
"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
"#!/bin/bash -ex\n",
"# Helper function\n",
"function error_exit\n",
"{\n",
" cfn-signal -e 1 -r \"$1\" '", { "Ref" : "WaitHandle" }, "'\n",
" exit 1\n",
"}\n",
"cfn-init -s ", { "Ref" : "AWS::StackName" }, " -r LaunchConfig ",
" --access-key ", { "Ref" : "HostKeys" },
" --secret-key ", { "Fn::GetAtt": ["HostKeys", "SecretAccessKey"] },
" --region ", { "Ref" : "AWS::Region" }, " || error_exit 'Failed to run cfn-init'\n",
"# Set up and run bamboo\n",
"docker pull ", { "Ref" : "BambooDockerImage" }, "\n",
"runit-service create bamboo 'docker -r=false run",
" -v /opt/bamboo:/bamboo",
" -p 8000:8000",
" -p 1936:1936",
" -p 80:80",
" -e BAMBOO_ZK_HOST=`cat /etc/sv/bamboo/env/BAMBOO_ZK_HOST`",
" -e BAMBOO_ZK_PATH=`cat /etc/sv/bamboo/env/BAMBOO_ZK_PATH`",
" -e BAMBOO_ENDPOINT=`cat /etc/sv/bamboo/env/BAMBOO_ENDPOINT`",
" -e MARATHON_ENDPOINT=`cat /etc/sv/bamboo/env/MARATHON_ENDPOINT`",
" -e HAPROXY_TEMPLATE_PATH=/bamboo/haproxy_template.cfg",
" ", { "Ref" : "BambooDockerImage" },
" -bind=:8000'\n",
"runit-service enable bamboo\n",
"# All is well so signal success\n",
"cfn-signal -e 0 -r \"Stack setup complete\" '", { "Ref" : "WaitHandle" }, "'\n",
"#EOF"
]]}}
}
},
"LbSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "bamboo lb",
"VpcId" : { "Ref" : "VpcId" },
"SecurityGroupIngress" : [
{ "IpProtocol" : "tcp", "FromPort" : "80", "ToPort" : "80", "CidrIp" : "0.0.0.0/0" },
{ "IpProtocol" : "tcp", "FromPort" : "8000", "ToPort" : "8000", "SourceSecurityGroupId" : { "Ref" : "AdminSecurityGroup"} }
]
}
},
"ServerSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "bamboo server",
"VpcId" : { "Ref" : "VpcId" },
"SecurityGroupIngress" : [
{ "IpProtocol" : "-1", "FromPort" : "0", "ToPort" : "65535", "SourceSecurityGroupId" : { "Ref" : "LbSecurityGroup"} },
{ "IpProtocol" : "tcp", "FromPort" : "8000", "ToPort" : "8000", "SourceSecurityGroupId" : { "Ref" : "MarathonServerSecurityGroup"} }
]
}
},
"BambooToMarathonIngress" : {
"Type" : "AWS::EC2::SecurityGroupIngress",
"Properties" : {
"GroupId" : { "Ref" : "ServerSecurityGroup" },
"IpProtocol" : "tcp",
"FromPort" : "8080",
"ToPort" : "8080",
"SourceSecurityGroupId" : { "Ref" : "MarathonServerSecurityGroup" }
}
},
"ElasticLoadBalancer" : {
"Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
"Properties" : {
"SecurityGroups": [{ "Ref": "LbSecurityGroup" }, { "Ref" : "AdminSecurityGroup" }],
"Subnets": { "Ref": "Subnets" },
"Listeners" : [{
"LoadBalancerPort" : "80",
"Protocol" : "HTTP",
"InstancePort" : "80",
"InstanceProtocol" : "HTTP"
}],
"HealthCheck" : {
"Target" : "HTTP:8000/status",
"HealthyThreshold" : "2",
"UnhealthyThreshold" : "2",
"Interval" : "5",
"Timeout" : "3"
}
}
},
"WaitHandle" : {
"Type" : "AWS::CloudFormation::WaitConditionHandle"
}
},
"Outputs" : {
"BambooEndpoint" : {
"Description" : "Bamboo Endpoint",
"Value" : { "Fn::Join" : ["", [
"http://", { "Fn::GetAtt" : [ "ElasticLoadBalancer", "DNSName" ]}, ":8000"
]]}
}
}
}