This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add cdn task to push static assets to S3
- Loading branch information
Showing
4 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ s3_website.yml | |
node_modules/ | ||
config/config.json | ||
public/rev-manifest.json | ||
.awspublish-static.sassmeister.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
var gulp = require('gulp'); | ||
var awspublish = require('gulp-awspublish'); | ||
var cloudfront = require('gulp-cloudfront-invalidate-aws-publish'); | ||
var gzip = require('gulp-gzip'); | ||
var config = require('../config').production | ||
|
||
gulp.task('cdn', function(callback) { | ||
if(! (process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY && process.env.AWS_S3_BUCKET && process.env.AWS_CLOUDFRONT_DISTRIBUTION_ID) ) { | ||
return callback(); | ||
} | ||
|
||
var aws = { | ||
region: 'us-west-2', | ||
key: process.env.AWS_ACCESS_KEY_ID, | ||
secret: process.env.AWS_SECRET_ACCESS_KEY, | ||
bucket: process.env.AWS_S3_BUCKET, | ||
distribution: process.env.AWS_CLOUDFRONT_DISTRIBUTION_ID | ||
}; | ||
|
||
var publisher = awspublish.create({ | ||
region: aws.region, | ||
accessKeyId: aws.key, | ||
secretAccessKey: aws.secret, | ||
params: { | ||
Bucket: aws.bucket | ||
} | ||
}); | ||
|
||
var cfSettings = { | ||
distribution: aws.distribution, | ||
accessKeyId: aws.key, | ||
secretAccessKey: aws.secret | ||
} | ||
|
||
return gulp.src(config.dest + '/**') | ||
.pipe(awspublish.gzip()) | ||
|
||
// publisher will add Content-Length, Content-Type and headers specified above | ||
// If not specified it will set x-amz-acl to public-read by default | ||
.pipe(publisher.publish(config.cdn.headers)) | ||
|
||
// print upload updates to console | ||
.pipe(awspublish.reporter({ | ||
states: ['create', 'update'] | ||
})) | ||
|
||
.pipe(cloudfront(cfSettings)); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters