Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit d5252db

Browse files
GuruPKKcasthewizgjchong25Grace Chong
authored
DOP-2764 Invalidating CDN (#606)
* DOP-2674 Cache Invalidation * * DOP-2713: Add environment information to slack notifications to help with troubleshooting (#610) Co-authored-by: Grace Chong <grace.chong@mongodb.com> Co-authored-by: Cassidy Schaufele <cassidyschaufele@gmail.com> Co-authored-by: gjchong25 <gjchong25@gmail.com> Co-authored-by: Grace Chong <grace.chong@mongodb.com>
1 parent 3ba631a commit d5252db

File tree

20 files changed

+1766
-115
lines changed

20 files changed

+1766
-115
lines changed

api/config/custom-environment-variables.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@
1919
"id": "FASTLY_DOCHUB_SERVICE_ID",
2020
"token": "FASTLY_DOCHUB_TOKEN"
2121
}
22-
}
22+
},
23+
"cdnClientID": "CDN_CLIENT_ID",
24+
"cdnClientSecret": "CDN_CLIENT_SECRET"
2325
}

api/config/default.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"maxRetries": 3,
2121
"retryDelay": 60,
2222
"commandOverride": ["node", "onDemandApp.js"],
23-
"subnets": ["subnet-8c3623f6", "subnet-a4ac73cf", "subnet-9e83fed2"],
23+
"subnets": ["subnet-0a142842e8f13a042", "subnet-0fba568cfd3839eee"],
2424
"parallel": {
2525
"enabled": true,
2626
"stg": {
@@ -43,5 +43,22 @@
4343
"id": "FASTLY_DOCHUB_SERVICE_ID",
4444
"token": "FASTLY_DOCHUB_TOKEN"
4545
}
46-
}
46+
},
47+
"prodDeploy": {
48+
"restrictedProdDeploy": true,
49+
"entitledSlackUsers": [
50+
"U0V6H55D2",
51+
"U0V2WGRFC",
52+
"U01S32X6GJV",
53+
"URF5PJS6Q",
54+
"U02HJ4P5MJS",
55+
"U015S53G8TT",
56+
"U01QVEWPL5B",
57+
"UKF72EJRF"
58+
]
59+
},
60+
"cdnInvalidationOauthScope": "mongodbcom-docs",
61+
"oauthTokenURL": "https://corp.mongodb.com/oauth2/aus4k4jv00hWjNnps297/v1/token",
62+
"grantType": "client_credentials",
63+
"oauthTokenPath": "docs/worker_pool/cdn/invalidator/token"
4764
}

