Skip to content

Rework include/exclude #2460

Closed
Closed

Description

@mthenw

This is a Feature Proposal

Description

Current solution is super confusing. After reading docs I have no idea how this thing works and what to expect. It's also not obvious for users:

Solution: .serverlessignore

Instead of reinventing the wheel we should use well-known solution used by git, npm, eslint and many many other tools out there.

User should be able to place this file in a root dir or any other dir, exactly the same as .gitignore.

eslint is using this module https://www.npmjs.com/package/ignore (3,016,506 downloads in the last month). I think we could also use that.

Activity

  1. eahefnawy commented on Oct 19, 2016

    @eahefnawy
    Contributor

    👍 👍 👍 👍 👍 👍

  2. nikgraf commented on Oct 19, 2016

    @nikgraf
    Contributor

    I like the idea of being consistent within these common tools. No matter if you are coming from Java, Node or Python .gitignore is familiar.

    The downside clearly is that not all config is rooted in one serverless.yaml which has a big benefit in terms of clarity (single source of truth). @mthenw how do you feel about that?

  3. mthenw commented on Oct 19, 2016

    @mthenw
    ContributorAuthor

    The downside clearly is that not all config is rooted in one serverless.yaml which has a big benefit in terms of clarity (single source of truth). @mthenw how do you feel about that?

    I prefer following known patters (because users already know them) especially if the goal is to achieve exactly the same feature.

    Other option would be to simplify current mechanism and replace include/exclude with ignore.

    package:
      ignore:
        - *.jsx
        - !test.jsx
    

    So the same filtering mechanism as in .gitignore but inside serverless.yml.

    I personally prefer .serverlessignore because it's more obvious when I looks at list of files in project. I automatically understand what is inside.

    My goal here is to reduce confusion.

  4. mthenw commented on Oct 19, 2016

    @mthenw
    ContributorAuthor

    Also the great benefit of .serverlessignore is that you can place those files deep in the folder structure. It's sometimes helpful to place ignorefile closer to excluded files.

  5. austencollins commented on Oct 19, 2016

    @austencollins
    Member

    Thx @mthenw. I'm not sure how package.exclude works either. It was pretty straightforward in V.0. The docs aren't helping. ATM, I'm still in the serverless.yml camp. Here's why:

    • We've had that as a standard since V0, so it's what our users expect.
    • There is a large audience who use include, which we still need support for, and now this will create a different experience in how you exclude things. Creating a happenstances/divergences in how stuff happens is always an anti-pattern for me. Include is being used often for including files/folders that are outside the service root. Like large JSON/data files, etc., which could exist in a parent directory and several services depend on.
    • This would remove the ability to set packaging excludes at the function level. Since we have chosen to go down the route of zipping up the entire service, a lot of people complain about unnecessary function bloat. Removing their option to exclude on a function basis would severely add to that problem.
    • imo codebases are getting polluted with too many .files. Just my opinion, but I'm tired of seeing and learning what all these dot files are about. OCD.

    imo, the solution is not to create an entirely different experience for excluding stuff, but stick with what we have, use the ignore package with package.exclude, keep the ability to easily do it at the function level, and document better how it works.

  6. nikgraf commented on Oct 19, 2016

    @nikgraf
    Contributor

    Haha, reminds me of a tweet I have seen today:

    My goal with open source is to put as many config files in your git repo as possible:
    .babelrc/.flowconfig/lerna.json/package.json/yarn.lock
    

    https://twitter.com/thejameskyle/status/788799662438227969

    😜

  7. mthenw commented on Oct 19, 2016

    @mthenw
    ContributorAuthor

    @ac360 it always problematic to change existing feature but I always wonder if we would add a exactly the same feature again. If not we should not block ourselves from changing what is wrong. Users will appreciate even if they use that.

    The main problem with using ignore package with package.exclude is that user will be able to also include a file (!) there. Super confusing. Another sls deploy --noDeploy. We should be very careful with that.

  8. johncmckim commented on Oct 19, 2016

    @johncmckim
    Contributor

    @mthenw totally agree that this area needs some TLC. The change to Globs was a good idea but has left packaging system very confusing.

    I like the idea of .serverlessignore as it puts the ignore information in the context of the files being packaged. It also keeps serverless.yml focused on function / resource configuration. I'm not normally changing include/exclude and function / resource config at the same time. So I think it's ok for it to be separate.

  9. mthenw commented on Oct 20, 2016

    @mthenw
    ContributorAuthor

    cc @serverless/vip

  10. nicka commented on Oct 20, 2016

    @nicka
    Contributor

    Still one thing we might be forgetting when it comes to the .serverlessignore, it could be that a service includes multiple functions and for one specific function you might want to add some binaries. How would you see this working? Would it become a mix of serverless.yml:package:include/exclude and .serverlessignore?

    Personally I'd rather see everything "documented" within the serverless.yml.

  11. mthenw commented on Oct 20, 2016

    @mthenw
    ContributorAuthor

    @nicka

    Still one thing we might be forgetting when it comes to the .serverlessignore, it could be that a service includes multiple functions and for one specific function you might want to add some binaries. How would you see this working?

    in case of .serverlessignore

    Assuming that users have functions in separate dirs it's possible to have one .serverlessignore in root dir and another in function dir. Rules from function's one are merged with those in root dir. I guess this is how .gitignore works.

    in case of package.ignore

    Same as it works right now. You can define package.ignore for each function.

  12. jordanmack commented on Oct 20, 2016

    @jordanmack
    Contributor

    I second @ac360's proposal to utilize serverless.yml. The ability to both exclude and include is needed, and the ability to do it both at the service or function level is very desirable. Combined with the Serverless variable system you could setup your include/exclude file structure any way you want without restriction.

  13. svdgraaf commented on Oct 20, 2016

    @svdgraaf
    Contributor

    yep, I second (third?) doing it in serverless.yml, already way to much .ignore files :)

  14. nachoab commented on Oct 20, 2016

    @nachoab

    I'm with @ac360 .serverlessignore is even more confusing and more inconvenient than the include/exclude pattern in serverless.yml

    At least for me, it works better to ignore all and include files per func, as my project is bloated but my functions are small.

    Right know my solution is to have a folder per endpoint controller (which has all the http methods) and include only that folder for those funcs. The problem is forgetting to install npm packages before deploying.

  15. kennu commented on Oct 20, 2016

    @kennu
    Contributor

    In principle I would support using existing syntax (.gitignore) instead of inventing a new one. But I can see the potential benefits in using Serverless variables. There is also a big difference between .gitignore and .serverlessignore purposes (the other typically excludes node_modules and other generated files, while the other specifically needs to include them) which might be a bit confusing for new users.

    I would still add though, that .*ignore files are very easy to manage with shell tools, e.g. find . -name test.json >> .serverlessignore. This is pretty much impossible for serverless.yml.

  16. 1 remaining item

  17. doapp-ryanp commented on Oct 28, 2016

    @doapp-ryanp
    Contributor

    I'm in total alignment with @tobyhede with needing control on a function by function basis and with @ac360 in that it should stay in serverless.yml.

    In fact I think determining what assets need to go in a package should be handled, by default, with software intelligence. This is a solved problem. Java handles this with tooling like maven, Node with tooling like Browserify. IMO optimization is a best practice, and should be on by default (or really easy to turn on). Explicit include/exclude still needs to be available for edge cases, but it becomes less important if we use intelligence.

    I'm working on a plugin that will do the optimization for node labda's with 0 config for 80%+ of the use cases.

    At this point in the include/exclude/bundling space I'm more concerned that the process to identify assets and bundle them up is different between sls deploy and sls deploy function -f <name>. I have #2561 open to try to address it, but it still seems messy and I don't see how a lang like Java fits into the current architecture (docs say java is supported, is there a v1.0 example someplace?).

  18. doapp-ryanp commented on Nov 1, 2016

    @doapp-ryanp
    Contributor

    My Browserify plugin is now ready. It removes the need for include and IMO drastically simplifies getting your node based code bundled while shrinking code footprint (which makes your Lambda's cold starts faster).

  19. dougmoscrop commented on Nov 3, 2016

    @dougmoscrop
    Contributor

    I'm not crazy about using Browserify or Rollup or WebPack for this. I don't think we should stop people from using it, but "optimization" should not be pigeon holed in to requiring these things.

    I wrote this: https://github.com/dougmoscrop/serverless-plugin-include-dependencies
    (still being tested)

    Which simply adds the dependencies to the "not-exclude" list. (The "include" list). You get sort of the same effect as browserify or other kinds of bundling, but everything is preserved in their own files.

    So while .serverlessignore is neat, I still want the ability to say "include this file" somehow. I'm fine if that's done via an include: statement (I would update my plugin to use that), regardless if exclusion is done via a .ignore file or what.

  20. jordanmack commented on Nov 3, 2016

    @jordanmack
    Contributor

    I still support serverless.yml as the main method for include/exclude. (Browserify/Rollup/Webpack are great plugins for advanced functionality though.) There seem to be a fair amount of people who highly prefer an external ignore file though.

    What if Serverless just allowed for a generic variable handler to parse and convert a plain text document into a YAML list? Perhaps something like ${textList(./.serverlessignore)}? This would bridge the syntax and a single line to serverless.yml would allow the use of something like .serverlessignore.

  21. added this to the 1.2 milestone on Nov 4, 2016
  22. self-assigned this
    on Nov 4, 2016
  23. pmuens commented on Nov 4, 2016

    @pmuens
    Contributor

    Personally I would like to see include and exclude again like it was before the globs support merge. That means that it should work like in previous versions but globs are additionally supported (for power users).

    That should work on a service but also function level. Furthermore non-globs syntax (such as .git instead of .git/**) should work as well out of the box (Not 100% sure about this yet as it might make the code more complex).

    The usage of exclude and include in serverless.yml is more natural to me as it's easier to see it in context and is kind of a configuration (therefore it should stay in serverless.yml).

    I personally don't prefer yet another dotfile.

  24. rowanu commented on Nov 4, 2016

    @rowanu
    Contributor

    Chiming in on this one; Originally I thought .serverlessignore was the way to go, but after discussions on Slack and in the forum I think this should be more about bringing back include, being able to include/exclude on a per function basis, and continue to support globs (in addition to non-glob syntax working).

  25. flomotlik commented on Nov 7, 2016

    @flomotlik
    Contributor

    Agreed with @pmuens proposal. The main reason why .serverlessignore is complex is because we need to be able to do include/exclude on a per function level. So one .serverlessignore file can't really capture that use case, we would have to introduce .serverlessignore files per function or some syntax for that. And thats kind of painful.

    So yeah include/exclude with globs sounds good.

  26. pmuens commented on Nov 7, 2016

    @pmuens
    Contributor

    Ok. Thanks! Will start the work on this one in the next days.

    Please let me know if you guys face some issues with this approach or if this should be done differently!

  27. pmuens commented on Nov 9, 2016

    @pmuens
    Contributor

    Hey everyone #2681 is the PR which re-adds include.

    Could you guys look into it and provide feedback if there's some time? Thanks 👍

  28. nikgraf commented on Nov 15, 2016

    @nikgraf
    Contributor

    @doapp-ryanp did you run any test on cold-starts with and without your Browserify plugin? I would be super curious how much of an impact it has.

  29. doapp-ryanp commented on Nov 15, 2016

    @doapp-ryanp
    Contributor

    @nikgraf I did but it was prob 6+ months ago. I've talked with the AWS lambda devs, and its confirmed that smaller code sizes decreases cold start times. As to how much % gain, I don't have firm numbers.

    I know your not asking for the following, but I feel its important. IMO "compiling" is super easy to do, so why not even if the gain is 1%. My Browserify plugin makes it dead simple.

    In addition to performance gain, it helps you from reaching your account's lambda code size limit and lets you iterate faster (quicker to upload smaller zip).

  30. flomotlik commented on Nov 16, 2016

    @flomotlik
    Contributor

    I know your not asking for the following, but I feel its important. IMO "compiling" is super easy to do, so why not even if the gain is 1%. My Browserify plugin makes it dead simple.

    Because more code and more complexity (basically). I'm very very reluctant to add anything to Serverless that doesn't solve actual issues or have noticeable improvements that make a large difference (potentially a few milliseconds at a cold-start is imho not enough). The complexity it would involve to get this in, the complexity in teaching users and the potential for this to be a PITA when users deploy something and errors get thrown in places they don't expect them (which can happen depending on the minimisation technique). So it would have to be a very clear cut advantage for it to get into core.

    Thats why I'm super reluctant on any automated optimisations, because they are always tricky, there are always edge cases and they will include more work than we currently think because of those issues. They are really advanced things that users should consciously add themselves once it makes a noticeable difference.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions