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

Calling serverless deploy with a --package flag argument starting with ./ does not work #6525

Closed
stephaneseng opened this issue Aug 11, 2019 · 0 comments · Fixed by #6526
Closed

Comments

@stephaneseng
Copy link
Contributor

This is a Bug Report

Description

Calling serverless deploy with a --package flag argument starting with ./ does not work.

Here are the steps to reproduce this issue:

$ serverless create --template aws-nodejs
$ serverless package --package ./my-artifacts

$ tree
.
├── handler.js
├── my-artifacts
│   ├── cloudformation-template-create-stack.json
│   ├── cloudformation-template-update-stack.json
│   ├── sandbox-serverless.zip
│   └── serverless-state.json
└── serverless.yml

$ serverless deploy --package ./my-artifacts
 
  Serverless Error ---------------------------------------
 
  No serverless-state.json file found in the package path you provided.
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com
 
  Your Environment Information ---------------------------
     Operating System:          linux
     Node Version:              10.16.2
     Serverless Version:        1.49.0
     Enterprise Plugin Version: 1.3.8
     Platform SDK Version:      2.1.0

However, serverless deploy --package my-artifacts works fine.

Cause

An unexpected behavior occurs when serverless tries to copy the already packaged artifacts from ./my-artificats in this case to the .serverless temporary folder, before the deploy.

This copy is triggered by the following calls:

function fileExists(srcDir, destDir, options) {
  const fullFilesPaths = walkDirSync(srcDir, options);

  fullFilesPaths.forEach(fullFilePath => {
    const relativeFilePath = fullFilePath.replace(srcDir, '');
    fse.copySync(fullFilePath, path.join(destDir, relativeFilePath));
  });
}

With --package ./my-artifacts, this copy result in the following file structure:

$ tree ./.serverless/
./.serverless/
└── my-artifacts
    ├── cloudformation-template-create-stack.json
    ├── cloudformation-template-update-stack.json
    ├── sandbox-serverless.zip
    └── serverless-state.json

This differs with how the resulting file structure looks with --package my-artifacts:

$ tree ./.serverless/
./.serverless/
├── cloudformation-template-create-stack.json
├── cloudformation-template-update-stack.json
├── sandbox-serverless.zip
└── serverless-state.json

This is because, when --package ./my-artifacts is called, when attempting to copy the serverless-state.json file, fse.copySync(fullFilePath, path.join(destDir, relativeFilePath)) is invoked in the following context:

  • fullFilePath = my-artifacts/serverless-state.json
  • destDir = /tmp/my-project/.serverless
  • relativeFilePath = my-artifacts/serverless-state.json
  • srcDir = ./my-artifacts

Here, the intent was to have relativeFilePath = serverless-state.json but serverless could not remove srcDir = ./my-artifacts from
fullFilePath = my-artifacts/serverless-state.json.

Resolution proposal

This issue can be solved by calling https://github.com/jprichardson/node-fs-extra/blob/8.1.0/docs/copy-sync.md directly on the directories to copy from and to instead of calling it on the files to copy individually.

Similar or dependent issues

Issue with the same root cause:

Issues related to the serverless-state.json file path but I am unsure that these are due to the same root cause:

Additional data

  • Serverless Framework Version: 1.49.0 (Enterprise Plugin: 1.3.8, Platform SDK: 2.1.0)
  • Operating System: Ubuntu 18.04.3
stephaneseng added a commit to stephaneseng/serverless that referenced this issue Aug 11, 2019
…copySync() on the directories instead of calling it on the files to copy individually.

Closes serverless#6525.
stephaneseng added a commit to stephaneseng/serverless that referenced this issue Aug 11, 2019
…copySync() on the directories instead of calling it on the files to copy individually.

Closes serverless#6525.
stephaneseng added a commit to stephaneseng/serverless that referenced this issue Aug 11, 2019
…tra::copySync() on the directories instead of calling it on the files to copy individually.

The main motivation behind these changes is to rely on
https://github.com/jprichardson/node-fs-extra/blob/8.1.0/docs/copy-sync.md as
much as possible in order to avoid having to do the
`fullFilePath.replace(srcDir, '')` operation because this operation can be
error-prone.

Doing so fixes the following issues because the user-submitted file paths are
now correctly interpreted by fs-extra, closing both serverless#6525 and serverless#5172.
stephaneseng added a commit to stephaneseng/serverless that referenced this issue Aug 12, 2019
…tra::copySync() on the directories instead of calling it on the files to copy individually.

The main motivation behind these changes is to rely on
https://github.com/jprichardson/node-fs-extra/blob/8.1.0/docs/copy-sync.md as
much as possible in order to avoid having to do the
`fullFilePath.replace(srcDir, '')` operation because this operation can be
error-prone.

Doing so fixes the following issues because the user-submitted file paths are
now correctly interpreted by fs-extra, closing both serverless#6525 and serverless#5172.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants