Repository navigation
Persist package.artifact correctly - #3469
Conversation
pmuens
left a comment
There was a problem hiding this comment.
Thanks for the PR @HyperBrain 👍
I tested it with the Google Cloud Functions provider plugin which fails because this.serverless.service.package.artifact is not available.
Unfortunately the error persists. This is the error message I get after running serverless deploy:
Serverless: WARNING: Plugin GoogleDeploy uses deprecated hook before:deploy:initialize
Serverless: WARNING: Plugin GoogleDeploy uses deprecated hook deploy:initialize
Serverless: WARNING: Plugin GoogleDeploy uses deprecated hook deploy:setupProviderConfiguration
Serverless: WARNING: Plugin GoogleDeploy uses deprecated hook before:deploy:compileFunctions
Serverless: Uploading artifacts...
Type Error ---------------------------------------------
path must be a string or Buffer
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
TypeError: path must be a string or Buffer
at Object.fs.open (fs.js:549:11)
at ReadStream.open (fs.js:1772:6)
at new ReadStream (fs.js:1759:10)
at Object.fs.createReadStream (fs.js:1713:10)
at GoogleDeploy.uploadArtifacts (/app/tmpdirs-serverless/A-Services/gcf-test/node_modules/serverless-google-cloudfunctions/deploy/lib/uploadArtifacts.js:17:18)
at runCallback (timers.js:651:20)
at tryOnImmediate (timers.js:624:5)
at processImmediate [as _immediateCallback] (timers.js:596:5)
From previous event:
at PluginManager.invoke (/app/lib/classes/PluginManager.js:234:22)
at PluginManager.run (/app/lib/classes/PluginManager.js:253:17)
at Serverless.run (/app/lib/Serverless.js:97:31)
at serverless.init.then (/app/bin/serverless:23:50)
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Forums: forum.serverless.com
Chat: gitter.im/serverless/serverless
Your Environment Information -----------------------------
OS: linux
Node Version: 7.5.0
Serverless Version: 1.11.0
And here's the code which causes the error:
Any idea what might be missing 💭 ?
There was a problem hiding this comment.
Why do we have both? artfifact and artifacts?
There was a problem hiding this comment.
I added artifacts for safety. It will contain the function artifacts, but it is not really needed, because extendedValidate will separately loop through the function artifacts by using the getFunctionArtifact() function.
Only artifact is needed right now.
Feel free to remove it - the fix works fine without it.
|
@pmuens Rearding the Google problem - The Imo, each provider should set its own |
|
Pressed wrong button :) |
|
@HyperBrain thanks! Yes, that sounds reasonable. Best would be if we could fix it in a way that other provider plugins don't need to do anything for now and can update later on so that it's non-breaking again. I can imagine that other plugin authors have looked into our code and inspired their solutions based on what they saw. But yes, moving it from |
|
@HyperBrain @pmuens sorry I missed the convo last week, but just to be sure, this is only an issue with |
|
I saw somewhere that it is set to package artifact. Also the function
artifacts are checked in extendedValidate directly. But please test if it
works.
Eslam λ Hefnawy <[email protected]> schrieb am Mo., 17. Apr. 2017,
4:11 nachm.:
… @HyperBrain <https://github.com/HyperBrain> @pmuens
<https://github.com/pmuens> sorry I missed the convo last week, but just
to be sure, this is only an issue with service.package.artifact not
function.package.artifact too?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3469 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFRM3u6KIeDPQD4WMqo9JHzmJ-uwdWEkks5rw3MQgaJpZM4M8q29>
.
|
I just tested the current functions:
hello:
handler: handler.hello
package:
artifact: foo/wasd.zip
events:
- http:
method: ANY
path: hello
integration: LAMBDA
cors: true
goodbye:
handler: handler.goodbye
events:
- http:
method: GET
path: goodbye |
|
🤔 @HyperBrain while testing the Could you please share an example real quick which illustrates what this PR fixes? |
|
It fixes compatibility with a bunch of plugins. A lot of plugins use the The effect is exactly the same as your test with the Google plugin you mentioned in #3469 (review) |
There was a problem hiding this comment.
Just tested it another time today.
Unfortunately I get this error when I run serverless package:
Serverless: Packaging service...
Error --------------------------------------------------
ENOENT: no such file or directory, open 'service.zip'
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
Error: ENOENT: no such file or directory, open 'service.zip'
at Object.fs.openSync (fs.js:558:18)
at Object.fs.readFileSync (fs.js:468:33)
at AwsCompileFunctions.compileFunction (/app/lib/plugins/aws/package/compile/functions/index.js:185:24)
at serverless.service.getAllFunctions.forEach (/app/lib/plugins/aws/package/compile/functions/index.js:227:39)
at Array.forEach (native)
at AwsCompileFunctions.compileFunctions (/app/lib/plugins/aws/package/compile/functions/index.js:227:8)
at BbPromise.reduce (/app/lib/classes/PluginManager.js:234:55)
From previous event:
at PluginManager.invoke (/app/lib/classes/PluginManager.js:234:22)
at PluginManager.run (/app/lib/classes/PluginManager.js:253:17)
at Serverless.run (/app/lib/Serverless.js:97:31)
at serverless.init.then (/app/bin/serverless:23:50)
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Forums: forum.serverless.com
Chat: gitter.im/serverless/serverless
Your Environment Information -----------------------------
OS: linux
Node Version: 7.5.0
Serverless Version: 1.11.0
My serverless.yml file looks like this:
service: service
provider:
name: aws
runtime: nodejs6.10
functions:
hello:
handler: handler.hello
goodbye:
handler: handler.goodbyeRunning serverless package in master succeeds.
|
I'll check. Did you test with a completely fresh project? |
|
@HyperBrain thanks for looking into it 👍 . Yes, I tested it with a fresh service. |
|
Quick update: Seems like the path is not prepended. Running this PR I get |
There was a problem hiding this comment.
I think this is where things fall apart.
Changing it to:
const foo = path.join(this.serverless.config.servicePath, '.serverless', zipFileName);
_.set(this.serverless.service, 'package.artifact', foo);fixes the problem.
Not sure if there's a better solution though.
There was a problem hiding this comment.
Ok. this is one part of the solution... The second one would be to replace the persisted path part of the artifact with the actual path for the deploy phase in extendedValidate().
So extendedValidate() should do a service.package.artifact = path.join(this.serverless.config.servicePath, '.serverless', << filename part of state.package.artifact >>)
There was a problem hiding this comment.
.... better: saveState should persist only the filename part of the artifact too. Then extendedValidate does not need to strip anything
|
Just a quick update on this one. The current version fails to package when using |
|
@HyperBrain this PR is obsolete from my side since #3496 resolves all the problems I faced in here. Should we close it? |
|
@HyperBrain gotcha. Sorry I misunderstood the comment you wrote above. I'll revert the stuff I've done next up. 👍 |
|
But remember not all changes, only the ones in packageService ;-) |
|
😄 shoot. I should read more carefully. Commit incoming! |
|
Ok. The PR should be in the correct state again. Feel free to rebase once #3496 is merged! |
The `service.package.artifact` property was missing in the saveState function, so it was not available in the deploy phase. This PR saves and restores the property correctly, and for AWS additionally sets it during packaging. For AWS the initialization of the property also was missing, possibly due to a merge conflict. Combination of the following commits: Re-revert changes for saveServiceState and extendedValidate Revert most recent changes Update package artifact to include path and .zip name Update artifact file path for packaging and name for service state Update tests for saveServiceState Do not persist artifacts as it is not needed Persist package.artifact correctly
a42dc8b to
aa29c96
Compare
4e3a618 to
36bff98
Compare
|
@mike-suggitt You can test this branch, if it changes the behavior and works. Its purpose is also to fix the serverless-webpack plugin and the alias-plugin. |
|
@pmuens PR is rebased now to master. We should test it to see, if the affected plugins now work correctly |
|
@pmuens I did some final tests. Everything worked here (webpack + alias). So from my side it's GTM. |
pmuens
left a comment
There was a problem hiding this comment.
Thanks for updating @HyperBrain 👍
Unfortunately it still fails with package.individually: true on the service level.
Here's the error message I get:
Serverless: Packaging service...
Type Error ---------------------------------------------
Cannot read property 'split' of undefined
For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.
Stack Trace --------------------------------------------
TypeError: Cannot read property 'split' of undefined
at AwsPackage.saveServiceState (/app/lib/plugins/aws/package/lib/saveServiceState.js:17:62)
From previous event:
at Object.aws:package:finalize:saveServiceState [as hook] (/app/lib/plugins/aws/package/index.js:81:10)
at BbPromise.reduce (/app/lib/classes/PluginManager.js:234:55)
From previous event:
at PluginManager.invoke (/app/lib/classes/PluginManager.js:234:22)
at PluginManager.spawn (/app/lib/classes/PluginManager.js:246:17)
at AwsPackage.BbPromise.bind.then (/app/lib/plugins/aws/package/index.js:69:51)
From previous event:
at Object.package:finalize [as hook] (/app/lib/plugins/aws/package/index.js:69:10)
at BbPromise.reduce (/app/lib/classes/PluginManager.js:234:55)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)
From previous event:
at PluginManager.invoke (/app/lib/classes/PluginManager.js:234:22)
at PluginManager.run (/app/lib/classes/PluginManager.js:253:17)
at Serverless.run (/app/lib/Serverless.js:97:31)
at serverless.init.then (/app/bin/serverless:23:50)
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Forums: forum.serverless.com
Chat: gitter.im/serverless/serverless
Your Environment Information -----------------------------
OS: linux
Node Version: 7.9.0
Serverless Version: 1.11.0
|
--Does it work on master?-- It seems that it is here: in saveServiceState... Looks like artifact does not get set with As solution we should wrap it in lodash calls, that do not fail on non-existing/empty properties. @pmuens Cannot happen on master ... artifact is not persisted explicitly there. |
|
@pmuens Now package individually should be handled too. |
|
Thanks for updating! Will give it another spin the upcoming hrs. 👍 |
pmuens
left a comment
There was a problem hiding this comment.
Just tested this with different setups. Was not able to break it.
Thanks @HyperBrain 👍
The
service.package.artifactproperty was missing in the saveState function, so it was not available in the deploy phase.This PR saves and restores the property correctly, and for AWS additionally sets it during packaging. For AWS the initialization of the property also was missing, possibly due to a merge conflict.
Should be merged as soon as possible!