Skip to content

Commit

Permalink
Merge pull request #65 from developmentseed/v2.2.3
Browse files Browse the repository at this point in the history
fix the corrupt zip file bug
  • Loading branch information
Alireza authored Jul 27, 2018
2 parents 5623272 + fdea25a commit f567536
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
9 changes: 7 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ jobs:

- run:
name: Install
command: |
npm install
command: npm install

- run:
name: Lint
command: |
./node_modules/.bin/eslint src --ext .js
./node_modules/.bin/eslint bin --ext .js
# save cahce
- save_cache:
key: deploy-{{ .Branch }}-{{ checksum "package.json" }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ build
dist
cloudformation.yml
myNestedTemplate.yml

yarn.lock
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v2.2.3
- Fix a bug where corrupt zip files were created and uploaded to S3 when the source file didn't exist

## v2.2.2
- allow plus in the apigateway path to support the new proxy resource

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kes",
"version": "2.2.2",
"version": "2.2.3",
"description": "Making deployment to AWS using CloudFormation easier and fun",
"scripts": {
"html-docs": "documentation build bin/cli.js -f html -o _docs --theme node_modules/documentation-devseed-theme",
Expand Down
1 change: 0 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const get = require('lodash.get');
const has = require('lodash.has');
const values = require('lodash.values');
const startsWith = require('lodash.startswith');
const trim = require('lodash.trim');
const replace = require('lodash.replace');
const upperFirst = require('lodash.upperfirst');
const capitalize = require('lodash.capitalize');
Expand Down
47 changes: 32 additions & 15 deletions src/lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ class Lambda {

// skip if the file with the same hash is zipped
if (fs.existsSync(lambda.local)) {
return Promise.resolve(lambda);
const stats = fs.statSync(lambda.local);
if (stats.isFile() && stats.size > 0) {
return Promise.resolve(lambda);
}
}

return utils.zip(lambda.local, [lambda.source]).then(() => {
Expand Down Expand Up @@ -131,7 +134,10 @@ class Lambda {
s3.headObject({
Bucket: this.bucket,
Key: lambda.remote
}).promise().then(() => {
}).promise().then((data) => {
if (data.ContentLength !== params.Body.byteLength) {
throw new Error('File sizes don\'t match');
}
console.log(`Already Uploaded: s3://${this.bucket}/${lambda.remote}`);
return resolve(lambda);
}).catch(() => {
Expand All @@ -153,7 +159,8 @@ class Lambda {
* @returns {Promise} returns the promise of updated lambda object
*/
zipAndUploadLambda(lambda) {
return this.zipLambda(lambda).then(l => this.uploadLambda(l));
return this.zipLambda(lambda)
.then(l => this.uploadLambda(l));
}

/**
Expand Down Expand Up @@ -196,19 +203,29 @@ class Lambda {
});
const jobs = Object.keys(uniqueHashes).map(l => this.zipAndUploadLambda(uniqueHashes[l]));

return Promise.all(jobs).then(() => {
// we handle lambdas as both arrays and key/objects
// below condition is intended to for cases where
// the lambda is returned as a lsit
if (Array.isArray(this.config.lambdas)) {
this.config.lambdas = lambdas;
return Promise.all(jobs)
.then(() => {
// we handle lambdas as both arrays and key/objects
// below condition is intended to for cases where
// the lambda is returned as a list
if (Array.isArray(this.config.lambdas)) {
this.config.lambdas = lambdas;
return this.config;
}
const tmp = {};
lambdas.forEach(l => (tmp[l.name] = l));
this.config.lambdas = tmp;
return this.config;
}
const tmp = {};
lambdas.forEach(l => (tmp[l.name] = l));
this.config.lambdas = tmp;
return this.config;
});
})
.catch((e) => {
// if the zip operation stops for any of the lambdas because the source
// file is missing, zip files with the size of 0 are created. Removing
// the build folder ensures that we start fresh in the next round of zipping
if (e.message.includes('ENOENT')) {
fs.removeSync(this.buildFolder);
}
throw e;
});
}
else return Promise.resolve(this.config);
}
Expand Down

0 comments on commit f567536

Please sign in to comment.