Skip to content

Update packaging to support individual packages per function - #1917

Merged
flomotlik merged 22 commits into
serverless:masterfrom
johncmckim:issue-1777
Sep 5, 2016
Merged

flomotlik merged 22 commits into
serverless:masterfrom
johncmckim:issue-1777

Conversation

@johncmckim

@johncmckim johncmckim commented Aug 21, 2016 •

Copy link
Copy Markdown
Contributor
Status:

Ready

Description:

Support per-function packages #1777

Todos:

@johncmckim

Copy link
Copy Markdown
Contributor Author

@flomotlik @pmuens this is ready for review when you're able.

@johncmckim johncmckim changed the title WIP: update packaging to support individual packages per function Update packaging to support individual packages per function Aug 29, 2016
@eahefnawy

eahefnawy commented Aug 31, 2016 •

Copy link
Copy Markdown
Contributor

@johncmckim pretty neat implementation! Thanks a lot! Unfortunately, based on my understanding of other providers, I think this plugin is only/mostly relevant to AWS. For example, Azure doesn't have a concept of "handlers" to begin with and functions need to be in the top level of the service. So I'm thinking the directory structure of other providers might be different and more rigid.

nonetheless, awesome PR! 💪 .... It'd be awesome if you could include the Sinon enhancements you mentioned in your TODOs (checking args, call counts..etc) to make the tests more precise. After that it's G2M ☺️

@johncmckim

Copy link
Copy Markdown
Contributor Author

@eahefnawy thanks for looking at it. I have updated the tests to check args.

I used the individually config option to allow this feature to be toggled on and off. It also allows other providers to throw if people try to turn it on.

I just realised I haven't updated the docs yet. If you're happy with the usability of the config, I'll update the docs.

@eahefnawy

Copy link
Copy Markdown
Contributor

Awesome! thanks a lot! yep I think they're good to go.

One other tiny thing, since it's packaging related (but not directly related to this PR), could you update the plugins/package/lib/cleanup.js to only cleanup if we're in a service folder? This would solve issue #1980... It should look something like this:

  cleanup() {
    if (this.serverless.config.servicePath) {
      const serverlessTmpDirPath = path.join(this.serverless.config.servicePath, '.serverless');
      if (this.serverless.utils.dirExistsSync(serverlessTmpDirPath)) {
        fse.removeSync(serverlessTmpDirPath);
      }
    }
    return BbPromise.resolve();
  },

Would be awesome to close this related issue as well with this PR 😊

@johncmckim

Copy link
Copy Markdown
Contributor Author

Can do. I'll update it tomorrow morning (AUS time).

@flomotlik

Copy link
Copy Markdown
Contributor

I thought about the individually flag a bit and while its not the best usability to have to set things in two locations it provides a nice feature for people to be able to turn individual deployment on or off and so easily test both. Otherwise they would have to go in and configure it separately.

And we can remove it easily in the future if we want to.

Still unsure about the union of service and function config, but I think its more often the case that people want to set something up that is a bit different from the general service config, than configure it completely separately. So I'm fine with the UX of it at the moment, we can learn from it and improve in the future once we understand it a little better. Thanks @johncmckim for getting this implemented

@johncmckim

Copy link
Copy Markdown
Contributor Author

@eahefnawy @flomotlik I've updated the docs and fixed that service path issue.

Let me know if there is anything else.

No worries. I've enjoyed contributing to this project. I think I will be getting busy soon, but hopefully I'll be able to find time to keep contributing to the project.

memorySize: 512 # optional, default is 1024
timeout: 10 # optional, default is 6
package: # optional requires individual function packaging to be enabled
include:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like include is mentioned twice here


it('should merge the IamRoleLambdaExecution template into the CloudFormation template', () => {
const IamRoleLambdaExecutionTemplate = awsCompileFunctions.serverless.utils.readFileSync(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if this whitespace could be removed

@pmuens pmuens added this to the v1.0.0-beta.3 milestone Sep 2, 2016
@pmuens

pmuens commented Sep 2, 2016

Copy link
Copy Markdown
Contributor

Hey @johncmckim thank you for this awesome PR! 👯

Just looked through it and added some (minor) comments.

Furthermore here's what else I saw / would like to discuss:

  • The uploadDeploymentPackate.js file includes logic to cleanup .zipped services in the S3 bucket. We've recently added a new file called cleanupS3Bucket.js which was dedicated to this task. Would be cool if the cleanup of individual .zip services could also live there so that the other file only handles upload logic
  • Could you remove the toS3Bucket (e.g. uploadZipFileToS3Bucket --> uploadZipFile) and the fromS3Bucket in the function names so that all functions follow the same naming (We've introduced this naming schema in the past but it's kind of verbose 😄 )?
  • We've recently merged the new resource logical Id naming. It seems like this PR is already up to date but it would be cool if you could re-check if the new resource logical Ids are used

Thanks in advance! And keep up the great work 🎉

@johncmckim

Copy link
Copy Markdown
Contributor Author

@pmuens Thanks for the review. I think I have resolved all those issues.

  • I deleted uploadDeploymentPackage.js as the functionality had already been moved into other files (outside this PR).
  • I renamed the uploadZipFileToS3Bucket to uploadZipFile as requested
  • If you're referring to the change for function names in the CloudFormationTemplates? i.e. Test to TestLambdaFunction ? This PR works with those changes. I just had to update some tests after I merged in those changes. I've tested deploying a project and it deployed successfully for me.

Let me know if you see anything else

@pmuens

pmuens commented Sep 4, 2016

Copy link
Copy Markdown
Contributor

@johncmckim thanks for the fixes! Looks good!

Great work you've done here! 👍 🎉

this.serverless.cli.log('Uploading .zip file to S3...');

const body = fs.readFileSync(this.serverless.service.package.artifact);
if (this.serverless.service.package.individually) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked and it looks like this part of the function isn't really covered from a test:

https://coveralls.io/builds/7732943/source?filename=lib%2Fplugins%2Faws%2Fdeploy%2Flib%2FuploadArtifacts.js#L31

Could you look into why this might be the case? Not sure if its simply not covered by the test or if there is some issue going on. I assume its simply a missing test where package.individually is set to true.

I'll also make sure that the code coverage is more visible for users

@johncmckim

Copy link
Copy Markdown
Contributor Author

Thanks @flomotlik. I thought I had covered that but it may have been removed in a previous merge. Updated the tests to cover 100% of that file.

I would have thought the status check would have failed with the reduced coverage?

@flomotlik

Copy link
Copy Markdown
Contributor

@johncmckim it only failed with -5% in the past, changed that to -0.1% now #makeitfail

Thanks for the quick edit, merging this now.

@flomotlik
flomotlik merged commit 1364f05 into serverless:master Sep 5, 2016
@johncmckim
johncmckim deleted the issue-1777 branch September 5, 2016 12:58
@flomotlik

Copy link
Copy Markdown
Contributor

@johncmckim awesome job on this again. Sorry for the back and forth, we're definitely working on making sure that we have less of that in the future!

@johncmckim

Copy link
Copy Markdown
Contributor Author

@flomotlik no worries. I'm happy to get the feedback and happy that there are responsive maintainers. Glad to get this in, it's been fun.

@nicka

nicka commented Sep 5, 2016

Copy link
Copy Markdown
Contributor

Perfect!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants