forked from javahometech/node-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolour-app.yaml
252 lines (215 loc) · 6.53 KB
/
colour-app.yaml
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
AWSTemplateFormatVersion: 2010-09-09
Description: CI/CD pipeline for GitHub projects
Parameters:
ENV:
Type: String
Default: preproduction
AllowedValues:
- preproduction
- production
ContainerPort:
Type: Number
Default: 8080
HostPort:
Type: Number
Default: 8080
PipelineSourceObjectKey:
Description: 'S3 source artifact'
Type: String
Default: kiri-ui.zip
DNSNamespaceID:
Type: String
Default: 'ns-d5forpjik2uspu4k'
Mappings:
ClusterTargetGroup:
name:
preproduction: colourapp-tgroup-staging
production: colourapp-tgroup-master
ALB:
name:
preproduction: colourapp-alb-staging
production: colourapp-alb-master
VPCid:
name:
preproduction: vpc-d27062a8
production: ''
UISGIds:
name:
preproduction: 'sg-e1a6fac2'
production: ''
PrivSubNetIds:
name:
preproduction: 'subnet-d356eedd,subnet-41478a60,subnet-e6aea4d8'
production: ''
PubSubNetIds:
name:
preproduction: 'subnet-d356eedd,subnet-41478a60,subnet-e6aea4d8'
production: ''
#!Split [ ",", !FindInMap [PubSubNetIds, name, !Ref ENV] ]
Resources:
#ECS Service
BlueappService:
Type: AWS::ECS::Service
DependsOn: [BlueappDiscoveryService]
Properties:
Cluster: arn:aws:ecs:us-east-1:858972826311:cluster/Appmesh-test-cluster
ServiceRegistries:
- ContainerName: blueapp-container
RegistryArn: !GetAtt BlueappDiscoveryService.Arn
DeploymentConfiguration:
MaximumPercent: '200'
MinimumHealthyPercent: '100'
DesiredCount: 1
LoadBalancers:
- ContainerName: blueapp-container
ContainerPort: !Ref ContainerPort
TargetGroupArn: !Ref 'ECSTG'
LaunchType: FARGATE
TaskDefinition: blueapp-task
#PlatformVersion: 1.3.0
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups: !Split [ ",", !FindInMap [UISGIds, name, !Ref ENV] ]
Subnets: !Split [ ",", !FindInMap [PubSubNetIds, name, !Ref ENV] ]
ServiceName: blueapp-service
RedappService:
Type: AWS::ECS::Service
DependsOn: [RedappDiscoveryService]
Properties:
Cluster: arn:aws:ecs:us-east-1:858972826311:cluster/Appmesh-test-cluster
ServiceRegistries:
- ContainerName: redapp-container
RegistryArn: !GetAtt RedappDiscoveryService.Arn
DeploymentConfiguration:
MaximumPercent: '200'
MinimumHealthyPercent: '100'
DesiredCount: 1
LoadBalancers:
- ContainerName: redapp-container
ContainerPort: !Ref ContainerPort
TargetGroupArn: !Ref 'ECSTG'
LaunchType: FARGATE
TaskDefinition: redapp-task
#PlatformVersion: 1.3.0
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups: !Split [ ",", !FindInMap [UISGIds, name, !Ref ENV] ]
Subnets: !Split [ ",", !FindInMap [PubSubNetIds, name, !Ref ENV] ]
ServiceName: redapp-service
GreenappService:
Type: AWS::ECS::Service
DependsOn: [GreenappDiscoveryService]
Properties:
Cluster: arn:aws:ecs:us-east-1:858972826311:cluster/Appmesh-test-cluster
ServiceRegistries:
- ContainerName: greenapp-container
RegistryArn: !GetAtt GreenappDiscoveryService.Arn
DeploymentConfiguration:
MaximumPercent: '200'
MinimumHealthyPercent: '100'
DesiredCount: 1
LoadBalancers:
- ContainerName: greenapp-container
ContainerPort: !Ref ContainerPort
TargetGroupArn: !Ref 'ECSTG'
LaunchType: FARGATE
TaskDefinition: greenapp-task
#PlatformVersion: 1.3.0
NetworkConfiguration:
AwsvpcConfiguration:
AssignPublicIp: ENABLED
SecurityGroups: !Split [ ",", !FindInMap [UISGIds, name, !Ref ENV] ]
Subnets: !Split [ ",", !FindInMap [PubSubNetIds, name, !Ref ENV] ]
ServiceName: greenapp-service
#Target Group for ECS
ECSTG:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
DependsOn: ECSALB
Properties:
HealthCheckIntervalSeconds: 30
HealthCheckPath: /
HealthCheckProtocol: HTTP
HealthCheckTimeoutSeconds: 10
HealthyThresholdCount: 2
Name: !FindInMap [ClusterTargetGroup, name, !Ref ENV]
Port: 80
#!Ref HostPort
Protocol: HTTP
TargetType: ip
UnhealthyThresholdCount: 2
VpcId: !FindInMap [VPCid, name, !Ref ENV]
#Load Balancer
ECSALB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Name: !FindInMap [ALB, name, !Ref ENV]
Scheme: internet-facing
LoadBalancerAttributes:
- Key: idle_timeout.timeout_seconds
Value: '30'
Subnets: !Split [ ",", !FindInMap [PubSubNetIds, name, !Ref ENV] ]
SecurityGroups: !Split [ ",", !FindInMap [UISGIds, name, !Ref ENV] ]
#ALB Listener
ALBListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref 'ECSTG'
LoadBalancerArn: !Ref 'ECSALB'
Port: '80'
Protocol: HTTP
#ALB Listener Rule
ECSALBListenerRule:
Type: AWS::ElasticLoadBalancingV2::ListenerRule
Properties:
Actions:
- Type: forward
TargetGroupArn: !Ref 'ECSTG'
Conditions:
- Field: path-pattern
Values: [/]
ListenerArn: !Ref 'ALBListener'
Priority: 1
DNSNamespace:
Type: AWS::ServiceDiscovery::PrivateDnsNamespace
Properties:
Name: mesh.local
Vpc: !FindInMap [VPCid, name, !Ref ENV]
BlueappDiscoveryService:
Type: AWS::ServiceDiscovery::Service
Properties:
DnsConfig:
RoutingPolicy: WEIGHTED
DnsRecords:
- Type: A
TTL: 60
Name: blueapp-service
NamespaceId: !GetAtt DNSNamespace.Id
RedappDiscoveryService:
Type: AWS::ServiceDiscovery::Service
Properties:
DnsConfig:
RoutingPolicy: WEIGHTED
DnsRecords:
- Type: A
TTL: 60
Name: redapp-service
NamespaceId: !GetAtt DNSNamespace.Id
GreenappDiscoveryService:
Type: AWS::ServiceDiscovery::Service
Properties:
DnsConfig:
RoutingPolicy: WEIGHTED
DnsRecords:
- Type: A
TTL: 60
Name: greenapp-service
NamespaceId: !GetAtt DNSNamespace.Id
CloudwatchLogsGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Join ['-', [ECSLogGroup, !Ref 'AWS::StackName']]
RetentionInDays: 7