-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
73 lines (64 loc) · 1.76 KB
/
gulpfile.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
let gulp = require('gulp');
let fs = require('fs');
let AWS = require('aws-sdk');
let gutil = require('gulp-util');
let using = require('gulp-using')
let async = require('async');
let environment = process.env.ENVIRONMENT || 'dev';
let appName = environment === 'production' ? process.env.APPNAME_PROD : process.env.APPNAME || 'TEST';
let bucketName = appName +"-"+environment;
let awsConfig = {
accessKeyId: environment === 'production' ? process.env.AWS_ACCESS_KEY_ID_PROD : process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: environment === 'production' ? process.env.AWS_SECRET_ACCESS_KEY_PROD : process.env.AWS_SECRET_ACCESS_KEY,
region: environment === 'production' ? process.env.AWS_REGION_PROD : process.env.AWS_REGION
}
AWS.config.update(awsConfig);
let gulps3 = require('gulp-s3-upload')(awsConfig);
gulp.task('s3-create', function(done) {
let s3 = new AWS.S3();
let policy = {
Version: '2012-10-17',
Statement: [{
Sid: 'Allow Public Access to All Objects',
Effect: 'Allow',
Principal: '*',
Action: 's3:GetObject',
Resource: 'arn:aws:s3:::' + bucketName + '/*'
}]
};
s3.createBucket({
Bucket: bucketName
}, function(err) {
if (err) {
throw new gutil.PluginError('deploy', err);
}
async.parallel([
s3.putBucketPolicy.bind(s3, {
Bucket: bucketName,
Policy: JSON.stringify(policy)
}),
s3.putBucketWebsite.bind(s3, {
Bucket: bucketName,
WebsiteConfiguration: {
IndexDocument: {
Suffix: 'index.html'
}
}
})
], function(err) {
if (err) {
throw new gutil.PluginError('deploy', err);
}
done();
});
});
});
gulp.task('deploy',['s3-create'], function(done) {
gulp.src("build/**/*")
.pipe(using())
.pipe(gulps3({
Bucket: bucketName,
ACL: 'public-read'
}))
});