forked from mozilla/brackets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invalidate.js
48 lines (43 loc) · 1.3 KB
/
invalidate.js
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
/**
* This file is a short script that invalidates
* the cloudfront edge caches for Thimble whenever
* we deploy a new version.
*/
var AWS = require('aws-sdk');
AWS.config.update({
// These variables are encrypted in the .travis.yml file
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
});
var cloudfront = new AWS.CloudFront();
// We can't do conditional logic in travis hooks, so
// we detect the branch we're on to deterimine whether to
// invalidate staging or prod
var invalidationPath;
var distribution;
if (process.env.TRAVIS_BRANCH === 'master') {
invalidationPath = '/bramble/staging/dist/*'
distribution = 'staging';
} else {
invalidationPath = '/bramble/production/dist/*'
distribution = 'production';
}
var params = {
DistributionId: process.env.CLOUDFRONT_DISTRIBUTION_ID,
InvalidationBatch: {
// Use the commit hash as the unique identifier for this invalidation
CallerReference: process.env.TRAVIS_COMMIT + '-' + distribution,
Paths: {
Quantity: 1,
Items: [ invalidationPath ]
}
}
};
cloudfront.createInvalidation(params, function(err, data) {
if (err) {
console.log(err, err.stack);
return process.exit(1);
}
console.log('Successfully invalidated CloudFront!\n', data);
process.exit(0);
});