forked from lambci/ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcluster.template
146 lines (146 loc) · 4.43 KB
/
cluster.template
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
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "LambCI build servers running on ECS",
"Parameters": {
"KeyName":{
"Type":"AWS::EC2::KeyPair::KeyName",
"Description":"Name of an existing EC2 KeyPair to enable SSH access to the ECS instances."
},
"InstanceType": {
"Description": "EC2 instance type (t2.micro, t2.medium, t2.large, etc)",
"Type": "String",
"Default": "t2.micro",
"ConstraintDescription": "must be a valid EC2 instance type."
}
},
"Mappings": {
"EcsAmisByRegion": {
"us-east-1": {"ami": "ami-ef49f695"},
"us-east-2": {"ami": "ami-62745007"},
"us-west-1": {"ami": "ami-689bc208"},
"us-west-2": {"ami": "ami-62d35c02"},
"eu-west-1": {"ami": "ami-95f8d2f3"},
"eu-west-2": {"ami": "ami-bf9481db"},
"eu-central-1": {"ami": "ami-085e8a67"},
"ap-northeast-1": {"ami": "ami-f63f6f91"},
"ap-southeast-1": {"ami": "ami-b4ae1dd7"},
"ap-southeast-2": {"ami": "ami-fbe9eb98"},
"ca-central-1": {"ami": "ami-ee58e58a"}
}
},
"Resources": {
"Cluster": {
"Type": "AWS::ECS::Cluster"
},
"BuildTask": {
"Type": "AWS::ECS::TaskDefinition",
"Properties": {
"ContainerDefinitions": [{
"Name": "build",
"Image": "slajax/lambci",
"Memory": 450,
"LogConfiguration": {
"LogDriver": "awslogs",
"Options": {
"awslogs-group": {"Ref": "EcsLogs"},
"awslogs-region": {"Ref": "AWS::Region"}
}
},
"Environment": [
{"Name": "LOG_GROUP", "Value": {"Ref": "EcsLogs"}},
{"Name": "AWS_REGION", "Value": {"Ref": "AWS::Region"}}
],
"MountPoints": [{"SourceVolume": "docker-socket", "ContainerPath": "/var/run/docker.sock"}]
}],
"Volumes": [{"Name": "docker-socket", "Host": {"SourcePath": "/var/run/docker.sock"}}]
}
},
"EcsLogs": {
"Type": "AWS::Logs::LogGroup"
},
"AutoScalingGroup": {
"Type": "AWS::AutoScaling::AutoScalingGroup",
"Properties": {
"AvailabilityZones": {"Fn::GetAZs": ""},
"LaunchConfigurationName": {"Ref": "LaunchConfig"},
"DesiredCapacity": "1",
"MinSize": "0",
"MaxSize": "4"
},
"CreationPolicy": {
"ResourceSignal": {
"Count": "1"
}
}
},
"LaunchConfig": {
"Type": "AWS::AutoScaling::LaunchConfiguration",
"Properties": {
"ImageId": {"Fn::FindInMap": ["EcsAmisByRegion", {"Ref": "AWS::Region"}, "ami"]},
"IamInstanceProfile": {"Ref": "InstanceProfile"},
"InstanceType": {"Ref": "InstanceType"},
"KeyName":{
"Ref":"KeyName"
},
"UserData": {
"Fn::Base64": {
"Fn::Join": ["", [
"#!/bin/bash\n",
"echo ECS_CLUSTER=", {"Ref": "Cluster"}, " >> /etc/ecs/ecs.config\n",
"yum install -y aws-cfn-bootstrap\n",
"/opt/aws/bin/cfn-signal -e $? --resource AutoScalingGroup --stack ", {"Ref": "AWS::StackName"}, " --region ", {"Ref": "AWS::Region"}
]]
}
}
}
},
"InstanceProfile": {
"Type": "AWS::IAM::InstanceProfile",
"Properties": {
"Path": "/",
"Roles": [{"Ref": "InstanceRole"}]
}
},
"InstanceRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Statement": {
"Effect": "Allow",
"Principal": {"Service": "ec2.amazonaws.com"},
"Action": "sts:AssumeRole"
}
},
"Policies": [{
"PolicyName": "RunEcs",
"PolicyDocument": {
"Statement": {
"Effect": "Allow",
"Action": [
"ecs:DeregisterContainerInstance",
"ecs:DiscoverPollEndpoint",
"ecs:Poll",
"ecs:RegisterContainerInstance",
"ecs:StartTelemetrySession",
"ecs:Submit*"
],
"Resource": "*"
}
}
},{
"PolicyName": "WriteLogs",
"PolicyDocument": {
"Statement": {
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
}
}]
}
}
}
}