-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverless.yml
More file actions
298 lines (271 loc) · 9.99 KB
/
serverless.yml
File metadata and controls
298 lines (271 loc) · 9.99 KB
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
service: frigg
custom:
webhookSecret: ${file(./utils/parameters.js):generateWebhookSecret}
provider:
name: aws
runtime: nodejs6.10
stage: local
profile: personal
environment:
LOG_LEVEL: { Fn::FindInMap: [ LogLevel, '${opt:stage, self:provider.stage}', level ] }
functions:
ConfigureGitHubWebhook:
handler: webhooks/setup/configure.github
role: ConfigureRole
environment:
WEBHOOK_HANDLER_URL: { Fn::Join : [ '', [ 'https://', { 'Ref' : ApiGatewayRestApi }, '.execute-api.', { 'Ref' : 'AWS::Region' }, '.amazonaws.com/${opt:stage, self:provider.stage}/github' ] ] }
GITHUB_WEBHOOK_SECRET: ${self:custom.webhookSecret}
FRIGG_CONFIG_BUCKET: { Ref: FriggConfig }
# TODO extract this into a list of orgs in a config
# TODO include whitelist and blacklist for repositories within org
GITHUB_ORGANIZATION: santaswap
# TODO create a pipeline for frigg to update itself
# DogFoodFrigg:
# handler:
# role:
# environment:
ProcessGitHubWebhook:
handler: webhooks/messages/process.github
role: PublishRole
events:
- http:
path: github
method: post
cors: true
environment:
UPSERT_PIPELINE_TOPIC: { Ref: 'SNSTopicUpsertpipeline${opt:stage, self:provider.stage}' }
REMOVE_PIPELINE_TOPIC: { Ref: 'SNSTopicRemovepipeline${opt:stage, self:provider.stage}' }
REMOVE_REPOSITORY_PIPELINES_TOPIC: { Ref: 'SNSTopicRemoverepositorypipelines${opt:stage, self:provider.stage}' }
GITHUB_WEBHOOK_SECRET: ${self:custom.webhookSecret}
UpsertPipeline:
handler: pipelines/handler.upsert
role: DeployRole
events: [ sns: 'upsert-pipeline-${opt:stage, self:provider.stage}' ]
environment:
PIPELINE_ADDED_TOPIC: { Ref: 'SNSTopicPipelineadded${opt:stage, self:provider.stage}' }
BUILD_ARTIFACT_BUCKET: { Ref: BuildArtifacts }
BUILD_PROJECT_NAME: { Ref: CodeBuild }
RemovePipeline:
handler: pipelines/handler.removePipeline
role: DeployRole
events: [ sns: 'remove-pipeline-${opt:stage, self:provider.stage}' ]
environment:
ODIN_REMOVE_STACK_TOPIC: hello #${cf:odin-${opt:stage, self:provider.stage}.DeleteStackSNS}
PIPELINE_REMOVED_TOPIC: { Ref: 'SNSTopicPipelineremoved${opt:stage, self:provider.stage}' }
RemoveRepositoryPipelines:
handler: pipelines/handler.removeRepository
role: DeployRole
events: [ sns: 'remove-repository-pipelines-${opt:stage, self:provider.stage}' ]
environment:
ODIN_REMOVE_STACK_TOPIC: hello #${cf:odin-${opt:stage, self:provider.stage}.DeleteStackSNS}
PIPELINE_REMOVED_TOPIC: { Ref: 'SNSTopicPipelineremoved${opt:stage, self:provider.stage}' }
SavePipelineStatus:
handler: status/handler.pipelineAdded
role: TableRole
events: [ sns: 'pipeline-added-${opt:stage, self:provider.stage}' ]
environment:
PIPELINES_TABLE: { Ref: PipelinesTable }
RemovePipelineStatus:
handler: status/handler.pipelineRemoved
role: TableRole
events: [ sns: 'pipeline-removed-${opt:stage, self:provider.stage}' ]
environment:
PIPELINES_TABLE: { Ref: PipelinesTable }
BUILDS_TABLE: { Ref: BuildsTable }
SaveBuildStartedStatus:
handler: status/handler.buildStarted
role: TableRole
events: [ sns: 'build-started-${opt:stage, self:provider.stage}' ]
environment:
BUILDS_TABLE: { Ref: BuildsTable }
SaveBuildFinishedStatus:
handler: status/handler.buildFinished
role: TableRole
events: [ sns: 'build-finished-${opt:stage, self:provider.stage}' ]
environment:
BUILDS_TABLE: { Ref: BuildsTable }
resources:
Description: Automated service for managing CodePipelines for repos & branches inside a GitHub organization
Mappings:
LogLevel:
test:
level: debug
local:
level: debug
dev:
level: debug
automation:
level: debug
production:
level: info
Resources:
PipelinesTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: owner/repository
AttributeType: S
- AttributeName: branch
AttributeType: S
KeySchema:
- AttributeName: owner/repository
KeyType: HASH
- AttributeName: branch
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
BuildsTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: owner/repository/branch
AttributeType: S
- AttributeName: timestamp
AttributeType: S
KeySchema:
- AttributeName: owner/repository/branch
KeyType: HASH
- AttributeName: timestamp
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
ConfigureGitHubWebhookCustomResource:
Type: Custom::ConfigureGitHubWebhook
Version: 1.0
# TODO figure out which of these is latest and only depend on it
DependsOn: [ ProcessGitHubWebhookLambdaPermissionApiGateway ]
Properties:
ServiceToken: { Fn::GetAtt: [ ConfigureGitHubWebhookLambdaFunction, Arn ] }
GITHUB_WEBHOOK_SECRET: ${self:custom.webhookSecret}
FriggConfig:
Type: AWS::S3::Bucket
BuildArtifacts:
Type: AWS::S3::Bucket
Properties:
VersioningConfiguration:
Status: Enabled
CodeBuild:
Type: AWS::CodeBuild::Project
Properties:
Name: FriggPipelineDeployer-${opt:stage, self:provider.stage}
Description: 'CodeBuild used by Frigg in the ${opt:stage, self:provider.stage} environment to deploy pipelines for other projects'
Source:
Type: S3
Location: { Fn::Join : [ /, [ { 'Ref' : BuildArtifacts }, 'build.zip' ] ] }
Environment:
Image: aws/codebuild/eb-nodejs-6.10.0-amazonlinux-64:4.0.0
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Artifacts:
Type: NO_ARTIFACTS
ServiceRole: { Ref: CodeBuildRole }
TimeoutInMinutes: 60
CodeBuildRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
AWS: { Fn::Join : [ ':', [ 'arn:aws:iam:', { 'Ref' : AWS::AccountId }, 'root' ] ] }
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: codebuild.amazonaws.com
Path: /
Policies:
- PolicyName: FriggPipelineDeployerRole
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: '*'
Resource: '*'
PublishRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: [ lambda.amazonaws.com ]
Action: sts:AssumeRole
Policies:
- PolicyName: FriggSNSAccess-${opt:stage, self:provider.stage}
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: sns:Publish
Resource: { Fn::Join : [ ':', [ 'arn:aws:sns', { 'Ref' : AWS::Region }, { 'Ref' : AWS::AccountId }, '*' ] ] }
- Effect: Allow
Action: logs:*
Resource: { Fn::Join : [ ':', [ 'arn:aws:logs', { 'Ref' : AWS::Region }, { 'Ref' : AWS::AccountId }, '*' ] ] }
TableRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: [ lambda.amazonaws.com ]
Action: sts:AssumeRole
Policies:
- PolicyName: FriggDynamoAccess-${opt:stage, self:provider.stage}
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: dynamodb:*
Resource: { Fn::Join : [ ':', [ 'arn:aws:dynamodb', { 'Ref' : AWS::Region }, { 'Ref' : AWS::AccountId }, '*' ] ] }
- Effect: Allow
Action: logs:*
Resource: { Fn::Join : [ ':', [ 'arn:aws:logs', { 'Ref' : AWS::Region }, { 'Ref' : AWS::AccountId }, '*' ] ] }
ConfigureRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: [ lambda.amazonaws.com ]
Action: sts:AssumeRole
Policies:
- PolicyName: FriggS3Access-${opt:stage, self:provider.stage}
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: s3:*
Resource: { Fn::Join : [ ':', [ 'arn:aws:s3', '', '', '*' ] ] }
- Effect: Allow
Action: ssm:*
Resource: { Fn::Join : [ ':', [ 'arn:aws:ssm', { 'Ref' : AWS::Region }, { 'Ref' : AWS::AccountId }, '*' ] ] }
- Effect: Allow
Action: logs:*
Resource: { Fn::Join : [ ':', [ 'arn:aws:logs', { 'Ref' : AWS::Region }, { 'Ref' : AWS::AccountId }, '*' ] ] }
DeployRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: [ lambda.amazonaws.com ]
Action: sts:AssumeRole
Policies:
- PolicyName: FriggDeployAccess-${opt:stage, self:provider.stage}
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action: '*'
Resource: '*'