Permalink
Browse files

Maintain a copy of awspublish cache hashes in S3 for stateless deploys

  • Loading branch information...
lmorchard committed Oct 22, 2015
1 parent 4c029ab commit 4b525710760ad70c0d83d910585e7bd9ddd80583
Showing with 29 additions and 1 deletion.
  1. +1 −0 .travis.yml
  2. +26 −1 lib/tasks/deploy.js
  3. +2 −0 package.json
View
@@ -5,3 +5,4 @@ secure: "SwZ7AHBRv/QDTathr29XiVvKoB3l1uCzxXSye909I02ZhCiAo3+2+MkHzPaqNTq7Pf3dYuQ
script:
- ./node_modules/gulp/bin/gulp.js indexes
- ./node_modules/gulp/bin/gulp.js build
- ./node_modules/gulp/bin/gulp.js deploy
View
@@ -2,6 +2,9 @@ var gulp = require('gulp');
var gulpIf = require('gulp-if');
var parallelize = require("concurrent-transform");
var awspublish = require('gulp-awspublish');
var remoteSrc = require('gulp-remote-src');
var rename = require('gulp-rename');
var ignoreErrors = require('gulp-ignore-errors');
var config = require('../../config');
@@ -10,8 +13,22 @@ var GZIP_EXTENSIONS = [
'html', 'json', 'rss', 'css', 'js',
'otf', 'eot', 'svg', 'ttf', 'woff', 'woff2'
];
var HASHES_FILENAME = 'hashes.json';
gulp.task('deploy', function () {
gulp.task('deploy', ['deploy:push-hashes']);
gulp.task('deploy:pull-hashes', function () {
return remoteSrc([HASHES_FILENAME], { base: config.site.absolute_baseurl + '/' })
.on('error', function (err) {
// HACK: Ignore error if not found - this is probably the first run.
console.log(err.toString());
this.emit('end');
})
.pipe(rename('.awspublish-' + config.aws.bucket))
.pipe(gulp.dest('.'))
});
gulp.task('deploy:content', ['deploy:pull-hashes'], function () {
var isGzippable = function (file) {
var ext = file.path.split('.').pop();
@@ -26,3 +43,11 @@ gulp.task('deploy', function () {
.pipe(awspublish.reporter());
});
gulp.task('deploy:push-hashes', ['deploy:content'], function () {
var publisher = awspublish.create(config.aws);
return gulp.src('.awspublish-' + config.aws.bucket)
.pipe(rename(HASHES_FILENAME))
.pipe(publisher.publish({},{force: true}))
.pipe(awspublish.reporter());
});
View
@@ -23,9 +23,11 @@
"gulp-front-matter": "^1.0.0",
"gulp-if": "^1.2.5",
"gulp-ignore": "^2.0.1",
"gulp-ignore-errors": "0.0.4",
"gulp-imagemin": "^2.3.0",
"gulp-marked": "^1.0.0",
"gulp-minify-css": "^1.2.0",
"gulp-remote-src": "^0.4.0",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.0.1",
"gulp-util": "^3.0.1",

0 comments on commit 4b52571

Please sign in to comment.