-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcf-master.yaml
414 lines (356 loc) · 13.1 KB
/
cf-master.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
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
410
411
412
413
414
AWSTemplateFormatVersion: 2010-09-09
Description: >
This is a root stack which creates all required nested stacks.
Parameters:
EnvType:
Description: Environment type.
Default: dev
Type: String
AllowedValues: [prod, dev]
ConstraintDescription: must specify prod or dev.
LoadBalancerName:
Description: ALB Name
Type: String
LoadBalancerSubnetId:
Type: List<AWS::EC2::Subnet::Id>
Description: Select at two subnets in your selected VPC.
LoadBalancerHealthCheckPath:
Type: String
Description: The path for the Application Load Balancer health check.
Default: /
MinLength: 1
MaxLength: 255
ConstraintDescription: Value must be between 1 and 255 characters
LoadBalancerSecurityGroup:
Description: An existing security group ID for Load Balancer.
Type: List<AWS::EC2::SecurityGroup::Id>
EcsClusterName:
Description: ECS Cluster Name.
Type: String
EcsServiceName:
Description: ECS Service Name. (Optional)
Type: String
EcsVpcId:
Type: AWS::EC2::VPC::Id
Description: Select a VPC that allows instances access to the Internet.
EcsSubnetId:
Type: List<AWS::EC2::Subnet::Id>
Description: Select at two subnets in your selected VPC.
EcsSecurityGroup:
Description: An existing security group ID for ECS Services.
Type: AWS::EC2::SecurityGroup::Id
CloudWatchLogGroup:
Description: CloudWatch Log Group Name.
Type: String
ContainerLogRetentionInDays:
Type: Number
Description: Retention settings to specify how long log events are kept in CloudWatch Logs. Expired log events get deleted automatically.
Default: 7
ApplicationDomainName:
Description: Domain Name for the application. For creating AWS Certificate Manager.
Type: String
EcsAlertEmail:
Type: String
Description: Email for sending alert when ECS task stopped.
TaskMinContainerCount:
Type: Number
Description: Minimum number of containers to run for the service
Default: 1
MinValue: 1
ConstraintDescription: Value must be at least one
TaskMaxContainerCount:
Type: Number
Description: Maximum number of containers to run for the service when auto scaling out
Default: 2
MinValue: 1
ConstraintDescription: Value must be at least one
ServiceScaleEvaluationPeriods:
Description: The number of periods over which data is compared to the specified threshold
Type: Number
Default: 2
MinValue: 2
ServiceCpuScaleOutThreshold:
Type: Number
Description: Average CPU value (Percent) to trigger auto scaling out
Default: 50
MinValue: 0
MaxValue: 100
ConstraintDescription: Value must be between 0 and 100
ServiceCpuScaleInThreshold:
Type: Number
Description: Average CPU value (Percent) to trigger auto scaling in
Default: 25
MinValue: 0
MaxValue: 100
ConstraintDescription: Value must be between 0 and 100
SeedDockerImageLaravel:
Type: String
Default: php:7.2-fpm-alpine
Description: Initial image before CodePipeline is executed. Existing application images in ECR should override this parameter
SeedDockerImageNginx:
Type: String
Default: nginx:alpine
Description: Initial image before CodePipeline is executed. Existing application images in ECR should override this parameter
ImageRepoLaravel:
Description: ECR Repositories Name for Laravel.
Type: String
ImageRepoNginx:
Description: ECR Repositories Name for Nginx web server.
Type: String
MaxTaggedContainerImagesToRetain:
Type: Number
Description: The number of tagged container images to retain before expiring
MinValue: 1
MaxValue: 100
ConstraintDescription: Value must be between 1 and 100
Default: 20
DaysToRetainUntaggedContainerImages:
Type: Number
Description: The number days to retain untagged container images before expiring
MinValue: 1
MaxValue: 100
ConstraintDescription: Value must be between 1 and 100
Default: 7
GitHubUser:
Type: String
Description: Your username on GitHub.
GitHubRepo:
Type: String
Description: The repo name of the sample service.
GitHubBranch:
Type: String
Description: The branch of the repo to continuously deploy.
GitHubToken:
Type: String
NoEcho: true
Description: >
Token for the user specified above. (https://github.com/settings/tokens).
CodePipelineName:
Description: CodePipeline Name.
Type: String
S3CodePipelineBucketName:
Description: S3 Bucket Name for CodePipeline artifact store.
Type: String
CodeBuildSpecFileName:
Description: The build specification for the project.
Type: String
Default: buildspec.yml
# Cloudformation pipeline parameter
CFGitHubUser:
Type: String
Description: Your username on GitHub.
CFGitHubRepo:
Type: String
Description: The repo name of the sample service.
CFGitHubBranch:
Type: String
Description: The branch of the repo to continuously deploy.
CFGitHubToken:
Type: String
NoEcho: true
Description: >
Token for the user specified above. (https://github.com/settings/tokens)
CFCodePipelineName:
Description: A name for cloudformation pipeline
Type: String
CFS3CodePipelineBucketName:
Description: S3 Bucket Name for CodePipeline artifact store.
Type: String
CFCodeBuildSpecFileName:
Type: String
Description: The build specification for the project.
Default: buildspec.yml
TemplateFileName:
Type: String
Description: The cloudformation template to deploy (Or the root stack template).
StackConfig:
Type: String
Description: The cloudformation Template Configuration File.
ChangeSetName:
Type: String
Description: A given name for the cloudformation change set.
Email:
Description: The email address where CodePipeline sends pipeline notifications.
Type: String
StartEcsLambdaScheduleExpression:
Description: >
The frequency that determines when CloudWatch Events runs the rule that
triggers the Lambda function. Cron or Rate Expressions.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html
Type: String
StopEcsLambdaScheduleExpression:
Description: >
The frequency that determines when CloudWatch Events runs the rule that
triggers the Lambda function. Cron or Rate Expressions.
https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html
Type: String
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Environment
Parameters:
- EnvType
- Label:
default: ECS Cluster Configuration
Parameters:
- LoadBalancerName
- LoadBalancerSubnetId
- LoadBalancerSecurityGroup
- LoadBalancerHealthCheckPath
- EcsClusterName
- EcsServiceName
- EcsVpcId
- EcsSubnetId
- EcsSecurityGroup
- CloudWatchLogGroup
- ContainerLogRetentionInDays
- ApplicationDomainName
- EcsAlertEmail
- Label:
default: ECS Auto Scaling Configuration
Parameters:
- TaskMinContainerCount
- TaskMaxContainerCount
- ServiceScaleEvaluationPeriods
- ServiceCpuScaleOutThreshold
- ServiceCpuScaleInThreshold
- Label:
default: ECR Configuration
Parameters:
- SeedDockerImageLaravel
- SeedDockerImageNginx
- ImageRepoLaravel
- ImageRepoNginx
- MaxTaggedContainerImagesToRetain
- DaysToRetainUntaggedContainerImages
- Label:
default: ECS CI/CD Configuration
Parameters:
- GitHubUser
- GitHubRepo
- GitHubBranch
- GitHubToken
- CodePipelineName
- S3CodePipelineBucketName
- CodeBuildSpecFileName
- Label:
default: Cloudformation CI/CD Configuration
Parameters:
- CFGitHubUser
- CFGitHubRepo
- CFGitHubBranch
- CFGitHubToken
- CFCodePipelineName
- CFS3CodePipelineBucketName
- CFCodeBuildSpecFileName
- Label:
default: CloudFormation Stack Info
Parameters:
- TemplateFileName
- StackConfig
- ChangeSetName
- Email
- Label:
default: Scheduled Lambda Configuration
Parameters:
- StartEcsLambdaScheduleExpression
- StopEcsLambdaScheduleExpression
Conditions:
CreateProdResources: !Equals [!Ref EnvType, prod]
CreateDevResources: !Equals [!Ref EnvType, dev]
Resources:
GitHubTokenSecret:
Type: AWS::SecretsManager::Secret
Properties:
Name: !Sub ${AWS::StackName}
Description: This secret has GitHub token in SecretString.
SecretString: !Sub '{"GitHubPersonalAccessToken":"${GitHubToken}","CFGitHubPersonalAccessToken":"${CFGitHubToken}"}'
Cluster:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: "./cf-ecs.yaml"
Parameters:
EnvType: !Ref EnvType
LoadBalancerName: !Ref LoadBalancerName
LoadBalancerSubnetId: !Join [ ",", !Ref LoadBalancerSubnetId ]
LoadBalancerSecurityGroup: !Join [ ",", !Ref LoadBalancerSecurityGroup ]
LoadBalancerHealthCheckPath: !Ref LoadBalancerHealthCheckPath
EcsClusterName: !Ref EcsClusterName
EcsServiceName: !Ref EcsServiceName
EcsVpcId: !Ref EcsVpcId
EcsSubnetId: !Join [ ",", !Ref EcsSubnetId ]
EcsSecurityGroup: !Ref EcsSecurityGroup
CloudWatchLogGroup: !Ref CloudWatchLogGroup
ContainerLogRetentionInDays: !Ref ContainerLogRetentionInDays
ApplicationDomainName: !Ref ApplicationDomainName
EcsAlertEmail: !Ref EcsAlertEmail
TaskMinContainerCount: !Ref TaskMinContainerCount
TaskMaxContainerCount: !Ref TaskMaxContainerCount
ServiceScaleEvaluationPeriods: !Ref ServiceScaleEvaluationPeriods
ServiceCpuScaleOutThreshold: !Ref ServiceCpuScaleOutThreshold
ServiceCpuScaleInThreshold: !Ref ServiceCpuScaleInThreshold
SeedDockerImageNginx: !Ref SeedDockerImageNginx
SeedDockerImageLaravel: !Ref SeedDockerImageLaravel
ImageRepoNginx: !Ref ImageRepoNginx
ImageRepoLaravel: !Ref ImageRepoLaravel
MaxTaggedContainerImagesToRetain: !Ref MaxTaggedContainerImagesToRetain
DaysToRetainUntaggedContainerImages: !Ref DaysToRetainUntaggedContainerImages
DeploymentPipeline:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: "./cf-app-pipeline.yaml"
Parameters:
EnvType: !Ref EnvType
Cluster: !GetAtt Cluster.Outputs.ecscluster
Service: !GetAtt Cluster.Outputs.ecsservice
GitHubUser: !Ref GitHubUser
GitHubRepo: !Ref GitHubRepo
GitHubBranch: !Ref GitHubBranch
GitHubToken: !Join [ '', [ '{{resolve:secretsmanager:', !Ref GitHubTokenSecret, ':SecretString:GitHubPersonalAccessToken}}' ] ]
CodePipelineName: !Ref CodePipelineName
S3CodePipelineBucketName: !Ref S3CodePipelineBucketName
CodeBuildSpecFileName: !Ref CodeBuildSpecFileName
ImageRepoNginx: !Ref ImageRepoNginx
ImageRepoLaravel: !Ref ImageRepoLaravel
CloudformationPipeline:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: "./cf-cloudformation-pipeline.yaml"
Parameters:
# EnvType: !Ref EnvType
GitHubUser: !Ref CFGitHubUser
GitHubRepo: !Ref CFGitHubRepo
GitHubBranch: !Ref CFGitHubBranch
GitHubToken: !Join [ '', [ '{{resolve:secretsmanager:', !Ref GitHubTokenSecret, ':SecretString:CFGitHubPersonalAccessToken}}' ] ]
PipelineName: !Ref CFCodePipelineName
S3CodePipelineBucketName: !Ref CFS3CodePipelineBucketName
CodeBuildSpecFileName: !Ref CFCodeBuildSpecFileName
TemplateFileName: !Ref TemplateFileName
StackName: !Ref AWS::StackName
StackConfig: !Ref StackConfig
ChangeSetName: !Ref ChangeSetName
Email: !Ref Email
ClusterLambdaEvent:
Type: AWS::CloudFormation::Stack
Condition: CreateDevResources
Properties:
TemplateURL: "./cf-lambda.yaml"
Parameters:
EnvType: !Ref EnvType
EcsCluster: !GetAtt Cluster.Outputs.ecscluster
EcsServiceName: !GetAtt Cluster.Outputs.ecsservice
StartEcsLambdaScheduleExpression: !Ref StartEcsLambdaScheduleExpression
StopEcsLambdaScheduleExpression: !Ref StopEcsLambdaScheduleExpression
Subnets: !Join [ ",", !Ref EcsSubnetId ]
SecurityGroup: !Ref EcsSecurityGroup
Outputs:
ServiceUrl:
Description: The sample service that is being continuously deployed.
Value: !GetAtt Cluster.Outputs.ECSALB
AppPipelineUrl:
Description: The continuous deployment pipeline for App in the AWS Management Console.
Value: !GetAtt DeploymentPipeline.Outputs.PipelineUrl
CloudformationPipelineUrl:
Description: The continuous deployment pipeline for CloudFormation in the AWS Management Console.
Value: !GetAtt CloudformationPipeline.Outputs.PipelineUrl