Skip to content

Bring back include configuration for an easier packaging control - #2681

Merged
flomotlik merged 10 commits into
masterfrom
rework-include-exclude
Nov 16, 2016
Merged

flomotlik merged 10 commits into
masterfrom
rework-include-exclude

Conversation

@pmuens

@pmuens pmuens commented Nov 9, 2016 •

Copy link
Copy Markdown
Contributor

What did you implement:

Closes #2460

Brings back the include configuration on a per-service and per-function level.

How did you implement it:

Added the include configuration and updated the zipping and packaging configuration so that the include definitions (globs) are appended to the exclude array. This way globs.sync will re-add the files (see https://github.com/jpillora/node-glob-all#usage).

How can we verify it:

Create the following directory structure:

bildschirmfoto 2016-11-09 um 14 22 54

With this serverless.yml

service: reword-include-exclude

provider:
  name: aws
  runtime: nodejs4.3

#### NOT INDIVIDUALLY

package:
  exclude:
    - excluded-by-default.json
    - excluded-directory/**
  include:
    - excluded-directory/should-be-included.js
    - excluded-directory/include-directory/**

functions:
  hello:
    handler: handler.hello

#### INDIVIDUALLY

#package:
#  individually: true
#  exclude:
#    - excluded-by-default.json

#functions:
#  hello:
#    handler: handler.hello
#    package:
#      include:
#        - excluded-by-default.json
#  world:
#    handler: handler.hello
#    package:
#      exclude:
#        - event.json

Comment out the stuff you want to test and run serverless deploy --noDeploy. After that inspect the .zip file.

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config/commands/resources
  • Change ready for review message below

Is this ready for review?: YES

@pmuens pmuens mentioned this pull request Nov 9, 2016
@pmuens
pmuens force-pushed the rework-include-exclude branch 4 times, most recently from f4c5bbf to a78b3c4 Compare November 10, 2016 14:16
@pmuens

pmuens commented Nov 14, 2016

Copy link
Copy Markdown
Contributor Author

@eahefnawy @flomotlik any update on this one? Can we merge it?

So that files and directories are considered during exclude / include.
Furthermore the test directory structure is updated so that it’s easier to extend
and understand.
This makes it possible that everything (even the .serverless dir) can be included again.
@pmuens
pmuens force-pushed the rework-include-exclude branch from 5283edc to f816879 Compare November 14, 2016 09:30
@rowanu

rowanu commented Nov 15, 2016

Copy link
Copy Markdown
Contributor

I checked this branch out and had a play with it - the service-level includes/excludes work, but the function-level includes/excludes didn't seem to work; I haven't had a chance to investigate why that is yet.

Can you confirm using function-level includes/excludes works for you @pmuens? I'm just trying to work out if it's my setup (all the tests pass for me).


# you can add packaging information here
package:
# 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.

Since we are using artifact here I would recommend to remove include/exclude completely. Even if you comment it out it's ignored.

# exclude:
# - exclude-me.js
# - exclude-me-dir/**
# artifact: my-service-code.zip

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.

Since include/exclude is ignored once you start using artifact I recommend to remove it from this example. To me it was so confusing that I needed a call with flo to explain it that it's either this or that.

# exclude:
# - exclude-me.py
# - exclude-me-dir/**
# artifact: my-service-code.zip

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.

Since include/exclude is ignored once you start using artifact I recommend to remove it from this example. To me it was so confusing that I needed a call with flo to explain it that it's either this or that.


# you can add packaging information here
package:
# 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.

Since we are using artifact here I would recommend to remove include/exclude completely. Even if you comment it out it's ignored.


# you can add packaging information here
package:
# 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.

Since we are using artifact here I would recommend to remove include/exclude completely. Even if you comment it out it's ignored.

Comment thread docs/providers/aws/guide/packaging.md Outdated
## Artifact

For complete control over the packaging process you can specify your own zip file for your service. Serverless won't zip your service if this is configured so `exclude` will be ignored.
For complete control over the packaging process you can specify your own zip file for your service. Serverless won't zip your service if this is configured so `exclude` and `include` will be ignored.

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.

At first I didn't get this part. I would recommend to make it very explicit that artifact and include/exclude should not be combined. What about:

For complete control over the packaging process you can specify your own artifact zip file. Serverless won't zip your service if this is configured and therefor `exclude` and `include` will be ignored. Either you use artifact or include/exclude.

The artifact option is especially useful in case your development environment allows you to generate a deployable artifact like Maven does for Java.

@nikgraf

nikgraf commented Nov 15, 2016

Copy link
Copy Markdown
Contributor

@rowanu i just tried. It works on a function level if you deploy just a function sldev deploy function --function hello --noDeploy. To be honest I was a bit surprised by that.

What kind of behaviour did you expect?


Then for every function you can use the same `exclude / artifact` config options as you can service wide. The `exclude` option will be merged with the service wide options to create one `exclude` config per function during packaging.
Then for every function you can use the same `exclude`, `include` or `artifact` config options as you can service wide. The `exclude` and `include` option will be merged with the service wide options to create one `exclude` and `include` config per function during packaging.

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.

Not sure if this is a bug or not that a single function deploy will always take package of a function into account.

If this is intended please add something along these lines:

Independently if you enable the package:individually option for your whole service the package option for a function will always be taking into account if you deploy via serverless deploy function --function functionName.

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.

@flomotlik Just discussed it with @pmuens. We are both not sure if this is a feature or a bug. Leadership needed 🚓 🚨

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.

if package: individually is enabled it should only use include/exclude of that one function. If its not set it should use the service wide config. If behaviour differs this is a bug, please open an issue in that case.

Comment thread lib/plugins/package/lib/zipService.js Outdated
});

// exclude the whole .serverless directory
patterns.push('!.serverless/**');

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.

You have .serverless in the defaultExcludes

. Is there a reason why explicitly add it here again? What if someone explicitly want's to add it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

He can re-add id via include as the include globs are pushed at the end of the array after the exclude. But I agree. I think we can remove it! Nice catch!

expect(getServiceArtifactNameStub.calledOnce).to.be.equal(true);

expect(zipDirectoryStub.calledOnce).to.be.equal(true);
expect(zipDirectoryStub.args[0][0]).to.be.equal(servicePath);

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.

Instead of matching arguments like this I personally find it way more expressive to use sinon's calledWithExactly
https://github.com/serverless/serverless/blob/master/lib/plugins/aws/deploy/tests/cleanupS3Bucket.js#L207

@nikgraf

nikgraf commented Nov 15, 2016

Copy link
Copy Markdown
Contributor

@pmuens This is really really awesome work! The ZipService test are nice and I'm super excited about the whole package:individually story.

@pmuens

pmuens commented Nov 15, 2016

Copy link
Copy Markdown
Contributor Author

@nikgraf thanks for the review! Updated all the things you brought up 👍
Just one comment regarding the bug / feature functionality is open.

@rowanu Thanks for looking into it as well. Do you still face the issue? What is the outcome you'd expect?

@rowanu

rowanu commented Nov 15, 2016

Copy link
Copy Markdown
Contributor

To your inline comment @nikgraf, I think it's a feature!

The problem I was having earlier was because I was missing individually: true at the top level of my serverless.yml, but I think that actually explains my expectations; Do we really need to specify individually: true anymore? If I specify package options at a function-level, it's obvious I want to package it individually!

I also expect packaging to be exactly the same, regardless of if I run sls deploy --function ... or just sls deploy. Packaging differently based on the same serverless.yml configuration would be surprising, and surprises are not generally a good thing in a framework.

@pmuens

pmuens commented Nov 16, 2016

Copy link
Copy Markdown
Contributor Author

Hey @rowanu thanks for the update about this! 👍
I agree. individually is not strictly necessary here as the outcome is obvious if I specify the exclude and include on a function level.
Maybe we can open up a separate issue for this and continue the discussion there!

Could not exactly reproduce the case that packaging differs when I run it for a service wide packaging and a per-function packaging. Maybe @nikgraf could open up an issue to describe how this can be reproduced.

I think we should fix this in a separate PR as this one targets the include / exclude.

@rowanu

rowanu commented Nov 16, 2016

Copy link
Copy Markdown
Contributor

Agreed, all that can be tackled elsewhere.

Hope we can get this merged before the next release.

@pmuens pmuens self-assigned this Nov 16, 2016
@pmuens

pmuens commented Nov 16, 2016 •

Copy link
Copy Markdown
Contributor Author

@rowanu Yes, we're about to release this in the next couple of hrs.

I just rethought the removal of individually but I think the problem is that this won't work if you have no exclude or include definitions at all. How should Serverless know that you want to package each function individually in that case.

Or am I missing something?

@flomotlik
flomotlik merged commit 4e39b32 into master Nov 16, 2016
@flomotlik
flomotlik deleted the rework-include-exclude branch November 16, 2016 15:18
@rowanu

rowanu commented Nov 16, 2016

Copy link
Copy Markdown
Contributor

@pmuens just to talk to your last comment, I was expecting individually: true to be inferred if I have set package options for individual functions; All other functions would just get the default service packaging (i.e. as if no package options were set anywhere).

Just a note that these expectations weren't based on reading the docs or anything - it was late when I was testing this and I probably should've just gone to bed! That being said, they still make sense to me now (that is, inferring individually: true if function package options are present) but I haven't had a chance to check the code and see how hard this would be to implement based on the existing code.

@pmuens

pmuens commented Nov 17, 2016

Copy link
Copy Markdown
Contributor Author

I understand. Thanks @rowanu for the clarification! 👍

@flomotlik

Copy link
Copy Markdown
Contributor

The main reason why we didn’t make it automatic was that packaging
individually is an optimisation that should be done knowingly. The UX of
the option isn’t good though at the moment, I agree.

On 16 November 2016 at 21:47:04, rowan ([email protected]) wrote:

@pmuens https://github.com/pmuens just to talk to your last comment, I
was expecting individually: true to be inferred if I have set package
options for individual functions; All other functions would just get the
default service packaging (i.e. as if no package options were set anywhere).

Just a note that these expectations weren't based on reading the docs or
anything - it was late when I was testing this and I probably should've
just gone to bed! That being said, they still make sense to me now (that
is, inferring individually: true if function package options are present)
but I haven't had a chance to check the code and see how hard this would be
to implement based on the existing code.

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
#2681 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAIGLeTiLxxYkPEinUJtfZBdE3qBVQTiks5q-3nYgaJpZM4KthxC
.

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.

4 participants