api/controllers/v1/jobs.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ async function prepSummaryMessage(
166166
msg = `Your Job <${jobUrl}${jobId}|Failed>! Please check the build log for any errors.\n- Repo:*${repoName}*\n- Branch:*${fullDocument.payload.branchName}*\n- urlSlug: *${fullDocument.payload.urlSlug}*\n- Env:*${env}*\n Check logs for more errors!!\nSorry :disappointed:! `;
167167
} else {
168168
if (repoName == 'mms-docs') {
169-
msg = `Your Job <${jobUrl}${jobId}|Completed>! \n- Repo:*${repoName}*\n- Branch:*${fullDocument.payload.branchName}*\n- urlSlug: *${fullDocument.payload.urlSlug}*\n- Env:*${env}*\n*Urls*\n *CM*:<${mms_urls[0]}|Cloud Manager> \n *OPM*:<${mms_urls[1]}|OPS Manager> \nEnjoy :smile:!`;
169+
msg = `Your Job <${jobUrl}${jobId}|Completed>! \n- Repo:*${repoName}*\n- Branch:*${fullDocument.payload.branchName}*\n- urlSlug: *${fullDocument.payload.urlSlug}*\n- Env:*${env}*\n*Urls*\n *CM*:<${mms_urls[0]}|Cloud Manager> \n *OPM*:<${mms_urls[1]}|OPS Manager>\n- InvalidationStatus:<${fullDocument.invalidationStatusURL}|Status> \nEnjoy :smile:!`;
170170
} else {
171-
msg = `Your Job <${jobUrl}${jobId}|Completed>! \n- Repo:*${repoName}*\n- Branch:*${fullDocument.payload.branchName}*\n- urlSlug: *${fullDocument.payload.urlSlug}*\n- Env:*${env}*\n- Url:<${url}|${repoName}> \nEnjoy :smile:!`;
171+
msg = `Your Job <${jobUrl}${jobId}|Completed>! \n- Repo:*${repoName}*\n- Branch:*${fullDocument.payload.branchName}*\n- urlSlug: *${fullDocument.payload.urlSlug}*\n- Env:*${env}*\n- Url:<${url}|${repoName}>\n- InvalidationStatus:<${fullDocument.invalidationStatusURL}|Status> \nEnjoy :smile:!`;
172172
}
173173
}
174174
// Removes instances of two or more periods
@@ -177,15 +177,16 @@ async function prepSummaryMessage(
177177

178178
function prepProgressMessage(jobUrl: string, jobId: string, jobTitle: string, status: string): string {
179179
const msg = `Your Job (<${jobUrl}${jobId}|${jobTitle}>) `;
180+
const env = c.get<string>('env');
180181
switch (status) {
181182
case 'inQueue':
182-
return msg + 'has successfully been added to the queue.';
183+
return msg + 'has successfully been added to the ' + env + ' queue.';
183184
case 'inProgress':
184185
return msg + 'is now being processed.';
185186
case 'completed':
186187
return msg + 'has successfully completed.';
187188
case 'failed':
188-
return msg + 'has failed and will not be placed back in the queue.';
189+
return msg + 'has failed and will not be placed back in the ' + env + ' queue.';
189190
default:
190191
return msg + 'has been updated to an unsupported status.';
191192
}

api/controllers/v1/slack.ts

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ function isUserEntitled(entitlementsObject: any): boolean {
1010
return (entitlementsObject?.repos?.length ?? 0) > 0;
1111
}
1212

13+
function isRestrictedToDeploy(userId: string): boolean {
14+
const { restrictedProdDeploy, entitledSlackUsers } = c.get<any>('prodDeploy');
15+
return restrictedProdDeploy && !entitledSlackUsers.includes(userId);
16+
}
17+
1318
function prepReponse(statusCode, contentType, body) {
1419
return {
1520
statusCode: statusCode,
@@ -61,8 +66,12 @@ export const DisplayRepoOptions = async (event: any = {}, context: any = {}): Pr
6166
const branchRepository = new BranchRepository(db, c, consoleLogger);
6267
const key_val = getQSString(event.body);
6368
const entitlement = await repoEntitlementRepository.getRepoEntitlementsBySlackUserId(key_val['user_id']);
64-
if (!isUserEntitled(entitlement)) {
65-
return prepReponse(401, 'text/plain', 'User is not entitled!');
69+
if (!isUserEntitled(entitlement) || isRestrictedToDeploy(key_val['user_id'])) {
70+
const { restrictedProdDeploy } = c.get<any>('prodDeploy');
71+
const response = restrictedProdDeploy
72+
? 'Production freeze in place - please notify DOP if seeing this past 3/26'
73+
: 'User is not entitled!';
74+
return prepReponse(401, 'text/plain', response);
6675
}
6776
const entitledBranches = await buildEntitledBranchList(entitlement, branchRepository);
6877
const resp = await slackConnector.displayRepoOptions(entitledBranches, key_val['trigger_id']);
@@ -78,12 +87,7 @@ export const DisplayRepoOptions = async (event: any = {}, context: any = {}): Pr
7887
};
7988
};
8089

81-
async function deployRepo(
82-
deployable: Array<any>,
83-
logger: ILogger,
84-
jobRepository: JobRepository,
85-
jobQueueUrl
86-
) {
90+
async function deployRepo(deployable: Array<any>, logger: ILogger, jobRepository: JobRepository, jobQueueUrl) {
8791
try {
8892
await jobRepository.insertJBulkJobs(deployable, jobQueueUrl);
8993
} catch (err) {
@@ -92,14 +96,22 @@ async function deployRepo(
9296
}
9397

9498
// Used solely for adding parallel deploy jobs to another array
95-
const parallelPrefixDeployHelper = (deployable, payload, jobTitle, jobUserName, jobUserEmail, parallelPrefix = undefined, parallelDeployable = []) => {
99+
const parallelPrefixDeployHelper = (
100+
deployable,
101+
payload,
102+
jobTitle,
103+
jobUserName,
104+
jobUserEmail,
105+
parallelPrefix = undefined,
106+
parallelDeployable = []
107+
) => {
96108
deployable.push(createJob({ ...payload }, jobTitle, jobUserName, jobUserEmail));
97109
if (parallelPrefix) {
98110
const parallelPayload = { ...payload };
99111
parallelPayload.prefix = parallelPrefix;
100112
parallelDeployable.push(createJob(parallelPayload, jobTitle, jobUserName, jobUserEmail));
101-
}
102-
}
113+
}
114+
};
103115

104116
export const DeployRepo = async (event: any = {}, context: any = {}): Promise<any> => {
105117
const consoleLogger = new ConsoleLogger();
@@ -185,7 +197,15 @@ export const DeployRepo = async (event: any = {}, context: any = {}): Promise<an
185197
if (non_versioned) {
186198
newPayload.urlSlug = '';
187199
}
188-
parallelPrefixDeployHelper(deployable, newPayload, jobTitle, jobUserName, jobUserEmail, parallelPrefix, parallelDeployable);
200+
parallelPrefixDeployHelper(
201+
deployable,
202+
newPayload,
203+
jobTitle,
204+
jobUserName,
205+
jobUserEmail,
206+
parallelPrefix,
207+
parallelDeployable
208+
);
189209
jobCount += 1;
190210
}
191211
//if this is stablebranch, we want autobuilder to know this is unaliased branch and therefore can reindex for search
@@ -202,16 +222,40 @@ export const DeployRepo = async (event: any = {}, context: any = {}): Promise<an
202222
// we use the primary alias for indexing search, not the original branch name (ie 'master'), for aliased repos
203223
if (urlSlug) {
204224
newPayload.urlSlug = urlSlug;
205-
parallelPrefixDeployHelper(deployable, newPayload, jobTitle, jobUserName, jobUserEmail, parallelPrefix, parallelDeployable);
225+
parallelPrefixDeployHelper(
226+
deployable,
227+
newPayload,
228+
jobTitle,
229+
jobUserName,
230+
jobUserEmail,
231+
parallelPrefix,
232+
parallelDeployable
233+
);
206234
jobCount += 1;
207235
}
208236
if (non_versioned) {
209237
newPayload.urlSlug = '';
210-
parallelPrefixDeployHelper(deployable, newPayload, jobTitle, jobUserName, jobUserEmail, parallelPrefix, parallelDeployable);
238+
parallelPrefixDeployHelper(
239+
deployable,
240+
newPayload,
241+
jobTitle,
242+
jobUserName,
243+
jobUserEmail,
244+
parallelPrefix,
245+
parallelDeployable
246+
);
211247
jobCount += 1;
212248
} else if (publishOriginalBranchName) {
213249
newPayload.urlSlug = branchName;
214-
parallelPrefixDeployHelper(deployable, newPayload, jobTitle, jobUserName, jobUserEmail, parallelPrefix, parallelDeployable);
250+
parallelPrefixDeployHelper(
251+
deployable,
252+
newPayload,
253+
jobTitle,
254+
jobUserName,
255+
jobUserEmail,
256+
parallelPrefix,
257+
parallelDeployable
258+
);
215259
jobCount += 1;
216260
}
217261
aliases.forEach(async (alias) => {
@@ -220,7 +264,15 @@ export const DeployRepo = async (event: any = {}, context: any = {}): Promise<an
220264
newPayload.stable = '';
221265
newPayload.urlSlug = alias;
222266
newPayload.primaryAlias = primaryAlias;
223-
parallelPrefixDeployHelper(deployable, newPayload, jobTitle, jobUserName, jobUserEmail, parallelPrefix, parallelDeployable);
267+
parallelPrefixDeployHelper(
268+
deployable,
269+
newPayload,
270+
jobTitle,
271+
jobUserName,
272+
jobUserEmail,
273+
parallelPrefix,
274+
parallelDeployable
275+
);
224276
jobCount += 1;
225277
}
226278
});

config/custom-environment-variables.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,8 @@
5252
"id": "FASTLY_MAIN_SERVICE_ID",
5353
"token": "FASTLY_MAIN_TOKEN"
5454
}
55-
}
55+
},
56+
"cdnClientID": "CDN_CLIENT_ID",
57+
"cdnClientSecret": "CDN_CLIENT_SECRET",
58+
"cdnInvalidatorServiceURL": "CDN_INVALIDATOR_SERVICE_URL"
5659
}

