Skip to content

Serverless.yml package exclude does not work #8093

Closed

Description

@lbittner-pdftron

Hi there!

I am trying to exclude files from a certain function using the exclude functionality on a per function basis. However, it seems like this setting is completely ignored.

Using the serverless config below, my merge deployment contains /lib/linux, which is expected, but the auth package also contains /lib/linux even though it is excluded. Ive tried every variation of glob patterns and ignore/include combos I can think of, but I cannot get this to work.

serverless.yml
service: ...

package:
  individually: true
  include:
    - keys/**
    - lib/linux/**
  exclude:
    - node_modules/aws-sdk/**
    
custom:
  myStage: ${opt:stage, self:provider.stage}
  myEnvironment:
    ENV:
      production: "production"
      staging: "staging"
  myBuckets:
    ENV:
      staging: ... 
      production: ...
provider:
  name: aws
  runtime: nodejs10.x

functions:
  merge:
    handler: services/merge/handler.handle
    environment:
      ENV: ${self:custom.myEnvironment.ENV.${self:custom.myStage}}
    events:
      - http:
          path: /xfdf/merge
          method: post
          cors: true
  auth:
    handler: services/auth/handler.handle
    package:
      exclude:
        - node_modules/**
        - keys/**
        - lib/linux/**
    events:
      - cloudFront:
          eventType: viewer-request
          origin:
            DomainName: ${self:custom.myBuckets.ENV.${self:custom.myStage}}
            S3OriginConfig:
              OriginAccessIdentity: ...
          behavior:
            ForwardedValues:
              QueryString: true
              Headers:
                - 'Access-Control-Request-Headers'
                - 'Access-Control-Request-Method'
                - 'Origin'
            AllowedMethods:
              - 'GET'
              - 'HEAD'
              - 'OPTIONS'

I am deploying using sls deploy --stage staging. The output is normal.

Installed version

$ sls --version
Framework Core: 1.78.1
Plugin: 3.7.0
SDK: 2.3.1
Components: 2.34.5

Activity

  1. lbittner-pdftron commented on Aug 18, 2020

    @lbittner-pdftron
    Author

    Hi,

    I managed to get it working by doing

      auth:
        handler: services/auth/handler.handle
        package:
          include:
            - '!lib/**'

    I'm not sure if exclude is supposed to work or not. If this is expected behaviour, you can close this ticket.

    Thanks,
    Logan

  2. medikoo commented on Aug 19, 2020

    @medikoo
    Contributor

    @lbittner-pdftron thanks for report

    This is a packaging logic design issue. Firstly global and individual rules for include and exclude are concatanated together. Then first exclude and after that include rules are applied. Hence in your case global lib/linux/** include shadows individual lib/linux/** exclude rule.

    I believe right fix for that is to:

    1. Replace include and exclude with single patterns rules set (better name welcome), then in one list we can setup both include and exclude rules as follows:
    package:
      patterns:
        - "includePath/**"
        - "!excludePath/**"
    1. Ensure that individual rules take priority over global so e.g. _global lib/** will be shadowed by local !lib/**

    This should be implemented in two phases

    1. In first phase we support both ways (include and exclude) and patterns (we should crash if both are used), and we show a deprecation notice if include or exclude is used
    2. With new major we remove support for include and exclude.

    PR is welcome!

  3. added
    breaking
    bug/design
    deprecation
    on Aug 19, 2020
  4. juanjoDiaz commented on Nov 29, 2020

    @juanjoDiaz
    Contributor

    Any intention of fixing this?

  5. siourdas-vasilis commented on Dec 22, 2020

    @siourdas-vasilis

    Same problem here..

  6. wallacepf commented on Feb 1, 2021

    @wallacepf

    Same here.

        package:
          patterns:
            - ".terraform/**"
            - ".circleci/**"
            - "test_reports/**" 
            - "Dockerfile"
    

    image

  7. medikoo commented on Feb 2, 2021

    @medikoo
    Contributor

    @wallacepf We have nearly finalized PR for that, so stay tuned, we should have fixed that shortly

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingbug/designcat/packagingdeprecationhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions