forked from lambci/lambci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
177 lines (164 loc) · 5.16 KB
/
template.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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: LambCI function and supporting services (see github.com/lambci/lambci for documentation)
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: GitHub Configuration
Parameters:
- GithubToken
- GithubSecret
- Label:
default: Slack Configuration (optional)
Parameters:
- SlackToken
- SlackChannel
Parameters:
GithubToken:
Description: GitHub OAuth token
Type: String
Default: ''
NoEcho : true
AllowedPattern: '^$|^[0-9a-f]{40}$'
ConstraintDescription: Must be empty or a 40 char GitHub token
GithubSecret:
Description: GitHub webhook secret
Type: String
Default: ''
NoEcho : true
SlackToken:
Description: (optional) Slack API token
Type: String
Default: ''
NoEcho : true
AllowedPattern: '^$|^xox.-[0-9]+-.+'
ConstraintDescription: 'Must be empty or a valid Slack token, eg: xoxb-1234'
SlackChannel:
Description: (optional) Slack channel
Type: String
Default: '#general'
AllowedPattern: '^$|^#.+'
ConstraintDescription: 'Must be empty or a valid Slack channel, eg: #general'
Resources:
# Uncomment this (and permissions below) to add an SNS topic to publish build statuses to:
# StatusTopic:
# Type: AWS::SNS::Topic
# Properties:
# DisplayName: LambCI
BuildLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-build
Description: !Sub 'LambCI build function for stack: ${AWS::StackName}'
Runtime: nodejs8.10
CodeUri: build/lambda.zip
Handler: index.handler
Timeout: 900
MemorySize: 3008
Events:
Webhook:
Type: Api
Properties:
Path: /lambci/webhook
Method: POST
Policies:
- S3FullAccessPolicy:
BucketName: !Ref BuildResults
- DynamoDBCrudPolicy:
TableName: !Ref ConfigTable
- Statement:
- Action:
- dynamodb:GetItem
- dynamodb:BatchGetItem
- dynamodb:Query
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:BatchWriteItem
Effect: Allow
Resource:
- !Sub arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${BuildsTable}
- !Sub arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${BuildsTable}/index/*
- LambdaInvokePolicy:
FunctionName: !Sub ${AWS::StackName}-build
# Uncomment this if you've added an SNS topic to publish to (above)
# - SNSPublishMessagePolicy:
# TopicName: !Ref StatusTopic
BuildResults:
Type: AWS::S3::Bucket
ConfigTable:
Type: AWS::Serverless::SimpleTable
Properties:
TableName: !Sub ${AWS::StackName}-config
PrimaryKey:
Name: project
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
BuildsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Sub ${AWS::StackName}-builds
AttributeDefinitions:
- AttributeName: project
AttributeType: S
- AttributeName: buildNum
AttributeType: N
- AttributeName: trigger
AttributeType: S
- AttributeName: commit
AttributeType: S
- AttributeName: requestId
AttributeType: S
KeySchema:
- AttributeName: project
KeyType: HASH
- AttributeName: buildNum
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
LocalSecondaryIndexes:
- IndexName: trigger
KeySchema:
- AttributeName: project
KeyType: HASH
- AttributeName: trigger
KeyType: RANGE
Projection:
ProjectionType: KEYS_ONLY
- IndexName: commit
KeySchema:
- AttributeName: project
KeyType: HASH
- AttributeName: commit
KeyType: RANGE
Projection:
ProjectionType: KEYS_ONLY
- IndexName: requestId
KeySchema:
- AttributeName: project
KeyType: HASH
- AttributeName: requestId
KeyType: RANGE
Projection:
ProjectionType: KEYS_ONLY
ConfigUpdater:
Type: Custom::ConfigUpdater
DependsOn: ConfigTable
Properties:
ServiceToken: !GetAtt BuildLambda.Arn
GithubToken: !Ref GithubToken
GithubSecret: !Ref GithubSecret
SlackToken: !Ref SlackToken
SlackChannel: !Ref SlackChannel
S3Bucket: !Ref BuildResults
WebhookUrl: !Sub https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/lambci/webhook
Outputs:
S3Bucket:
Description: Name of the build results S3 bucket, see github.com/lambci/lambci
Value: !Ref BuildResults
WebhookUrl:
Description: GitHub webhook URL
Value: !Sub https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/lambci/webhook