config/default.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,9 @@
7878
"token": "FASTLY_MAIN_TOKEN"
7979
}
8080
},
81-
"repo_dir": "repos"
81+
"repo_dir": "repos",
82+
"cdnInvalidationOauthScope": "mongodbcom-docs",
83+
"oauthTokenURL": "https://corp.mongodb.com/oauth2/aus4k4jv00hWjNnps297/v1/token",
84+
"grantType": "client_credentials",
85+
"oauthTokenPath": "docs/worker_pool/cdn/invalidator/token"
8286
}

infrastructure/ecs-main/ecs_service.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Resources:
22
SecurityGroupVPC:
33
Type: 'AWS::EC2::SecurityGroup'
44
Properties:
5-
VpcId: vpc-781fab13
5+
VpcId: vpc-03701c29a3408c714
66
GroupDescription: 'Security group to VPC'
77

88
ECSCluster:
@@ -102,6 +102,13 @@ Resources:
102102
Value: ${self:custom.jobsQueueUrl}
103103
- Name: JOB_UPDATES_QUEUE_URL
104104
Value: ${self:custom.jobUpdatesQueueUrl}
105+
- Name: CDN_CLIENT_ID
106+
Value: ${self:custom.cdnClientID}
107+
- Name: CDN_CLIENT_SECRET
108+
Value: ${self:custom.cdnClientSecret}
109+
- Name: CDN_INVALIDATOR_SERVICE_URL
110+
Value: ${self:custom.cdnInvalidatorServiceURL.${self:provider.stage}}
111+
105112
LogConfiguration:
106113
LogDriver: awslogs
107114
Options:
@@ -146,4 +153,12 @@ Resources:
146153
Resource:
147154
- 'arn:aws:sqs:us-east-2:216656347858:autobuilder-job-updates-queue-${self:provider.stage}'
148155
- 'arn:aws:sqs:us-east-2:216656347858:autobuilder-jobs-queue-${self:provider.stage}'
156+
- PolicyName: AllowSSMAccess
157+
PolicyDocument:
158+
Version: '2012-10-17'
159+
Statement:
160+
- Effect: Allow
161+
Action:
162+
- 'ssm:GetParameter'
163+
Resource: "*"
149164

