Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to per-function configuration files #1030

Merged
merged 9 commits into from Aug 17, 2022

Conversation

eduardoboucas
Copy link
Member

@eduardoboucas eduardoboucas commented Feb 18, 2022

BEGIN_COMMIT_OVERRIDE
feat: add support to per-function configuration files (#1030)

feat: new bundler that allows to skip bundling (#1173)
END_COMMIT_OVERRIDE

Summary

Adds support to per-function configuration files. These files are only taken into account if they are inside a directory that is part of the new configFileDirectories configuration property.

Take the following project structure as an example:

.netlify/
  functions-internal/
    internal-function-1/
      internal-function-1.json
      internal-function-1.js
    internal-function-2.json
    internal-function-2.ts
netlify/
  functions/
    user-function-1.ts

If configFileDirectories contains .netlify/functions-internal, then internal-function-1 and internal-function-2 will read configuration properties from .netlify/functions-internal/internal-function-1/internal-function-1.json and .netlify/functions-internal/internal-function-2.json, respectively.

Even if there was a netlify/functions/user-function-1.json file, it would be ignored if netlify/functions was not part of configFileDirectories.

Any configuration properties loaded from a per-function configuration file take precedence over the global config object.

A picture of a cute animal (not mandatory, but encouraged)

where-to-see-sloths-in-costa-rica

@eduardoboucas eduardoboucas added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Feb 18, 2022
@eduardoboucas eduardoboucas requested a review from a team July 12, 2022 16:13
@github-actions
Copy link
Contributor

github-actions bot commented Jul 12, 2022

⏱ Benchmark results

Comparing with b472a84

largeDepsEsbuild: 7.5s

⬆️ 4.15% increase vs. b472a84

^                                   7.5s  
│                           7.1s    ┌──┐  
│   6.6s                    ┌──┐    |▒▒|  
│ ──┌──┐────────────────────┼──┼────|▒▒|──
│   |  |    6.1s     6s     |  |    |▒▒|  
│   |  |    ┌──┐    ┌──┐    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-4     T-3     T-2     T-1      T    
Legend

largeDepsNft: 36.9s

⬆️ 3.83% increase vs. b472a84

^                                  36.9s  
│                          35.5s    ┌──┐  
│                           ┌──┐    |▒▒|  
│ ─30.7s────────────────────┼──┼────|▒▒|──
│   ┌──┐                    |  |    |▒▒|  
│   |  |           27.6s    |  |    |▒▒|  
│   |  |            ┌──┐    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |            |  |    |  |    |▒▒|  
│   |  |    n/a     |  |    |  |    |▒▒|  
└───┴──┴────────────┴──┴────┴──┴────┴──┴──>
    T-4     T-3     T-2     T-1      T    
Legend

largeDepsZisi: 55.3s

⬆️ 3.96% increase vs. b472a84

^                                  55.3s  
│                          53.1s    ┌──┐  
│                           ┌──┐    |▒▒|  
│                           |  |    |▒▒|  
│ ─45.5s───45.4s────────────┼──┼────|▒▒|──
│   ┌──┐    ┌──┐   42.5s    |  |    |▒▒|  
│   |  |    |  |    ┌──┐    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-4     T-3     T-2     T-1      T    
Legend

@danez danez marked this pull request as draft July 13, 2022 07:47
@danez danez self-assigned this Jul 18, 2022
@danez
Copy link
Contributor

danez commented Jul 18, 2022

@eduardoboucas What was the idea behind restricting this to certain directories instead of allowing it for every function? We did not want to expose this config support to user-generated functions?

Also do you think that zisi is the right place for reading the config? The problem I have with it is that not all of the config is relevant for zisi, lambda_runtime being one example. That means that zisi now reads a config file that might only contain configuration for a later step outside of zisi.
Wouldn't it make sense to have the logic for the function config files to be inside @netlify/config? And then zisi gets whatever config it needs from there. Same actually for ISC and scheduled functions. Might make sense to move that to @netlify/config as well, because in the end it is configuration that can be supplied to zisi.

@eduardoboucas
Copy link
Member Author

What was the idea behind restricting this to certain directories instead of allowing it for every function? We did not want to expose this config support to user-generated functions?

Yes, exactly! Once we get to ISC, I think we'll want to allow all types of functions to be configured that way, but until then I don't think it makes sense for user-generated functions to use this functionality. Asking people to write a per-function JSON feels incredibly unergonomic, and they'd be better off using netlify.toml instead.

Also do you think that zisi is the right place for reading the config?

Note that zip-it-and-ship-it is the only package capable of resolving a functions config. Imagine this:

[functions."next_*"]
node_bundler = "nft"

@netlify/config doesn't know how to unpack this into a list of functions, because it doesn't know how to tell whether a file is a function. This is why zip-it-and-ship-it is currently responsible for handling functions configuration.

Personally, I don't think that passing to zip-it-and-ship-it a configuration property that it doesn't use or understand is that big of a problem, but I'm happy to discuss any alternative options you have in mind.

@danez danez marked this pull request as ready for review July 22, 2022 09:26
@danez
Copy link
Contributor

danez commented Jul 22, 2022

Other question: The Proposal only specifies nodeBundler and included_files as valid configuration options coming from the deployment config. The current implementation does not limit the config though, that means all config options from zisi are currently available to be set in the config.

Should we limit/restrict this?

I personally don't see any downside of allowing all options, but I probably am missing something.

Should we add validation of the config? We can also do that later, once we introduce non zisi config stuff. At least then it would make sense IMHO.

@jackiewmacharia @eduardoboucas

@eduardoboucas
Copy link
Member Author

I also don't see any obvious downsides of allowing all configuration properties. I think the proposal mentioned those two as examples of properties we have an identified use case for in the deploy configuration API.

Copy link
Contributor

@jackiewmacharia jackiewmacharia left a comment

Choose a reason for hiding this comment

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

Looks good overall, left a few comments.

src/config.ts Show resolved Hide resolved
src/config.ts Show resolved Hide resolved
@danez
Copy link
Contributor

danez commented Jul 28, 2022

@eduardoboucas I cannot add you as reviewer, because you are the creator. would you mind looking over basically your own code once more, and comment if you notice something?

danez
danez previously approved these changes Jul 28, 2022
src/config.ts Show resolved Hide resolved
src/config.ts Outdated Show resolved Hide resolved
tests/main.js Show resolved Hide resolved
@eduardoboucas
Copy link
Member Author

would you mind looking over basically your own code once more, and comment if you notice something?

Done!

tests/main.js Outdated Show resolved Hide resolved
@eduardoboucas
Copy link
Member Author

LGTM!

danez and others added 2 commits July 29, 2022 15:19
Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
@danez
Copy link
Contributor

danez commented Jul 29, 2022

Okay I consider this done. I'm not going to merge this yet, but will start to build the skip bundling based on this PR and then merge both together.

danez and others added 2 commits August 17, 2022 15:03
* feat: add none bundler that does not bundle anything

* chore: fix fixtures

* Update src/runtimes/node/bundlers/none/index.ts

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>

* Update src/runtimes/node/bundlers/none/index.ts

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>

* chore: update snapshot

Co-authored-by: Eduardo Bouças <mail@eduardoboucas.com>
@danez danez merged commit dbc0857 into main Aug 17, 2022
@danez danez deleted the feat/per-function-config branch August 17, 2022 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants