Skip to content

Fixed #4188 - Package generating incorrect package artifact path in serverless-state.json - #5297

Merged
pmuens merged 3 commits into
serverless:masterfrom
fruffin:fix-4188
Mar 14, 2019
Merged

pmuens merged 3 commits into
serverless:masterfrom
fruffin:fix-4188

Conversation

@fruffin

@fruffin fruffin commented Sep 15, 2018 •

Copy link
Copy Markdown
Contributor

What did you implement:

Closes #4188 - Package generating incorrect package artifact path in serverless-state.json

How did you implement it:

Because artifacts are generated in the .serverless directory first, even if a package path was provided, the reference to the artefact zip file was incorrectly pointing at the .serverless directory.
This only needs to be changed at the time the service state is saved, so I have added a few lines to the saveServiceState.js file of the AWS package plugin to fix the paths in the service configuration before saving.

How can we verify it:

  • In your serverless.yml file, specify a package path like so:
package:
  path: ../dist
  • Run the sls package command
  • Verify that the serverless-state.json file in the dist directory references the dist directory for the package path of each function

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

@warapitiya

Copy link
Copy Markdown

@fruffin Why this PR is not moving forward?

@fruffin

fruffin commented Jan 2, 2019

Copy link
Copy Markdown
Contributor Author

I just haven't got around to adding the extra tests and remove the coverage warnings yet. I'll try to look into it this week

@ahmed-abdulmoniem

Copy link
Copy Markdown

Waiting for this PR because the issue is happening with me as well.

@dschep dschep left a comment

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.

Yup.. looks pretty good. I would want a test covering this tho. I took a quick stab at adding test coverage myself, but didn't get it working in the short time I'm allotting to each issue/pr I review.

dschep
dschep previously requested changes Jan 7, 2019

@dschep dschep left a comment

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.

Furthermore.. in a project without artifact defined I get this error:

$ SLS_DEBUG=t STAGE=test sls deploy
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: WARNING: Missing "tenant" and "app" properties in serverless.yml. Without these properties, you can not publish the service to the Serverless Platform.
Serverless: Invoke deploy
Serverless: Invoke package
Serverless: Invoke aws:common:validate
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Invoke aws:package:finalize

  Type Error ---------------------------------------------

  Cannot read property 'substr' of undefined

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Stack Trace --------------------------------------------

TypeError: Cannot read property 'substr' of undefined
    at _.forEach.func (/Users/dschep/code/sls/serverless/lib/plugins/aws/package/lib/saveServiceState.js:34:29)
    at /Users/dschep/code/sls/serverless/node_modules/lodash/lodash.js:4911:15
    at baseForOwn (/Users/dschep/code/sls/serverless/node_modules/lodash/lodash.js:2996:24)
    at /Users/dschep/code/sls/serverless/node_modules/lodash/lodash.js:4880:18
    at Function.forEach (/Users/dschep/code/sls/serverless/node_modules/lodash/lodash.js:9344:14)
    at AwsPackage.saveServiceState (/Users/dschep/code/sls/serverless/lib/plugins/aws/package/lib/saveServiceState.js:30:7)
From previous event:
    at Object.aws:package:finalize:saveServiceState [as hook] (/Users/dschep/code/sls/serverless/lib/plugins/aws/package/index.js:81:10)
    at BbPromise.reduce (/Users/dschep/code/sls/serverless/lib/classes/PluginManager.js:390:55)
From previous event:
    at PluginManager.invoke (/Users/dschep/code/sls/serverless/lib/classes/PluginManager.js:390:22)
    at PluginManager.spawn (/Users/dschep/code/sls/serverless/lib/classes/PluginManager.js:408:17)
    at AwsPackage.BbPromise.bind.then (/Users/dschep/code/sls/serverless/lib/plugins/aws/package/index.js:69:51)
From previous event:
    at Object.package:finalize [as hook] (/Users/dschep/code/sls/serverless/lib/plugins/aws/package/index.js:69:10)
    at BbPromise.reduce (/Users/dschep/code/sls/serverless/lib/classes/PluginManager.js:390:55)
From previous event:
    at PluginManager.invoke (/Users/dschep/code/sls/serverless/lib/classes/PluginManager.js:390:22)
    at PluginManager.spawn (/Users/dschep/code/sls/serverless/lib/classes/PluginManager.js:408:17)
    at Deploy.BbPromise.bind.then.then (/Users/dschep/code/sls/serverless/lib/plugins/deploy/deploy.js:123:50)
From previous event:
    at Object.before:deploy:deploy [as hook] (/Users/dschep/code/sls/serverless/lib/plugins/deploy/deploy.js:113:10)
    at BbPromise.reduce (/Users/dschep/code/sls/serverless/lib/classes/PluginManager.js:390:55)
From previous event:
    at PluginManager.invoke (/Users/dschep/code/sls/serverless/lib/classes/PluginManager.js:390:22)
    at PluginManager.run (/Users/dschep/code/sls/serverless/lib/classes/PluginManager.js:421:17)
    at variables.populateService.then.then (/Users/dschep/code/sls/serverless/lib/Serverless.js:157:33)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:121:23)
From previous event:
    at Serverless.run (/Users/dschep/code/sls/serverless/lib/Serverless.js:144:8)
    at serverless.init.then (/Users/dschep/code/sls/serverless/bin/serverless:43:50)

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           10.13.0
     Serverless Version:     1.31.0

@Idanatcox

Copy link
Copy Markdown

I had the same issue see #3525 (comment) for a workaround

@ahmed-abdulmoniem

Copy link
Copy Markdown

Any progress on this PR?

@pmuens pmuens self-assigned this Mar 7, 2019

@pmuens pmuens left a comment •

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.

Thanks for working on this @fruffin 👍

I just pulled this today and tested it. Added some minor refactorings and a unit test.

Here's the config I've used to test this:

service:
  name: test

provider:
  name: aws
  stage: dev
  runtime: nodejs8.10

package:
  path: ../dist

functions:
  hello:
    handler: handler.hello
    package:
      artifact: ../artifacts/hello.zip
  world:
    handler: handler.world

Looks like it's working fine.

@warapitiya @ahmed-abdulmoniem @Idanatcox can you test this as well so that we can merge this soon? Thanks!

@pmuens pmuens left a comment

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.

Just tested this again today and couldn't find any issues.

Merging :shipit:

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.

Package generating incorrect package artifact path in serverless-state.json

7 participants