Skip to content
This repository was archived by the owner on Nov 3, 2022. It is now read-only.

Commit c66cb7d

Browse files
authored
Merge pull request #69 from binoculars/develop
For v3.2.0
2 parents 88d4407 + 040a6c2 commit c66cb7d

File tree

10 files changed

+1389
-756
lines changed

10 files changed

+1389
-756
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ language: node_js
22
node_js: lts/boron
33
sudo: false
44
dist: trusty
5-
cache:
6-
directories:
7-
- node_modules
8-
- $HOME/.cache
5+
cache: yarn
6+
env:
7+
- FORCE_COLOR=1
98
before_install:
109
- |
1110
if [ -n "$TRAVIS_BRANCH" ]; then
@@ -26,6 +25,7 @@ before_install:
2625
export USE_GZIP=false
2726
export MIME_TYPES='{"png":"image/png","mp4":"video/mp4"}'
2827
export VIDEO_MAX_DURATION='30'
28+
- curl -o- -L https://yarnpkg.com/install.sh | bash
2929
before_script:
3030
- yarn global add gulp
3131
script:

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ node node_modules/babel-cli/bin/babel-node.js test/aws.js
8989
### Gulp
9090

9191
#### Task: `aws:create-cfn-bucket`
92-
Creates the CloudFormation for your CloudFormation template and Lambda function code. **Run this once**, the result of
93-
this goes in environment variable, `CFN_S3_BUCKET`
92+
Creates the CloudFormation for your CloudFormation template and Lambda function code. **Run this once**. Set the `CFN_S3_BUCKET` environment variable to the name of the bucket you want to create.
93+
```bash
94+
CFN_S3_BUCKET=cloudformation-bucket gulp aws:create-cfn-bucket
95+
```
9496

9597
#### Environment Settings
9698
The following environment variables must be set prior to using the rest of the gulp commands

gulpfile.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const buildDir = 'build';
1717
const filename = path.join(buildDir, 'ffmpeg-build-lambda.tar.gz');
1818
const releaseUrl = 'https://api.github.com/repos/binoculars/ffmpeg-build-lambda/releases/latest';
1919

