-
Notifications
You must be signed in to change notification settings - Fork 72
/
serverless.yml
297 lines (280 loc) · 11.5 KB
/
serverless.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
service: docs-worker-pool-api
variablesResolutionMode: 20210326
plugins:
- serverless-prune-plugin
- serverless-iam-roles-per-function
- serverless-esbuild
provider:
name: aws
runtime: nodejs18.x
stage: ${opt:stage, 'stg'}
iamRoleStatements:
- Effect: Allow
Action:
- "ssm:PutParameter"
- "ssm:GetParameter"
Resource:
- "*"
deploymentBucket: ${self:custom.deploymentBucket.${opt:stage, 'stg'}}
deploymentPrefix: serverless
region: us-east-2
package:
individually: true
patterns:
api/config/**
custom:
esbuild:
plugins: './api/config/plugins.js'
deploymentBucket:
dev: worker-pool-deployment
stg: worker-pool-deployment
prd: worker-pool-deployment
dotcomstg: worker-pool-deployment
dotcomprd: worker-pool-deployment
searchIndexBucket:
dev: "" # I'm just here so I don't get fined
# TODO: When satisfied with manifest generation, remove the '-test'
dotcomstg: docs-search-indexes-test/preprd
dotcomprd: docs-search-indexes-test/prd
fastlyDochubToken: ${ssm:/env/${self:provider.stage}/docs/worker_pool/fastly/docs/dochub/token}
fastlyDochubServiceId: ${ssm:/env/${self:provider.stage}/docs/worker_pool/fastly/docs/dochub/service_id}
fastlyDochubMap: ${ssm:/env/${self:provider.stage}/docs/worker_pool/fastly/dochub_map}
docuhubEventSource:
stg: aws.partner/mongodb.com/stitch.trigger/5e00b7afec293c6507679c4d
prd: aws.partner/mongodb.com/stitch.trigger/5e00b7afec293c6507679c4d
dev: aws.partner/mongodb.com/stitch.trigger/5e00b7afec293c6507679c4d
dotcomstg: aws.partner/mongodb.com/stitch.trigger/5e00b7afec293c6507679c4d
dotcomprd: aws.partner/mongodb.com/stitch.trigger/5e00b7afec293c6507679c4d
dochubEventBus: arn:aws:events:${aws:region}:${aws:accountId}:event-bus/${self:custom.docuhubEventSource.${self:provider.stage}}
dbUsername: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/username}
dbPassword: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/password}
dbName: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/dbname}
snootyDbName: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/collections/snooty}
dbhost: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/host}
jobCollection: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/collections/job/queue}
entitlementCollection: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/collections/user/entitlements}
repoBranchesCollection: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/collections/repo}
docsetsCollection: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/collections/docsets}
githubSecret: ${ssm:/env/${self:provider.stage}/docs/worker_pool/github/webhook/secret}
githubDeletionSecret: ${ssm:/env/${self:provider.stage}/docs/worker_pool/github/webhook/deletionSecret}
githubBotPW: ${ssm:/env/${self:provider.stage}/docs/worker_pool/github/bot/password}
slackSecret: ${ssm:/env/${self:provider.stage}/docs/worker_pool/slack/webhook/secret}
slackAuthToken: ${ssm:/env/${self:provider.stage}/docs/worker_pool/slack/auth/token}
snootySecret: ${ssm:/env/${self:provider.stage}/docs/worker_pool/snooty/webhook/secret}
featureFlagMonorepoPath: ${ssm:/env/${self:provider.stage}/docs/worker_pool/flag/monorepo_path}
JobsQueueName: autobuilder-jobs-queue-${self:provider.stage}
JobsDLQueueName: autobuilder-jobs-dlqueue-${self:provider.stage}
JobUpdatesQueueName: autobuilder-job-updates-queue-${self:provider.stage}
JobUpdatesDLQueueName: autobuilder-job-updates-dlqueue-${self:provider.stage}
dashboardUrl:
stg: https://workerpoolstaging-qgeyp.mongodbstitch.com/pages/job.html?collName=${self:custom.jobCollection}&jobId=
prd: https://workerpool-boxgs.mongodbstitch.com/pages/job.html?collName=${self:custom.jobCollection}&jobId=
dotcomstg: https://workerpoolstaging-qgeyp.mongodbstitch.com/pages/job.html?collName=${self:custom.jobCollection}&jobId=
dotcomprd: https://workerpool-boxgs.mongodbstitch.com/pages/job.html?collName=${self:custom.jobCollection}&jobId=
dev: https://workerpoolstaging-qgeyp.mongodbstitch.com/pages/job.html?collName=${self:custom.jobCollection}&jobId=
env:
stg: "staging"
prd: "production"
dev: "staging"
jobsQueueUrl: https://sqs.${aws:region}.amazonaws.com/${aws:accountId}/${self:custom.JobsQueueName}
jobUpdatesQueueUrl: https://sqs.${aws:region}.amazonaws.com/${aws:accountId}/${self:custom.JobUpdatesQueueName}
cdnClientID: ${ssm:/env/${self:provider.stage}/docs/worker_pool/cdn/client/id}
cdnClientSecret: ${ssm:/env/${self:provider.stage}/docs/worker_pool/cdn/client/secret}
default-env: &default-env
STAGE: ${self:provider.stage}
ENVIRONMENT: ${self:provider.stage}
FASTLY_DOCHUB_MAP: ${self:custom.fastlyDochubMap}
FASTLY_DOCHUB_SERVICE_ID: ${self:custom.fastlyDochubServiceId}
FASTLY_DOCHUB_TOKEN: ${self:custom.fastlyDochubToken}
GITHUB_WEBHOOK_SECRET: REPLACE-WITH-YOUR-SECRET-HERE
NODE_CONFIG_DIR: './api/config'
CDN_CLIENT_ID: ${self:custom.cdnClientID}
CDN_CLIENT_SECRET: ${self:custom.cdnClientSecret}
webhook-env-core: &webhook-env-core
STAGE: ${self:provider.stage}
ENVIRONMENT: ${self:provider.stage}
MONGO_ATLAS_USERNAME: ${self:custom.dbUsername}
MONGO_ATLAS_PASSWORD: ${self:custom.dbPassword}
MONGO_ATLAS_HOST: ${self:custom.dbhost}
MONGO_ATLAS_URL: mongodb+srv://${self:custom.dbUsername}:${self:custom.dbPassword}@${self:custom.dbhost}/admin?retryWrites=true
DB_NAME: ${self:custom.dbName}
SNOOTY_DB_NAME: ${self:custom.snootyDbName}
USER_ENTITLEMENT_COL_NAME: ${self:custom.entitlementCollection}
JOB_QUEUE_COL_NAME: ${self:custom.jobCollection}
GITHUB_SECRET: ${self:custom.githubSecret}
GITHUB_DELETION_SECRET: ${self:custom.githubDeletionSecret}
GITHUB_BOT_PASSWORD: ${self:custom.githubBotPW}
REPO_BRANCHES_COL_NAME: ${self:custom.repoBranchesCollection}
DOCSETS_COL_NAME: ${self:custom.docsetsCollection}
SLACK_SECRET: ${self:custom.slackSecret}
SLACK_TOKEN: ${self:custom.slackAuthToken}
SNOOTY_SECRET: ${self:custom.snootySecret}
FEATURE_FLAG_MONOREPO_PATH: ${self:custom.featureFlagMonorepoPath}
DASHBOARD_URL: ${self:custom.dashboardUrl.${self:provider.stage}}
NODE_CONFIG_DIR: './api/config'
TASK_DEFINITION_FAMILY: docs-worker-pool-${self:provider.stage}
JOB_UPDATES_QUEUE_URL: ${self:custom.jobUpdatesQueueUrl}
JOBS_QUEUE_URL: ${self:custom.jobsQueueUrl}
resources:
- ${file(./queues.yml)}
functions:
v1GithubDeployRepo:
handler: api/controllers/v1/github.TriggerBuild
events:
- http:
path: /webhook/github/trigger/build
method: POST
cors: true
environment:
<<: *webhook-env-core
v1DochubDeployRepo:
handler: api/controllers/v1/dochub.TriggerBuild
events:
- http:
path: /webhook/dochub/trigger/build
method: POST
cors: true
public: true
environment:
<<: *webhook-env-core
v1UpsertEdgeDictionaryItem:
handler: api/controllers/v1/dochub.UpsertEdgeDictionaryItem
events:
- http:
path: /webhook/dochub/trigger/upsert
method: POST
cors: true
public: true
environment:
<<: *default-env
v1SlackDisplayRepoOptions:
handler: api/controllers/v1/slack.DisplayRepoOptions
events:
- http:
path: /webhook/slack/display/repos
method: POST
cors: true
environment:
<<: *webhook-env-core
v1SlackDeployRepo:
handler: api/controllers/v1/slack.DeployRepo
events:
- http:
path: /webhook/slack/trigger/build
method: POST
cors: true
iamRoleStatementsName: 'dwpapi-v1SlackDeployRepo-lr-${self:provider.region}-${self:provider.stage}'
iamRoleStatements:
- Effect: Allow
Action:
- "sqs:SendMessage"
Resource:
- "*"
environment:
<<: *webhook-env-core
v1TriggerLocalBuild:
handler: api/controllers/v1/jobs.TriggerLocalBuild
events:
- http:
path: /webhook/local/trigger/build
method: POST
cors: true
batchSize: 1
iamRoleStatementsName: 'dwpapi-v1TriggerLocalBuild-lr-${self:provider.region}-${self:provider.stage}'
iamRoleStatements:
- Effect: Allow
Action:
- "sqs:SendMessage"
- "sqs:GetQueueAttributes"
Resource:
- Fn::GetAtt: [AutobuilderJobUpdatesQueue, Arn]
- Fn::GetAtt: [AutobuilderJobsQueue, Arn]
environment:
<<: *webhook-env-core
v1HandleJobs:
handler: api/controllers/v1/jobs.HandleJobs
timeout: 180
events:
- sqs:
arn: !GetAtt AutobuilderJobsQueue.Arn
batchSize: 1
- sqs:
arn: !GetAtt AutobuilderJobUpdatesQueue.Arn
batchSize: 1
iamRoleStatementsName: 'dwpapi-v1HandleJobs-ecs-execution-lr-${self:provider.region}-${self:provider.stage}'
iamRoleStatements:
- Effect: Allow
Action:
- "sqs:ReceiveMessage"
- "sqs:DeleteMessage"
- "sqs:SendMessage"
- "sqs:GetQueueAttributes"
Resource:
- Fn::GetAtt: [AutobuilderJobUpdatesQueue, Arn]
- Fn::GetAtt: [JobUpdatesDLQ, Arn]
- Fn::GetAtt: [AutobuilderJobsQueue, Arn]
- Fn::GetAtt: [JobsDLQ, Arn]
- Effect: Allow
Action:
- "ecs:RunTask"
- "ecs:StopTask"
- "ecs:DescribeTasks"
Resource:
- arn:aws:ecs:${aws:region}:${aws:accountId}:task-definition/docs-worker-pool-${self:provider.stage}:*
- arn:aws:ecs:${aws:region}:${aws:accountId}:task/docs-worker-pool-${self:provider.stage}/*
- Effect: Allow
Action:
- ecs:DescribeTaskDefinition
- ecr:GetAuthorizationToken
- ecr:BatchCheckLayerAvailability
- ecr:GetDownloadUrlForLayer
- ecr:BatchGetImage
Resource: "*"
- Effect: Allow
Action:
- iam:PassRole
Resource: "*"
- Effect: Allow
Action:
- batch:SubmitJob
Resource:
- arn:aws:batch:${aws:region}:${aws:accountId}:job-queue/docs-archive-${self:provider.stage}
- arn:aws:batch:${aws:region}:${aws:accountId}:job-definition/docs-archive-${self:provider.stage}
- arn:aws:batch:${aws:region}:${aws:accountId}:job-definition/docs-archive-${self:provider.stage}:*
environment:
<<: *webhook-env-core
v1FailStuckJobs:
handler: api/controllers/v1/jobs.FailStuckJobs
events:
- schedule: rate(8 hours)
environment:
<<: *webhook-env-core
v1SnootyBuildComplete:
handler: api/controllers/v1/jobs.SnootyBuildComplete
events:
- http:
path: /webhook/snooty/trigger/complete
method: POST
cors: true
environment:
<<: *webhook-env-core
v1GithubDeleteArtifacts:
handler: api/controllers/v1/github.MarkBuildArtifactsForDeletion
events:
- http:
path: /webhook/github/trigger/delete
method: POST
cors: true
environment:
<<: *webhook-env-core
Outputs:
JobsQueueURL:
Description: Jobs Queue Url
Value: ${self:custom.jobsQueueUrl}
Export:
Name: docs-worker-pool-${self:provider.stage}-jobs-queue
JobsUpdateQueueURL:
Description: Job updates Queue URL
Value: ${self:custom.jobUpdatesQueueUrl}
Export:
Name: docs-worker-pool-${self:provider.stage}-job-updates-queue