infrastructure/ecs-main/serverless.yml

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ provider:
1212
- "s3:DeleteObject"
1313
- "s3:PutObject"
1414
- "sqs:SendMessage"
15+
- "ssm:PutParameter"
16+
- "ssm:GetParameter"
1517
Resource:
1618
- "*"
1719
- Effect: Allow
@@ -27,9 +29,8 @@ provider:
2729
- 'Fn::GetAtt':
2830
- GroupId
2931
subnetIds:
30-
- subnet-8c3623f6
31-
- subnet-a4ac73cf
32-
- subnet-9e83fed2
32+
- subnet-0a142842e8f13a042
33+
- subnet-0fba568cfd3839eee
3334
custom:
3435
deploymentBucket:
3536
dev: worker-pool-deployment
@@ -41,17 +42,17 @@ custom:
4142
port: '80'
4243
imageUrl: ${self:custom.accountId.${self:provider.stage}}.dkr.ecr.us-east-2.amazonaws.com/${self:service}-${self:provider.stage}:latest
4344
containerCpu:
44-
dev: '4096'
45-
stg: '4096'
46-
prd: '4096'
47-
dotcomstg: '4096'
48-
dotcomprd: '4096'
45+
dev: '2048'
46+
stg: '2048'
47+
prd: '2048'
48+
dotcomstg: '2048'
49+
dotcomprd: '2048'
4950
containerMemory:
50-
dev: '24576'
51-
stg: '24576'
52-
prd: '24576'
53-
dotcomstg: '24576'
54-
dotcomprd: '24576'
51+
dev: '8192'
52+
stg: '8192'
53+
prd: '8192'
54+
dotcomstg: '8192'
55+
dotcomprd: '8192'
5556
desiredCount:
5657
dev: '4'
5758
stg: '4'
@@ -125,14 +126,27 @@ custom:
125126
entitlementCollection: ${ssm:/env/${self:provider.stage}/docs/worker_pool/atlas/collections/user/entitlements}
126127
jobsQueueUrl: ${docs-worker-pool-api-${self:provider.stage}.JobsQueueURL}
127128
jobUpdatesQueueUrl: ${docs-worker-pool-api-${self:provider.stage}.JobsUpdateQueueURL}
129+
cdnClientID: ${ssm:/env/${self:provider.stage}/docs/worker_pool/cdn/client/id}
130+
cdnClientSecret: ${ssm:/env/${self:provider.stage}/docs/worker_pool/cdn/client/secret}
131+
cdnInvalidatorServiceURL:
132+
stg: https://cdnvalidator.devops.staging.corp.mongodb.com/api/v1beta1/distributions/${self:custom.distributionName.${self:provider.stage}}/invalidations
133+
prd: https://cdnvalidator.devops.prod.corp.mongodb.com/api/v1beta1/distributions/${self:custom.distributionName.${self:provider.stage}}/invalidations
134+
dotcomstg: https://cdnvalidator.devops.staging.corp.mongodb.com/api/v1beta1/distributions/${self:custom.distributionName.${self:provider.stage}}/invalidations
135+
dotcomprd: https://cdnvalidator.devops.staging.corp.mongodb.com/api/v1beta1/distributions/${self:custom.distributionName.${self:provider.stage}}/invalidations
136+
dev: https://cdnvalidator.devops.staging.corp.mongodb.com/api/v1beta1/distributions/${self:custom.distributionName.${self:provider.stage}}/invalidations
137+
distributionName:
138+
stg: mongodbcom-staging-docs
139+
dotcomstg: mongodbcom-staging-docs
140+
dev: mongodbcom-staging-docs
141+
dotcomprd: mongodbcom-prod-docs
142+
prd: mongodbcom-prod-docs
128143
env:
129144
stg: "staging"
130145
prd: "production"
131146
dev: "staging"
132147
dotcomstg: "dotcomstg"
133148
dotcomprd: "dotcomprd"
134149

135-
136150
resources:
137151
- ${file(./buckets.yml)}
138152
- ${file(./ecs_service.yml)}

0 commit comments

Comments
 (0)