20-
function request(url, toPipe) {
20+
function request(url, toPipe, retries = 0) {
2121
const options = parse(url);
2222
options.headers = {
2323
'User-Agent': 'node'
@@ -31,6 +31,22 @@ function request(url, toPipe) {
3131
if (statusCode === 302)
3232
return request(response.headers.location, toPipe);
3333

34+
if (statusCode === 403 && retries < 3)
35+
return new Promise((resolve, reject) => {
36+
const tryCount = retries + 1;
37+
38+
console.log(`Request failed, retrying ${tryCount} of 3`);
39+
40+
setTimeout(
41+
() => {
42+
return request(url, toPipe, tryCount)
43+
.then(resolve)
44+
.catch(reject);
45+
},
46+
3e3
47+
);
48+
});
49+
3450
return reject(new Error('Failed to load page, status code: ' + response.statusCode));
3551
}
3652

@@ -148,7 +164,16 @@ fs.readdirSync(baseDir)
148164
'env',
149165
{
150166
targets: {
151-
node: platform === 'aws' ? 6.10 : 6.9
167+
node: (() => {
168+
switch(platform) {
169+
case 'aws':
170+
return '6.10';
171+
case 'gcp':
172+
return '6.11';
173+
default:
174+
return 'current';
175+
}
176+
})()
152177
}
153178
}
154179
]

package.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
"version": "3.1.0",
44
"private": true,
55
"description": "AWS Lambda function to resize video and generate a thumbnail",
6-
"engines-strict": true,
76
"engines": {
8-
"node": ">=4.3",
7+
"node": ">=6.10",
98
"npm": ">=3"
109
},
1110
"main": "index.js",
@@ -26,24 +25,24 @@
2625
"author": "Barrett Harber",
2726
"license": "Unlicense",
2827
"devDependencies": {
29-
"ava": "^0.18.2",
28+
"ava": "^0.23.0",
3029
"aws-sdk-on-lambda": "binoculars/aws-sdk-js-on-lambda",
3130
"azure-storage": "^2.1.0",
32-
"babel-cli": "^6.23.0",
33-
"babel-preset-env": "^1.2.2",
34-
"chalk": "^1.1.3",
35-
"del": "^2.2.0",
36-
"google-cloud": "^0.49.0",
31+
"babel-cli": "^6.24.1",
32+
"babel-preset-env": "^1.6.1",
33+
"chalk": "^2.0.1",
34+
"del": "^3.0.0",
35+
"google-cloud": "^0.57.0",
3736
"gulp": "^3.9.1",
38-
"gulp-babel": "^6.1.2",
37+
"gulp-babel": "^7.0.0",
3938
"gulp-chmod": "^2.0.0",
4039
"gulp-install": "^1.1.0",
4140
"gulp-json-editor": "^2.2.1",
4241
"gulp-rename": "^1.2.2",
4342
"gulp-util": "^3.0.8",
4443
"gulp-zip": "^4.0.0",
45-
"run-sequence": "^1.0.2",
46-
"simple-git": "^1.67.0"
44+
"run-sequence": "^2.0.0",
45+
"simple-git": "^1.73.0"
4746
},
4847
"dependencies": {},
4948
"babel": {

platform/aws/cloudformation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"HasNoDestinationBucketName": {
6161
"Fn::Equals": [
6262
{
63-
"Ref": "SourceBucketName"
63+
"Ref": "DestinationBucketName"
6464
},
6565
""
6666
]

platform/aws/gulp-lib.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ function stackEventToRow({Timestamp, ResourceStatus, ResourceType, LogicalResour
7373
LogicalResourceId
7474
].map((val, i) => val.match(new RegExp(`.{1,${columns[i]}}`, 'g')));
7575

76-
const style = chalk.styles[
77-
getResourceStatusColor(ResourceStatus)
78-
];
76+
const color = getResourceStatusColor(ResourceStatus);
7977

8078
const maxLines = cells
8179
.reduce((acc, val) => val.length > acc ? val.length : acc, '');
@@ -87,11 +85,9 @@ function stackEventToRow({Timestamp, ResourceStatus, ResourceType, LogicalResour
8785

8886
for (let j = 0; j < cells.length; j++) {
8987
const isColored = j === 1;
90-
const open = isColored ? style.open : '';
91-
const close = isColored ? style.close : '';
9288
const value = pad(cells[j][i] || '', columns[j]);
9389

94-
line.push(`${open}${value}${close}`);
90+
line.push(isColored ? chalk[color](value) : value);
9591
}
9692

9793
lines.push(cellsToRow(line));

platform/aws/gulpfile.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function getCloudFormationOperation(StackName) {
4040
})
4141
.promise()
4242
.then(() => 'updateStack')
43-
.catch(() => 'createStack')
43+
.catch(() => 'createStack');
4444
}
4545

4646
function printEventsAndWaitFor(condition, StackName) {
@@ -131,6 +131,7 @@ module.exports = function(gulp, prefix) {
131131
['VideoMaxDuration', VIDEO_MAX_DURATION],
132132
CI ? ['ExecutionRoleManagedPolicyArn', EXECUTION_ROLE_ARN] : undefined
133133
]
134+
.filter(val => val)
134135
.map(([ParameterKey, ParameterValue]) => ({ParameterKey, ParameterValue}));
135136

136137
return getCloudFormationOperation(StackName)
@@ -167,9 +168,9 @@ module.exports = function(gulp, prefix) {
167168
LogicalResourceId: 'Lambda'
168169
})
169170
.promise()
170-
.then(({StackResourceDetail: PhysicalResourceId}) => lambda
171+
.then(({StackResourceDetail: {PhysicalResourceId: FunctionName}}) => lambda
171172
.updateFunctionCode({
172-
FunctionName: PhysicalResourceId,
173+
FunctionName,
173174
S3Bucket: Bucket,
174175
S3Key: lambdaKey
175176
})
@@ -178,30 +179,27 @@ module.exports = function(gulp, prefix) {
178179
);
179180

180181
// Builds the function and uploads
181-
gulp.task(`${prefix}:build-upload`, cb => runSequence(
182+
gulp.task(`${prefix}:build-upload`, () => runSequence(
182183
'clean',
183184
'download-ffmpeg',
184185
`${prefix}:source`,
185186
'npm',
186187
'untar-ffmpeg',
187188
'copy-ffmpeg',
188189
'zip',
189-
`${prefix}:upload`,
190-
cb
190+
`${prefix}:upload`
191191
));
192192

193193
// For an already created stack
194-
gulp.task(`${prefix}:update`, cb => runSequence(
194+
gulp.task(`${prefix}:update`, () => runSequence(
195195
`${prefix}:build-upload`,
196-
`${prefix}:updateCode`,
197-
cb
196+
`${prefix}:updateCode`
198197
));
199198

200199
// For a new stack (or you change cloudformation.json)
201-
gulp.task(`${prefix}:default`, cb => runSequence(
200+
gulp.task(`${prefix}:default`, () => runSequence(
202201
`${prefix}:build-upload`,
203-
`${prefix}:deployStack`,
204-
cb
202+
`${prefix}:deployStack`
205203
));
206204

207205
const ciStackName = `CI-for-${StackName}`;
@@ -274,7 +272,7 @@ module.exports = function(gulp, prefix) {
274272
})
275273
.promise()
276274
)
277-
.then(([{Stacks: Outputs}]) => console.log(
275+
.then(({Stacks: [{Outputs}]}) => console.log(
278276
Outputs
279277
.map(({OutputKey, OutputValue}) => `${outputEnvMap.get(OutputKey)}=${OutputValue}`)
280278
.join('\n')

platform/gcp/gulpfile.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ module.exports = function(gulp, prefix) {
4646
'deploy',
4747
'ffmpeg',
4848
'--entry-point', 'entryPoint',
49-
'--bucket', config.functionBucket,
50-
'--trigger-gs-uri', config.sourceBucket
49+
'--stage-bucket', config.functionBucket,
50+
'--trigger-bucket', config.sourceBucket
5151
],
5252
{
5353
cwd: './dist',
@@ -63,4 +63,4 @@ module.exports = function(gulp, prefix) {
6363
cb
6464
);
6565
});
66-
};
66+
};

test/unit/aws/gulp-lib.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ test('A one-line event', t => {
1414
};
1515

1616
const actual = stackEventToRow(stackEvent);
17-
18-
const {open, close} = chalk.styles.yellow;
1917
const expected = `
20-
│ 1970-01-01T00:00:00.000Z │ ${open}CREATE_IN_PROGRESS${close} │ AWS::CloudFormation::Stack │ username-aws-lambda-ffmpeg-tag-v240 │
18+
│ 1970-01-01T00:00:00.000Z │ ${chalk.yellow('CREATE_IN_PROGRESS')} │ AWS::CloudFormation::Stack │ username-aws-lambda-ffmpeg-tag-v240 │
2119
`.trim();
2220

2321
t.is(actual, expected);
@@ -35,12 +33,10 @@ test('A multi-line event', t => {
3533
};
3634

3735
const actual = stackEventToRow(stackEvent);
38-
39-
const {open, close} = chalk.styles.red;
4036
const expected = `
41-
│ 1970-01-01T00:00:00.000Z │ ${open}UPDATE_ROLLBACK_CO${close} │ AWS::CloudFormation::Stack │ username-aws-lambda-ffmpeg-branch-mas │
42-
│ │ ${open}MPLETE_CLEANUP_IN_${close} │ │ ter │
43-
│ │ ${open}PROGRESS ${close} │ │ │
37+
│ 1970-01-01T00:00:00.000Z │ ${chalk.red('UPDATE_ROLLBACK_CO')} │ AWS::CloudFormation::Stack │ username-aws-lambda-ffmpeg-branch-mas │
38+
│ │ ${chalk.red('MPLETE_CLEANUP_IN_')} │ │ ter │
39+
│ │ ${chalk.red('PROGRESS ')} │ │ │
4440
`.trim();
4541

4642
t.is(actual, expected);

0 commit comments

Comments
 (0)