Skip to content

Commit

Permalink
Update the deploy script to deploy chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Nov 22, 2024
1 parent 58fafe1 commit 04a8db5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 34 deletions.
58 changes: 38 additions & 20 deletions scripts/deploy/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,48 @@ const uploadPathTypes = process.argv[4].split(',')
runMain(async () => {
const awsConfig = AWS_CONFIG[env]
let cloudfrontPathsToInvalidate = []
for (const { packageName } of packages) {
const bundleFolder = buildBundleFolder(packageName)
for (const uploadPathType of uploadPathTypes) {
let uploadPath
if (uploadPathType === 'pull-request') {
const pr = await fetchPR(LOCAL_BRANCH)
if (!pr) {
console.log('No pull requests found for the branch')
return
}
uploadPath = buildPullRequestUploadPath(packageName, pr.number)
} else if (uploadPathType === 'root') {
uploadPath = buildRootUploadPath(packageName, version)
} else {
uploadPath = buildDatacenterUploadPath(uploadPathType, packageName, version)
}
const bundlePath = `${bundleFolder}/${buildBundleFileName(packageName)}`
for (const { packageName, chunks } of packages) {
const pathsToInvalidate = await uploadPackage(awsConfig, packageName, chunks)
cloudfrontPathsToInvalidate.push(...pathsToInvalidate)
}
invalidateCloudfront(awsConfig, cloudfrontPathsToInvalidate)
})

async function uploadPackage(awsConfig, packageName, chunks) {
const cloudfrontPathsToInvalidate = []
const bundleFolder = buildBundleFolder(packageName)

for (const uploadPathType of uploadPathTypes) {
for (const chunkName of chunks) {
const uploadPath = await generateUploadPath(uploadPathType, chunkName, version)
const bundlePath = `${bundleFolder}/${buildBundleFileName(chunkName)}`

uploadToS3(awsConfig, bundlePath, uploadPath)
cloudfrontPathsToInvalidate.push(`/${uploadPath}`)
cloudfrontPathsToInvalidate.push(uploadPath)
}
}
invalidateCloudfront(awsConfig, cloudfrontPathsToInvalidate)
})

return cloudfrontPathsToInvalidate
}

async function generateUploadPath(uploadPathType, chunkName, version) {
let uploadPath

if (uploadPathType === 'pull-request') {
const pr = await fetchPR(LOCAL_BRANCH)
if (!pr) {
console.log('No pull requests found for the branch')
process.exit(0)
}
uploadPath = buildPullRequestUploadPath(chunkName, pr.number)
} else if (uploadPathType === 'root') {
uploadPath = buildRootUploadPath(chunkName, version)
} else {
uploadPath = buildDatacenterUploadPath(uploadPathType, chunkName, version)
}

return uploadPath
}

function uploadToS3(awsConfig, bundlePath, uploadPath) {
const accessToS3 = generateEnvironmentForRole(awsConfig.accountId, 'build-stable-browser-agent-artifacts-s3-write')
Expand Down
28 changes: 14 additions & 14 deletions scripts/deploy/lib/deploymentUtils.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
const packages = [
{ packageName: 'logs', service: 'browser-logs-sdk' },
{ packageName: 'rum', service: 'browser-rum-sdk' },
{ packageName: 'rum-slim', service: 'browser-rum-sdk' },
{ packageName: 'logs', chunks: ['datadog-logs'], service: 'browser-logs-sdk' },
{ packageName: 'rum', chunks: ['datadog-rum', 'recorder.datadog-rum'], service: 'browser-rum-sdk' },
{ packageName: 'rum-slim', chunks: ['datadog-rum-slim'], service: 'browser-rum-sdk' },
]

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

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

// ex: datadog-rum.js
const buildBundleFileName = (packageName, extension = 'js') => `datadog-${packageName}.${extension}`
// ex: datadog-rum.js, recorder.datadog-rum.js
const buildBundleFileName = (chunkName, extension = 'js') => `${chunkName}.${extension}`

// ex: pull-request/2781/datadog-rum.js, pull-request/2781/recorder.datadog-rum.js
const buildPullRequestUploadPath = (chunkName, version, extension = 'js') =>
`pull-request/${version}/${chunkName}.${extension}`

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

Expand Down

0 comments on commit 04a8db5

Please sign in to comment.