1
0
mirror of https://github.com/kremalicious/blog.git synced 2025-02-14 21:10:25 +01:00

deploy everything to S3 bucket

- switch to hosting full site on S3
- remove CDN URL injection
- remove rsync deployment
This commit is contained in:
Matthias Kretschmann 2016-04-15 23:18:33 +02:00
parent 32ef1c74c0
commit 44e4b9ec6c
Signed by: m
GPG Key ID: BD3C1F3EDD7831FC
3 changed files with 54 additions and 72 deletions

View File

@ -3,25 +3,11 @@
set -e;
echo "$(tput setaf 136)"
echo " Starting assets CDN "
echo " Starting S3 deployment "
echo "============================================="
echo "$(tput sgr0)" # reset
gulp s3:assets
gulp cdn
echo "$(tput setaf 64)" # green
echo "---------------------------------------------"
echo " ✓ done assets CDN"
echo "$(tput sgr0)" # reset
echo "$(tput setaf 136)"
echo " Starting rsync deployment "
echo "============================================="
echo "$(tput sgr0)" # reset
rsync --recursive --delete --delete-excluded --checksum --verbose -e "ssh" ~/src/github.com/kremalicious/kremalicious3/_site/ $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH
gulp deploy
echo "$(tput setaf 64)" # green
echo "---------------------------------------------"

View File

@ -49,8 +49,6 @@ var COMPATIBILITY = ['last 2 versions', 'ie >= 9'];
// paths
var SRC = '_src',
DIST = '_site',
//CDN = 'https://cdn.kremalicious.com',
CDN = 'https://d2jlreog722xe2.cloudfront.net',
S3BUCKET = 'kremalicious.com',
S3PATH = '/',
S3REGION = 'eu-central-1';
@ -307,60 +305,6 @@ gulp.task('rev:replace', function() {
});
//
// CDN url injection
//
gulp.task('cdn', function() {
return gulp.src([
DIST + '/**/*.html',
DIST + '/assets/css/*.css'
], { base: DIST })
.pipe($.replace('/assets/css/', CDN + '/assets/css/'))
.pipe($.replace('/assets/js/', CDN + '/assets/js/'))
//.pipe($.replace('/assets/img/', CDN + '/assets/img/'))
.pipe($.replace('/media/', CDN + '/media/'))
.pipe($.replace('https://kremalicious.com/media/', CDN + '/media/'))
.pipe($.replace('https://kremalicious.com' + CDN + '/media/', CDN + '/media/'))
.pipe($.replace('../', CDN + '/assets/'))
.pipe(gulp.dest(DIST))
});
//
// Assets uploading to S3
//
gulp.task('s3:assets', function() {
var publisher = $.awspublish.create({
params: {
'Bucket': S3BUCKET
},
'accessKeyId': process.env.AWS_ACCESS_KEY_ID,
'secretAccessKey': process.env.AWS_SECRET_ACCESS_KEY,
'region': S3REGION
});
// define custom headers
var headers = {
'Cache-Control': 'max-age=315360000, no-transform, public',
'x-amz-acl': 'public-read'
};
var assets = gulp.src(DIST + '/assets/**/*', { base: DIST + '/' }),
media = gulp.src(DIST + '/media/**/*', { base: DIST + '/' });
return merge(assets, media)
.pipe($.rename(function (path) {
// This is weird, but is needed to make the file use the relative path...
}))
.pipe($.awspublish.gzip({ ext: '' })) // gzip all the things
.pipe(parallelize(publisher.publish(headers), 10))
//.pipe(publisher.sync()) // delete files in bucket that are not in local folder
.pipe($.awspublish.reporter({
states: ['create', 'update', 'delete']
}));
});
//
// Dev Server
//
@ -409,3 +353,54 @@ gulp.task('build', function(done) {
done
);
});
//
// Deploy to S3
//
gulp.task('deploy', function() {
// create publisher, define config
var publisher = $.awspublish.create({
params: {
"Bucket": S3BUCKET
},
"accessKeyId": process.env.AWS_ACCESS_KEY,
"secretAccessKey": process.env.AWS_SECRET_KEY,
"region": S3REGION
});
return gulp.src(DIST + '**/*')
.pipe($.awspublishRouter({
cache: {
// cache for 5 minutes by default
cacheTime: 300
},
routes: {
// all static assets, cached & gzipped
'^assets/(?:.+)\\.(?:js|css|png|jpg|jpeg|gif|ico|svg|ttf)$': {
cacheTime: 2592000, // cache for 1 month
gzip: true
},
// every other asset, cached
'^assets/.+$': {
cacheTime: 2592000 // cache for 1 month
},
// all html files, not cached & gzipped
'^.+\\.html': {
cacheTime: 0,
gzip: true
},
// pass-through for anything that wasn't matched by routes above, to be uploaded with default options
"^.+$": "$&"
}
}))
.pipe(parallelize(publisher.publish({}, 'force'), 10))
.pipe(publisher.sync()) // delete files in bucket that are not in local folder
.pipe($.awspublish.reporter({
states: ['create', 'update', 'delete']
}));
});

View File

@ -30,6 +30,7 @@
"gulp": ">=3.8.0",
"gulp-autoprefixer": ">=2.3.0",
"gulp-awspublish": ">=2.0.2",
"gulp-awspublish-router": "^0.1.1",
"gulp-concat": ">=2.5.2",
"gulp-cssmin": ">=0.1.7",
"gulp-filter": ">=2.0.2",