Skip to content

Commit 04a8db5

Browse files
committed
Update the deploy script to deploy chunks
1 parent 58fafe1 commit 04a8db5

File tree

2 files changed

+52
-34
lines changed

2 files changed

+52
-34
lines changed

scripts/deploy/deploy.js

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,48 @@ const uploadPathTypes = process.argv[4].split(',')
3939
runMain(async () => {
4040
const awsConfig = AWS_CONFIG[env]
4141
let cloudfrontPathsToInvalidate = []
42-
for (const { packageName } of packages) {
43-
const bundleFolder = buildBundleFolder(packageName)
44-
for (const uploadPathType of uploadPathTypes) {
45-
let uploadPath
46-
if (uploadPathType === 'pull-request') {
47-
const pr = await fetchPR(LOCAL_BRANCH)
48-
if (!pr) {
49-
console.log('No pull requests found for the branch')
50-
return
51-
}
52-
uploadPath = buildPullRequestUploadPath(packageName, pr.number)
53-
} else if (uploadPathType === 'root') {
54-
uploadPath = buildRootUploadPath(packageName, version)
55-
} else {
56-
uploadPath = buildDatacenterUploadPath(uploadPathType, packageName, version)
57-
}
58-
const bundlePath = `${bundleFolder}/${buildBundleFileName(packageName)}`
42+
for (const { packageName, chunks } of packages) {
43+
const pathsToInvalidate = await uploadPackage(awsConfig, packageName, chunks)
44+
cloudfrontPathsToInvalidate.push(...pathsToInvalidate)
45+
}
46+
invalidateCloudfront(awsConfig, cloudfrontPathsToInvalidate)
47+
})
48+
49+
async function uploadPackage(awsConfig, packageName, chunks) {
50+
const cloudfrontPathsToInvalidate = []
51+
const bundleFolder = buildBundleFolder(packageName)
52+
53+
for (const uploadPathType of uploadPathTypes) {
54+
for (const chunkName of chunks) {
55+
const uploadPath = await generateUploadPath(uploadPathType, chunkName, version)
56+
const bundlePath = `${bundleFolder}/${buildBundleFileName(chunkName)}`
5957

6058
uploadToS3(awsConfig, bundlePath, uploadPath)
61-
cloudfrontPathsToInvalidate.push(`/${uploadPath}`)
59+
cloudfrontPathsToInvalidate.push(uploadPath)
6260
}
6361
}
64-
invalidateCloudfront(awsConfig, cloudfrontPathsToInvalidate)
65-
})
62+
63+
return cloudfrontPathsToInvalidate
64+
}
65+
66+
async function generateUploadPath(uploadPathType, chunkName, version) {
67+
let uploadPath
68+
69+
if (uploadPathType === 'pull-request') {
70+
const pr = await fetchPR(LOCAL_BRANCH)
71+
if (!pr) {
72+
console.log('No pull requests found for the branch')
73+
process.exit(0)
74+
}
75+
uploadPath = buildPullRequestUploadPath(chunkName, pr.number)
76+
} else if (uploadPathType === 'root') {
77+
uploadPath = buildRootUploadPath(chunkName, version)
78+
} else {
79+
uploadPath = buildDatacenterUploadPath(uploadPathType, chunkName, version)
80+
}
81+
82+
return uploadPath
83+
}
6684

6785
function uploadToS3(awsConfig, bundlePath, uploadPath) {
6886
const accessToS3 = generateEnvironmentForRole(awsConfig.accountId, 'build-stable-browser-agent-artifacts-s3-write')

scripts/deploy/lib/deploymentUtils.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
const packages = [
2-
{ packageName: 'logs', service: 'browser-logs-sdk' },
3-
{ packageName: 'rum', service: 'browser-rum-sdk' },
4-
{ packageName: 'rum-slim', service: 'browser-rum-sdk' },
2+
{ packageName: 'logs', chunks: ['datadog-logs'], service: 'browser-logs-sdk' },
3+
{ packageName: 'rum', chunks: ['datadog-rum', 'recorder.datadog-rum'], service: 'browser-rum-sdk' },
4+
{ packageName: 'rum-slim', chunks: ['datadog-rum-slim'], service: 'browser-rum-sdk' },
55
]
66

7-
// ex: datadog-rum-v4.js
8-
const buildRootUploadPath = (packageName, version, extension = 'js') => `datadog-${packageName}-${version}.${extension}`
7+
// ex: datadog-rum-v4.js, recorder.datadog-rum-v4.js
8+
const buildRootUploadPath = (chunkName, version, extension = 'js') => `${chunkName}-${version}.${extension}`
99

10-
// ex: us1/v4/datadog-rum.js
11-
const buildDatacenterUploadPath = (datacenter, packageName, version, extension = 'js') =>
12-
`${datacenter}/${version}/datadog-${packageName}.${extension}`
10+
// ex: us1/v4/datadog-rum.js, eu1/v4/recorder.datadog-rum.js
11+
const buildDatacenterUploadPath = (datacenter, chunkName, version, extension = 'js') =>
12+
`${datacenter}/${version}/${chunkName}.${extension}`
1313

14-
// ex: datadog-rum.js
15-
const buildBundleFileName = (packageName, extension = 'js') => `datadog-${packageName}.${extension}`
14+
// ex: datadog-rum.js, recorder.datadog-rum.js
15+
const buildBundleFileName = (chunkName, extension = 'js') => `${chunkName}.${extension}`
16+
17+
// ex: pull-request/2781/datadog-rum.js, pull-request/2781/recorder.datadog-rum.js
18+
const buildPullRequestUploadPath = (chunkName, version, extension = 'js') =>
19+
`pull-request/${version}/${chunkName}.${extension}`
1620

17-
// ex: pull-request/2781/datadog-rum.js
18-
function buildPullRequestUploadPath(packageName, version, extension = 'js') {
19-
return `pull-request/${version}/datadog-${packageName}.${extension}`
20-
}
2121
// ex: packages/rum/bundle
2222
const buildBundleFolder = (packageName) => `packages/${packageName}/bundle`
2323

0 commit comments

Comments
 (0)