-
Notifications
You must be signed in to change notification settings - Fork 50
/
pipeline-taskcat.yml
305 lines (305 loc) · 8.51 KB
/
pipeline-taskcat.yml
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
---
AWSTemplateFormatVersion: '2010-09-09'
Description: CodePipeline with CodeBuild workflow to run TaskCat test CloudFormation templates
Parameters:
GitHubUser:
Type: String
Description: GitHub User
Default: "stelligent"
GitHubRepo:
Type: String
Description: GitHub Repo to pull from. Only the Name. not the URL
Default: "pipeline-dashboard"
GitHubBranch:
Type: String
Description: GitHub Branch
Default: "master"
GitHubToken:
NoEcho: true
Type: String
Default: '{{resolve:secretsmanager:github/personal-access-token:SecretString}}'
Description: GitHub Token. Must be defined in AWS Secrets Manager and here https://github.com/settings/tokens
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "GitHub Configuration"
Parameters:
- GitHubToken
- GitHubUser
- GitHubRepo
- GitHubBranch
ParameterLabels:
GitHubToken:
default: GitHub OAuth2 Token
GitHubUser:
default: GitHub User/Org Name
GitHubRepo:
default: GitHub Repository Name
GitHubBranch:
default: GitHub Branch Name
Resources:
SiteBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Retain
Properties:
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
CodePipelineRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- codepipeline.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
Policies:
- PolicyName: codepipeline-service
PolicyDocument:
Statement:
- Action:
- logs:*
- lambda:*
- cloudwatch:*
- codebuild:*
- s3:*
Resource: "*"
Effect: Allow
- Action:
- s3:PutObject
Resource:
- arn:aws:s3:::codepipeline*
Effect: Allow
- Action:
- logs:*
- lambda:*
- cloudwatch:*
- codebuild:*
- s3:*
- ec2:*
- iam:PassRole
Resource: "*"
Effect: Allow
Version: '2012-10-17'
CodeBuildRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- codebuild.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
Policies:
- PolicyName: codebuild-service
PolicyDocument:
Statement:
- Action:
- apigateway:*
- cloudformation:*
- cloudwatch:*
- cloudtrail:*
- codebuild:*
- codecommit:*
- codepipeline:*
- config:*
- dynamodb:*
- ec2:*
- events:*
- iam:*
- kms:*
- lambda:*
- logs:*
- redshift:*
- rds:*
- secretsmanager:*
- s3:*
- sns:*
- sqs:*
Effect: Allow
Resource: "*"
Version: '2012-10-17'
CodeBuildSetup:
Type: AWS::CodeBuild::Project
DependsOn: CodeBuildRole
Properties:
Name: !Sub ${AWS::StackName}-setup
Description: Setup Test Files. For example uploading to S3
ServiceRole: !GetAtt CodeBuildRole.Arn
Artifacts:
Type: NO_ARTIFACTS
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: "aws/codebuild/amazonlinux2-x86_64-standard:1.0"
Source:
Type: GITHUB
Location: !Sub https://github.com/${GitHubUser}/${GitHubRepo}.git
BuildSpec: buildspec-setup.yml
TimeoutInMinutes: 10
CodeBuildCleanup:
Type: AWS::CodeBuild::Project
DependsOn: CodeBuildRole
Properties:
Name: !Sub ${AWS::StackName}-cleanup
Description: Setup Test Files. For example uploading to S3
ServiceRole: !GetAtt CodeBuildRole.Arn
Artifacts:
Type: NO_ARTIFACTS
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: "aws/codebuild/amazonlinux2-x86_64-standard:1.0"
Source:
Type: GITHUB
Location: !Sub https://github.com/${GitHubUser}/${GitHubRepo}.git
BuildSpec: buildspec-cleanup.yml
TimeoutInMinutes: 10
CodeBuildTest:
Type: AWS::CodeBuild::Project
DependsOn: CodeBuildRole
Properties:
Name: !Sub ${AWS::StackName}-taskcat
Description: Run TaskCat
ServiceRole: !GetAtt CodeBuildRole.Arn
Artifacts:
Type: NO_ARTIFACTS
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: "aws/codebuild/amazonlinux2-x86_64-standard:1.0"
Source:
Type: GITHUB
Location: !Sub https://github.com/${GitHubUser}/${GitHubRepo}.git
BuildSpec: buildspec-taskcat.yml
TimeoutInMinutes: 60
CodeBuildWebsite:
Type: AWS::CodeBuild::Project
DependsOn: CodeBuildRole
Properties:
Name: !Sub ${AWS::StackName}-dashboard
Description: Deploy site to S3
ServiceRole: !GetAtt CodeBuildRole.Arn
Artifacts:
Type: CODEPIPELINE
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: "aws/codebuild/amazonlinux2-x86_64-standard:1.0"
Source:
Type: CODEPIPELINE
BuildSpec: !Sub |
version: 0.2
phases:
install:
runtime-versions:
python: 3.7
post_build:
commands:
- aws s3 cp --recursive --acl public-read ./taskcat_outputs s3://${SiteBucket}/
artifacts:
type: zip
files:
- ./index.html
TimeoutInMinutes: 10
PipelineBucket:
Type: AWS::S3::Bucket
DeletionPolicy: Delete
Pipeline:
Type: AWS::CodePipeline::Pipeline
Properties:
RoleArn: !GetAtt CodePipelineRole.Arn
Stages:
- Name: Source
Actions:
- InputArtifacts: []
Name: Source
ActionTypeId:
Category: Source
Owner: ThirdParty
Version: '1'
Provider: GitHub
OutputArtifacts:
- Name: SourceArtifacts
Configuration:
Owner: !Ref GitHubUser
Repo: !Ref GitHubRepo
Branch: !Ref GitHubBranch
OAuthToken: !Ref GitHubToken
RunOrder: 1
- Name: Build
Actions:
- InputArtifacts:
- Name: SourceArtifacts
Name: Setup
ActionTypeId:
Category: Test
Owner: AWS
Version: '1'
Provider: CodeBuild
OutputArtifacts:
- Name: SetupArtifacts
Configuration:
ProjectName:
Ref: CodeBuildSetup
RunOrder: 1
- InputArtifacts:
- Name: SetupArtifacts
Name: RunTaskCat
ActionTypeId:
Category: Test
Owner: AWS
Version: '1'
Provider: CodeBuild
OutputArtifacts:
- Name: TaskCatArtifacts
Configuration:
ProjectName:
Ref: CodeBuildTest
RunOrder: 10
- InputArtifacts:
- Name: TaskCatArtifacts
Name: TaskCatDashboard
ActionTypeId:
Category: Test
Owner: AWS
Version: '1'
Provider: CodeBuild
OutputArtifacts: []
Configuration:
ProjectName:
Ref: CodeBuildWebsite
RunOrder: 20
- Name: Cleanup
Actions:
- InputArtifacts:
- Name: SourceArtifacts
Name: RemoveS3Buckets
ActionTypeId:
Category: Test
Owner: AWS
Version: '1'
Provider: CodeBuild
OutputArtifacts: []
Configuration:
ProjectName:
Ref: CodeBuildCleanup
RunOrder: 1
ArtifactStore:
Type: S3
Location: !Ref PipelineBucket
Outputs:
PipelineUrl:
Value: !Sub https://console.aws.amazon.com/codepipeline/home?region=${AWS::Region}#/view/${Pipeline}
Description: CodePipeline URL
TaskCatDashboardUrl:
Value: !Sub http://${SiteBucket}.s3-website-us-east-1.amazonaws.com
Description: URL for TaskCat Dashboard (Available after the CodePipeline completes)