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

Commit 5b836f2

Browse files
committed
Merge branch 'feature/env-vars' into develop, closes #20
2 parents 3b77fe6 + 8e64f69 commit 5b836f2

File tree

9 files changed

+315
-256
lines changed

9 files changed

+315
-256
lines changed

.travis.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ before_install:
1313
- |
1414
if [ -n "$TRAVIS_BRANCH" ]; then
1515
LOWER=${TRAVIS_BRANCH,,}
16-
export S3_PREFIX="branch-${LOWER//[^a-z0-9]}"
16+
export CFN_S3_PREFIX="branch-${LOWER//[^a-z0-9]}"
1717
fi
1818
1919
if [ -n "$TRAVIS_TAG" ]; then
2020
LOWER=${$TRAVIS_TAG,,}
21-
export S3_PREFIX="tag-${LOWER//[^a-z0-9]}"
21+
export CFN_S3_PREFIX="tag-${LOWER//[^a-z0-9]}"
2222
fi
2323
24-
export STACK_NAME="${TRAVIS_REPO_SLUG//[^-a-zA-Z]/-}-$S3_PREFIX"
24+
export STACK_NAME="${TRAVIS_REPO_SLUG//[^-a-zA-Z]/-}-$CFN_S3_PREFIX"
2525
export BUCKET_PREFIX="${STACK_NAME:0:59}"
26-
export BUILD_DIR="$TRAVIS_BUILD_DIR"
27-
$BUILD_DIR/test/integration/aws/config.sh
26+
export SOURCE_BUCKET="$BUCKET_PREFIX-src"
27+
export DESTINATION_BUCKET="$BUCKET_PREFIX-dst"
28+
export FFMPEG_ARGS=$'-c:a copy -vf scale=\'min(320\\,iw):-2\' -movflags +faststart -metadata description=http://my.site/$KEY_PREFIX.mp4 out.mp4 -vf thumbnail -vf scale=\'min(320\\,iw):-2\' -vframes 1 out.png'
29+
export USE_GZIP=false
30+
export MIME_TYPES='{"png":"image/png","mp4":"video/mp4"}'
31+
export VIDEO_MAX_DURATION='30'
2832
2933
before_script:
3034
- yarn global add gulp

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,37 @@ At minimum, you need to modify:
7373
export AWS_ACCESS_KEY_ID=AKIDEXAMPLE
7474
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY
7575
export AWS_REGION=us-east-1
76-
export CONFIG_FILE=../config/aws.json
76+
export DESTINATION_BUCKET=destination-bucket
77+
# Note that the following variable is single-quote escaped. Use $KEY_PREFIX to get the filename minus the extension.
78+
export FFMPEG_ARGS=$'-c:a copy -vf scale=\'min(320\\,iw):-2\' -movflags +faststart -metadata description=http://my.site/$KEY_PREFIX.mp4 out.mp4 -vf thumbnail -vf scale=\'min(320\\,iw):-2\' -vframes 1 out.png'
79+
export USE_GZIP=false
80+
export MIME_TYPES='{"png":"image/png","mp4":"video/mp4"}'
81+
export VIDEO_MAX_DURATION='30'
7782
# Node version
7883
nvm use 4.3.2 # This is subject to change
7984
# Babel-node test script
8085
node node_modules/babel-cli/bin/babel-node.js test/aws.js
8186
```
8287

8388
### Gulp
84-
Be sure to create your functionBucket first (e.g. `aws s3 mb s3://function-bucket` or in the console)
89+
90+
#### Task: `aws:create-cfn-bucket`
91+
Creates the CloudFormation for your CloudFormation template and Lambda function code. **Run this once**, the result of
92+
this goes in environment variable, `CFN_S3_BUCKET`
93+
94+
#### Environment Settings
95+
The following environment variables must be set prior to using the rest of the gulp commands
96+
97+
```bash
98+
export CFN_S3_BUCKET=cloudformation-bucket
99+
export SOURCE_BUCKET=source-bucket
100+
export DESTINATION_BUCKET=destination-bucket
101+
# Note that the following variable is single-quote escaped. Use $KEY_PREFIX to get the filename minus the extension.
102+
export FFMPEG_ARGS=$'-c:a copy -vf scale=\'min(320\\,iw):-2\' -movflags +faststart -metadata description=http://my.site/$KEY_PREFIX.mp4 out.mp4 -vf thumbnail -vf scale=\'min(320\\,iw):-2\' -vframes 1 out.png'
103+
export USE_GZIP=false # can be true or false
104+
export MIME_TYPES='{"png":"image/png","mp4":"video/mp4"}' # must be a JSON object with "extension": "mimeType" as the key/value pairs
105+
export VIDEO_MAX_DURATION='30' # must be a number
106+
```
85107

86108
#### Task: `aws:default`
87109
Everything you need to get started. Note: You can change the stack name by setting environment variable `STACK_NAME`.

config_samples/aws.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

