-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgulpfile.js
More file actions
139 lines (118 loc) · 3.6 KB
/
gulpfile.js
File metadata and controls
139 lines (118 loc) · 3.6 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var http = require('http');
var fs = require('fs');
var gulp = require('gulp');
var shell = require('gulp-shell');
var flatten = require('gulp-flatten');
var gutil = require('gulp-util');
var del = require('del');
var rename = require('gulp-rename');
var install = require('gulp-install');
var zip = require('gulp-zip');
var AWS = require('aws-sdk');
var runSequence = require('run-sequence');
var filename = './build/ffmpeg-git-64bit-static.tar.xz';
gulp.task('download-ffmpeg', function(cb) {
var file = fs.createWriteStream(filename);
http.get('http://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz', function(response) {
response.pipe(file);
file.on('finish', function() {
file.close();
cb();
})
});
});
gulp.task('untar-ffmpeg', shell.task([
'tar -xvf ' + filename + ' -C ./build'
]));
// This is still buggy
gulp.task('copy-ffmpeg', ['download-ffmpeg', 'untar-ffmpeg'], function() {
gulp.src('build/ffmpeg-*/ffmpeg')
.pipe(flatten())
.pipe(gulp.dest('./dist'));
});
/*
From: https://medium.com/@AdamRNeary/a-gulp-workflow-for-amazon-lambda-61c2afd723b6
*/
// First we need to clean out the dist folder and remove the compiled zip file.
gulp.task('clean', function(cb) {
//del('./build/*');
del('./dist',
del('./dist.zip', cb)
);
});
// The js task could be replaced with gulp-coffee as desired.
gulp.task('js', function() {
gulp.src(['index.js', 'config.json'])
.pipe(gulp.dest('dist/'))
});
// Here we want to install npm packages to dist, ignoring devDependencies.
gulp.task('npm', function() {
gulp.src('./package.json')
.pipe(gulp.dest('./dist/'))
.pipe(install({production: true}));
});
// Next copy over environment variables managed outside of source control.
gulp.task('env', function() {
gulp.src('./config.env.production')
.pipe(rename('.env'))
.pipe(gulp.dest('./dist'))
});
// Now the dist directory is ready to go. Zip it.
gulp.task('zip', function() {
gulp.src(['dist/**/*', '!dist/package.json', 'dist/.*'])
.pipe(zip('dist.zip'))
.pipe(gulp.dest('./'));
});
// Per the gulp guidelines, we do not need a plugin for something that can be
// done easily with an existing node module. #CodeOverConfig
//
// Note: This presumes that AWS.config already has credentials. This will be
// the case if you have installed and configured the AWS CLI.
//
// See http://aws.amazon.com/sdk-for-node-js/
gulp.task('upload', function() {
AWS.config.region = 'us-east-1';
var lambda = new AWS.Lambda();
var functionName = require('./package.json').name;
lambda.getFunction({FunctionName: functionName}, function(err, data) {
if (err) {
var warning;
if (err.statusCode === 404) {
warning = 'Unable to find lambda function ' + deploy_function
+ '. Verify the lambda function name and AWS region are correct.';
} else {
warning = 'AWS API request failed. Check your AWS credentials and permissions.';
}
gutil.log(warning);
}
// This is a bit silly, simply because these five parameters are required.
var current = data.Configuration;
var params = {
FunctionName: functionName,
Handler: current.Handler,
Mode: current.Mode,
Role: current.Role,
Runtime: current.Runtime
};
fs.readFile('./dist.zip', function(err, data) {
params['FunctionZip'] = data;
lambda.uploadFunction(params, function(err, data) {
if (err) {
var warning = 'Package upload failed. ';
warning += 'Check your iam:PassRole permissions.';
gutil.log(warning);
}
});
});
});
});
gulp.task('default', function(callback) {
return runSequence(
['clean'],
['copy-ffmpeg'],
['js', 'npm', 'env'],
['zip'],
//['upload'],
callback
);
});