platform/aws/cloudformation.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@
2323
"AllowedPattern": ".*\\.zip",
2424
"Description": "The S3 key for the lambda function code"
2525
},
26+
"FFmpegArgs": {
27+
"Type": "String",
28+
"Description": "The arguments for the FFmpeg command"
29+
},
30+
"MimeTypes": {
31+
"Type": "String",
32+
"Description": "A JSON map of extensions to MIME types"
33+
},
34+
"UseGzip": {
35+
"Type": "String",
36+
"AllowedPattern": "^(true|false)$",
37+
"Description": "Whether to use gzip or not"
38+
},
39+
"VideoMaxDuration": {
40+
"Type": "String",
41+
"AllowedPattern": "^\\d+(\\.\\d+)*$",
42+
"Default": "30",
43+
"Description": "The maximum duration of a video, in seconds"
44+
},
2645
"ExecutionRoleManagedPolicyArn": {
2746
"Type": "String",
2847
"Default": "",
@@ -170,6 +189,25 @@
170189
"Arn"
171190
]
172191
},
192+
"Environment": {
193+
"Variables": {
194+
"DESTINATION_BUCKET": {
195+
"Ref": "DestinationBucketName"
196+
},
197+
"FFMPEG_ARGS": {
198+
"Ref": "FFmpegArgs"
199+
},
200+
"USE_GZIP": {
201+
"Ref": "UseGzip"
202+
},
203+
"MIME_TYPES": {
204+
"Ref": "MimeTypes"
205+
},
206+
"VIDEO_MAX_DURATION": {
207+
"Ref": "VideoMaxDuration"
208+
}
209+
}
210+
},
173211
"Timeout": 30,
174212
"Handler": "aws/index.handler",
175213
"Runtime": "nodejs4.3",

platform/aws/gulpfile.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,11 @@ const cloudFormation = new AWS.CloudFormation();
1212
const packageInfo = require('../../package.json');
1313
const lib = require('./gulp-lib');
1414

15-
let config = {};
16-
try {
17-
config = require('../../config/aws.json');
18-
} catch (ex) {
19-
config = {};
20-
}
21-
22-
const Bucket = process.env.S3_BUCKET || config.functionBucket;
23-
const s3Prefix = process.env.S3_PREFIX || packageInfo.name;
15+
const Bucket = process.env.CFN_S3_BUCKET;
16+
const s3Prefix = process.env.CFN_S3_PREFIX || packageInfo.name;
2417
const templateKey = `${s3Prefix}/cloudformation.template`;
2518
const lambdaKey = `${s3Prefix}/lambda.zip`;
2619
const StackName = process.env.STACK_NAME || packageInfo.name;
27-
const bucketPrefix = process.env.BUCKET_PREFIX;
28-
const sourceBucket = process.env.CI ? `${bucketPrefix}-src` : config.sourceBucket;
29-
const destinationBucket = process.env.CI ? `${bucketPrefix}-dst` : config.destinationBucket;
3020
const now = new Date();
3121

3222
function getCloudFormationOperation(StackName) {
@@ -117,11 +107,11 @@ module.exports = function(gulp, prefix) {
117107
const Parameters = [
118108
{
119109
ParameterKey: 'SourceBucketName',
120-
ParameterValue: sourceBucket
110+
ParameterValue: process.env.SOURCE_BUCKET
121111
},
122112
{
123113
ParameterKey: 'DestinationBucketName',
124-
ParameterValue: destinationBucket
114+
ParameterValue: process.env.DESTINATION_BUCKET
125115
},
126116
{
127117
ParameterKey: 'LambdaS3Bucket',
@@ -130,6 +120,22 @@ module.exports = function(gulp, prefix) {
130120
{
131121
ParameterKey: 'LambdaS3Key',
132122
ParameterValue: lambdaKey
123+
},
124+
{
125+
ParameterKey: 'FFmpegArgs',
126+
ParameterValue: process.env.FFMPEG_ARGS
127+
},
128+
{
129+
ParameterKey: 'UseGzip',
130+
ParameterValue: process.env.USE_GZIP
131+
},
132+
{
133+
ParameterKey: 'MimeTypes',
134+
ParameterValue: process.env.MIME_TYPES
135+
},
136+
{
137+
ParameterKey: 'VideoMaxDuration',
138+
ParameterValue: process.env.VIDEO_MAX_DURATION
133139
}
134140
];
135141

@@ -221,7 +227,7 @@ module.exports = function(gulp, prefix) {
221227
['CIRegion', 'AWS_REGION'],
222228
['ServiceRoleArn', 'CLOUDFORMATION_ROLE_ARN'],
223229
['ModulePolicyArn', 'EXECUTION_ROLE_ARN'],
224-
['Bucket', 'S3_BUCKET']
230+
['Bucket', 'CFN_S3_BUCKET']
225231
]);
226232

227233
return Promise
@@ -293,4 +299,12 @@ module.exports = function(gulp, prefix) {
293299
.join('\n')
294300
))
295301
});
302+
303+
gulp.task(`${prefix}:create-cfn-bucket`, () => s3
304+
.createBucket({
305+
Bucket
306+
})
307+
.promise()
308+
.catch(console.error)
309+
);
296310
};

0 commit comments

Comments
 (0)